Add Support for Pyomo/OMLT Models in Inverse (nlp_based) and Forward (AIS2AOS) Mapping#33
Add Support for Pyomo/OMLT Models in Inverse (nlp_based) and Forward (AIS2AOS) Mapping#33hfsf wants to merge 3 commits intoCODES-group:mainfrom
Conversation
…S2AOS_map with Pyomo/OMLT models
|
Hi @hfsf! Thank you for this great addition! I've the plans to add this myself (but couldn't find the time to), so I appreciate your efforts in making it happen. I'm currently reviewing your PR and should be able to incorporate it to the tool, give you the proper and deserved credit/acknowledgement in the next release, and plan to have an example in the Examples gallery. Speaking of examples, could you prepare a more comprehensive OMLT/IDAES example, inspired by the "look-and-feel" of the ones present in the Examples Gallery, so we could have an end-to-end case-study? This can be done in a second PR later in the future, after I incorporate this one, or you could modify this PR. Your call. Many thanks again for contributing! |
|
Hey @hfsf, thanks for this contribution! The Pyomo/OMLT integration is a great addition. I tested both That said, there are a few things that need to be addressed before we can merge: Critical
Medium
Minor
Test resultsExisting tests pass (3/4;
Overall the implementation logic is solid. Just needs the dependency fix and the cleanup items above. Let me know if you have any questions! |
|
Hi @victoraalves, Sorry for the delay in responding and thank you for the detailed fix plan. I will implement the suggested fix and update this PR soon. |
This PR introduces native support for Pyomo and OMLT (Optimization and Machine Learning Toolkit) models within the
opyrabilityframework.Previously, the library treated process models strictly as "black-box" callables, relying on finite differences or external JAX wrappers for derivatives. This update enables an equation-oriented (glass-box) approach, allowing the
ipoptsolver to access exact Hessians and Jacobians directly from the algebraic structure.This is particularly useful for integrating Neural Networks (via OMLT) or rigorous thermodynamic models (via IDAES) into the operability analysis workflow.
Key Changes
1.
nlp_based_approach(Inverse Mapping)modelis a Pyomo constructor (e.g., hasbuild_pyomo_constraintsattribute) or an OMLT object.pyomo.ConcreteModeland solves it directly using the IPOPT interface, bypassingscipy.optimize.2.
AIS2AOS_map(Forward Mapping)output_dim(required for Pyomo models) to correctly initialize result arrays.appsi_ipopt(Auto-Persistent Solver Interface) if available. This keeps the solver loaded in memory, reducing I/O overhead by orders of magnitude.appsi_ipoptis not installed/configured, it gracefully falls back to the standardipoptexecutable.3.
implicit_mapNotImplementedErrorguard. If a user attempts to pass a Pyomo model toimplicit_map, the function returns a clear error message explaining that JAX/JIT dependencies make it currently incompatible.4. Examples (
shower.py)shower.pyexample file to includebuild_shower*functions. These serve as clean examples of how users should define algebraic models for the new interface, preserving the original NumPy functions for backward compatibility.Performance Note on
AIS2AOS_mapWhen using Pyomo models for forward mapping, there is an inherent overhead compared to pure NumPy callables due to the Python-to-Solver I/O.
appsi_ipopt: Performance is comparable to fast simulation.ipopt: There is a known I/O overhead per point (~0.05s). The implemented warm-start strategy mitigates the mathematical solution time, making it viable for standard grid resolutions.How to Test
You can test the new functionality using the updated
shower.py: