Introduction
OMLT (Optimization & Machine Learning Toolkit) is an open-source Python library designed to bridge the gap between machine learning (ML) and mathematical optimization. In modern engineering and computer science, decisions often rely on complex systems represented by ML models. For instance, an engineer might use a neural network (NN) as a surrogate for a chemical process where the underlying physics is too complex for simple equations.
However, integrating trained ML models—such as ReLU networks or gradient-boosted trees (GBTs)—into formal mathematical optimization frameworks (consisting of variables, constraints, and objectives) is a significant challenge. This process is typically tedious, error-prone, and sensitive to the specific mathematical "formulation" used, which can drastically affect solver performance. OMLT automates this translation, allowing researchers to focus on problem-solving rather than implementation details.
Methodology
OMLT acts as a middle layer between ML frameworks and optimization solvers. Its architecture is built upon three key pillars:
- Universal Input via ONNX: By using the Open Neural Network Exchange (ONNX) format, OMLT remains framework-agnostic. It supports models trained in PyTorch, TensorFlow, Keras, and scikit-learn.
- Pyomo Integration: OMLT transforms ML models into "Blocks" within Pyomo, a popular Python-based algebraic modeling language. This allows the ML model to be seamlessly embedded as a component of a larger optimization problem.
- Multiple Formulations: The toolkit provides a library of mathematical formulations. For neural networks, it supports smooth activations (sigmoid, tanh) and non-smooth activations (ReLU) via Big-M, complementarity, and partition-based formulations. For GBTs, it implements efficient Big-M formulations.
Key Features and Insights
A core strength of OMLT is the "Block" abstraction. By treating the ML model as a Pyomo Block, the toolkit hides underlying complexity—such as hundreds of constraints and auxiliary variables—from the user. Users only need to define the inputs and outputs.
Furthermore, OMLT addresses the "Information Gap" often found in ML models, which frequently lack the scaling and variable bound information necessary for efficient optimization. OMLT provides a structured way to inject this metadata. Perhaps most importantly, it allows users to switch between different mathematical formulations (e.g., from Big-M to Partition-based ReLU) with a single line of code, facilitating easy benchmarking to find the most efficient approach for a specific solver.
Applications and Results
OMLT has been evaluated across several diverse domains:
- AI Safety: Using the MNIST dataset, OMLT was used to verify neural network robustness against adversarial perturbations.
- Industrial Engineering: In collaboration with the IDAES-PSE project, OMLT integrated NN surrogates to replace complex physical simulations of an "auto-thermal reformer," speeding up design and operation optimization.
- Black-Box Optimization: OMLT simplifies GBT-based optimization through integration with tools like ENTMOOT.
The toolkit demonstrates significant automation efficiency. For a sample ReLU network, OMLT can instantly toggle between formulations involving 248, 308, or 428 constraints. Version 1.0 supports dense and convolutional layers along with a wide range of activation functions including ReLU, linear, softplus, sigmoid, and tanh.
Limitations and Future Directions
While OMLT 1.0 is highly versatile, there are areas for growth. Currently, support is focused on dense and convolutional layers; more complex architectures like Transformers or LSTMs are not yet explicitly supported. Additionally, some advanced formulations, such as partition-based ReLUs, are currently restricted to dense layers. Finally, while OMLT streamlines model construction, the ultimate performance remains dependent on the underlying solver's ability to handle the resulting mixed-integer or non-linear constraints. Future work will likely focus on developing even more "solver-friendly" formulations.
Summary updated