https://github.com/cog-imperial/omlt
Represent trained machine learning models as Pyomo optimization formulations
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
✓DOI references
Found 4 DOI reference(s) in README -
○Academic publication links
-
✓Committers with academic emails
5 of 21 committers (23.8%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.3%) to scientific vocabulary
Keywords
cnn
gradient-boosted-trees
keras-neural-networks
mathematical-modelling
mathematical-programming
mixed-integer-optimization
mixed-integer-programming
modeling-language
neural-network
nonlinear-optimization
nonlinear-programming
onnx
optimization
pyomo
python
relu
Keywords from Contributors
minlp
Last synced: 5 months ago
·
JSON representation
Repository
Represent trained machine learning models as Pyomo optimization formulations
Basic Info
Statistics
- Stars: 327
- Watchers: 13
- Forks: 66
- Open Issues: 30
- Releases: 0
Topics
cnn
gradient-boosted-trees
keras-neural-networks
mathematical-modelling
mathematical-programming
mixed-integer-optimization
mixed-integer-programming
modeling-language
neural-network
nonlinear-optimization
nonlinear-programming
onnx
optimization
pyomo
python
relu
Created over 4 years ago
· Last pushed 11 months ago
Metadata Files
Readme
License
Code of conduct
README.rst
.. image:: https://user-images.githubusercontent.com/282580/146039921-b3ea73af-7da3-47c1-bdfb-c40ad537a737.png
:target: https://github.com/cog-imperial/OMLT
:alt: OMLT
:align: center
:width: 200px
.. image:: https://github.com/cog-imperial/OMLT/actions/workflows/main.yml/badge.svg
:target: https://github.com/cog-imperial/OMLT/actions?workflow=CI
:alt: CI Status
.. image:: https://codecov.io/gh/cog-imperial/OMLT/branch/main/graph/badge.svg?token=9U7WLDINJJ
:target: https://codecov.io/gh/cog-imperial/OMLT
.. image:: https://readthedocs.org/projects/omlt/badge/?version=latest
:target: https://omlt.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://user-images.githubusercontent.com/31448377/202018691-dfacb0f8-620d-4d48-b918-2fa8b8da3d26.png
:target: https://www.coin-or.org/
:alt: COIN
:width: 130px
===============================================
OMLT: Optimization and Machine Learning Toolkit
===============================================
OMLT is a Python package for representing machine learning models (neural networks and gradient-boosted trees) within the Pyomo optimization environment. The package provides various optimization formulations for machine learning models (such as full-space, reduced-space, and MILP) as well as an interface to import sequential Keras and general ONNX models.
Please reference the paper for this software package as:
::
@article{ceccon2022omlt,
title={OMLT: Optimization & Machine Learning Toolkit},
author={Ceccon, F. and Jalving, J. and Haddad, J. and Thebelt, A. and Tsay, C. and Laird, C. D and Misener, R.},
journal={Journal of Machine Learning Research},
volume={23},
number={349},
pages={1--8},
year={2022}
}
When utilizing linear model decision trees, please cite the following paper in addition:
::
@article{ammari2023,
title={Linear Model Decision Trees as Surrogates in Optimization of Engineering Applications},
author= {Bashar L. Ammari and Emma S. Johnson and Georgia Stinchfield and Taehun Kim and Michael Bynum and William E. Hart and Joshua Pulsipher and Carl D. Laird},
journal={Computers \& Chemical Engineering},
volume = {178},
year = {2023},
issn = {0098-1354},
doi = {https://doi.org/10.1016/j.compchemeng.2023.108347}
}
When utilizing graph neural networks, please cite the following paper in addition:
::
@article{zhang2024,
title = {Augmenting optimization-based molecular design with graph neural networks},
author= {Shiqiang Zhang and Juan S. Campos and Christian Feldmann and Frederik Sandfort and Miriam Mathea and Ruth Misener},
journal = {Computers \& Chemical Engineering},
volume = {186},
pages = {108684},
year = {2024},
issn = {0098-1354},
doi = {https://doi.org/10.1016/j.compchemeng.2024.108684},
}
Documentation
==============
The latest OMLT documentation can be found at the `readthedocs page `_. Additionally, much of the current functionality is demonstrated using Jupyter notebooks available in the `notebooks folder `_.
Example
========
.. code-block:: Python
import tensorflow
import pyomo.environ as pyo
from omlt import OmltBlock, OffsetScaling
from omlt.neuralnet import FullSpaceNNFormulation, NetworkDefinition
from omlt.io import load_keras_sequential
#load a Keras model
nn = tensorflow.keras.models.load_model('tests/models/keras_linear_131_sigmoid', compile=False)
#create a Pyomo model with an OMLT block
model = pyo.ConcreteModel()
model.nn = OmltBlock()
#the neural net contains one input and one output
model.input = pyo.Var()
model.output = pyo.Var()
#apply simple offset scaling for the input and output
scale_x = (1, 0.5) #(mean,stdev) of the input
scale_y = (-0.25, 0.125) #(mean,stdev) of the output
scaler = OffsetScaling(offset_inputs=[scale_x[0]],
factor_inputs=[scale_x[1]],
offset_outputs=[scale_y[0]],
factor_outputs=[scale_y[1]])
#provide bounds on the input variable (e.g. from training)
scaled_input_bounds = {0:(0,5)}
#load the keras model into a network definition
net = load_keras_sequential(nn,scaler,scaled_input_bounds)
#multiple formulations of a neural network are possible
#this uses the default NeuralNetworkFormulation object
formulation = FullSpaceNNFormulation(net)
#build the formulation on the OMLT block
model.nn.build_formulation(formulation)
#query inputs and outputs, as well as scaled inputs and outputs
model.nn.inputs.display()
model.nn.outputs.display()
model.nn.scaled_inputs.display()
model.nn.scaled_outputs.display()
#connect pyomo model input and output to the neural network
@model.Constraint()
def connect_input(mdl):
return mdl.input == mdl.nn.inputs[0]
@model.Constraint()
def connect_output(mdl):
return mdl.output == mdl.nn.outputs[0]
#solve an inverse problem to find that input that most closely matches the output value of 0.5
model.obj = pyo.Objective(expr=(model.output - 0.5)**2)
status = pyo.SolverFactory('ipopt').solve(model, tee=False)
print(pyo.value(model.input))
print(pyo.value(model.output))
Development
===========
OMLT uses `just `_ to manage development tasks:
* ``just`` to list available tasks
* ``just check`` to run all checks
* ``just fix`` to apply any auto-fixes
* ``just dev`` to install development dependencies in your current Python environment
* ``just dev-gpu`` same as ``dev`` but with GPU support
* ``just docs`` to build the documentation
OMLT also includes a workflow for publishing new releases. This workflow can be triggered by pushing a new tag with an updated version number: ::
git tag # e.g. git tag v1.2.0
git push upstream --tags
Contributors
============
.. list-table::
:header-rows: 1
:widths: 10 40 50
* - GitHub
- Name
- Acknowledgements
* - |jalving|_
- Jordan Jalving
- This work was funded by Sandia National Laboratories, Laboratory Directed Research and Development program.
* - |fracek|_
- Francesco Ceccon
- This work was funded by an Engineering & Physical Sciences Research Council Research Fellowship [GrantNumber EP/P016871/1].
* - |carldlaird|_
- Carl D. Laird
- Initial work was funded by Sandia National Laboratories, Laboratory Directed Research and Development program. Current work supported by Carnegie Mellon University.
* - |tsaycal|_
- Calvin Tsay
- This work was funded by an Engineering & Physical Sciences Research Council Research Fellowship [GrantNumber EP/T001577/1], with additional support from an Imperial College Research Fellowship.
* - |thebtron|_
- Alexander Thebelt
- This work was supported by BASF SE, Ludwigshafen am Rhein.
* - |bammari|_
- Bashar L. Ammari
- This work was funded by Sandia National Laboratories, Laboratory Directed Research and Development program.
* - |juan-campos|_
- Juan S. Campos
- This work was funded by an Engineering & Physical Sciences Research Council Research Fellowship [GrantNumber EP/W003317/1].
* - |zshiqiang|_
- Shiqiang Zhang
- This work was funded by an Imperial College Hans Rausing PhD Scholarship.
.. _jalving: https://github.com/jalving
.. |jalving| image:: https://avatars1.githubusercontent.com/u/16785413?s=120&v=4
:width: 80px
.. _fracek: https://github.com/fracek
.. |fracek| image:: https://avatars1.githubusercontent.com/u/282580?s=120&v=4
:width: 80px
.. _carldlaird: https://github.com/carldlaird
.. |carldlaird| image:: https://avatars.githubusercontent.com/u/18519762?v=4
:width: 80px
.. _tsaycal: https://github.com/tsaycal
.. |tsaycal| image:: https://avatars.githubusercontent.com/u/50914878?s=120&v=4
:width: 80px
.. _thebtron: https://github.com/ThebTron
.. |thebtron| image:: https://avatars.githubusercontent.com/u/31448377?s=120&v=4
:width: 80px
.. _bammari: https://github.com/bammari
.. |bammari| image:: https://avatars.githubusercontent.com/u/96192809?v=4
:width: 80px
.. _juan-campos: https://github.com/juan-campos
.. |juan-campos| image:: https://avatars.githubusercontent.com/u/65016230?v=4
:width: 80px
.. _zshiqiang: https://github.com/zshiqiang
.. |zshiqiang| image:: https://avatars.githubusercontent.com/u/91337036?v=4
:width: 80px
Owner
- Name: C⚙G - Imperial College London
- Login: cog-imperial
- Kind: organization
- Location: London
- Website: https://optimisation.doc.ic.ac.uk/
- Repositories: 9
- Profile: https://github.com/cog-imperial
Computational Optimisation Group @ Imperial College London
GitHub Events
Total
- Issues event: 8
- Watch event: 53
- Issue comment event: 24
- Push event: 5
- Pull request review comment event: 8
- Pull request event: 12
- Pull request review event: 9
- Fork event: 6
- Create event: 3
Last Year
- Issues event: 8
- Watch event: 53
- Issue comment event: 24
- Push event: 5
- Pull request review comment event: 8
- Pull request event: 12
- Pull request review event: 9
- Fork event: 6
- Create event: 3
Committers
Last synced: about 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Francesco Ceccon | f****o@c****e | 76 |
| Carl Laird | c****d | 56 |
| jhjalvi | j****i@s****v | 51 |
| Jordan Jalving | j****g@g****m | 44 |
| at1618 | a****8@i****k | 21 |
| Jeremy Sadler | 5****r | 20 |
| adi4656 | 5****6 | 19 |
| joshuahaddad | j****d@u****u | 15 |
| jalving | y****u@e****m | 15 |
| Juan Campos | j****o@J****l | 9 |
| Calvin Tsay | c****y@i****k | 8 |
| ThebTron | 3****n | 6 |
| tsaycal | 5****l | 5 |
| joshuahaddad | j****a@s****v | 4 |
| Bashar Ammari | 9****i | 3 |
| bammari | b****i@a****u | 3 |
| zshiqiang | s****l@g****m | 3 |
| Michael Bynum | m****m@s****v | 2 |
| chrismarquez | c****z@o****m | 2 |
| Ruth Misener | r****r@i****k | 1 |
| joshuahaddad | 4****d | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 64
- Total pull requests: 96
- Average time to close issues: about 2 months
- Average time to close pull requests: 24 days
- Total issue authors: 31
- Total pull request authors: 21
- Average comments per issue: 1.55
- Average comments per pull request: 1.66
- Merged pull requests: 77
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 7
- Pull requests: 8
- Average time to close issues: 2 days
- Average time to close pull requests: 12 days
- Issue authors: 5
- Pull request authors: 5
- Average comments per issue: 2.29
- Average comments per pull request: 1.75
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- jezsadler (11)
- rmisener (7)
- jalving (6)
- carldlaird (5)
- fracek (3)
- bahar239 (2)
- bspiveyxom (2)
- tsaycal (2)
- viggotw (2)
- hhijazi (2)
- pulsipher (1)
- jsiirola (1)
- Maltimore (1)
- RuifMaxx (1)
- ssrisunt (1)
Pull Request Authors
- jalving (27)
- bammari (14)
- fracek (9)
- carldlaird (9)
- ThebTron (8)
- jezsadler (6)
- zshiqiang (4)
- tsaycal (4)
- Epanemu (4)
- emma58 (4)
- kalset1 (3)
- adi4656 (3)
- juan-campos (2)
- rmisener (2)
- emsunshine (2)
Top Labels
Issue Labels
enhancement (3)
question (1)
bug (1)
good first issue (1)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 12,652 last-month
- Total dependent packages: 2
- Total dependent repositories: 13
- Total versions: 10
- Total maintainers: 5
pypi.org: omlt
OMLT is a Python package for representing machine learning models (such as neural networks) within the Pyomo optimization environment.
- Documentation: https://omlt.readthedocs.io/
- License: ================= Copyright Notice ================= Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights in this software. Copyright (c) 2021, C⚙G - Imperial College London All rights reserved. Copyright (c) 2021, Carnegie Mellon University (Author: Carl Laird) All rights reserved. Revised BSD License ------------------- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sandia National Laboratories, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
Latest release: 1.2.2
published 11 months ago
Rankings
Dependent packages count: 3.2%
Downloads: 3.3%
Docker downloads count: 3.8%
Dependent repos count: 4.0%
Average: 4.1%
Stargazers count: 4.6%
Forks count: 5.9%
Maintainers (5)
Last synced:
6 months ago
Dependencies
.github/workflows/main.yml
actions
- actions/checkout v2 composite
- actions/setup-python v2 composite
- codecov/codecov-action v2 composite
- s-weigand/setup-conda v1 composite
pyproject.toml
pypi
setup.py
pypi
docs/requirements.txt
pypi
- importlib-metadata *
- linear-tree *
- networkx *
- numpy *
- onnx *
- pyomo *
- sphinx *
- sphinx-rtd-theme *
- tensorflow *