cog-imperial / OMLT

Represent trained machine learning models as Pyomo optimization formulations
Other
284 stars 59 forks source link

update io __init__.py with attempt import #97

Closed jalving closed 2 years ago

jalving commented 2 years ago

This PR uses the pyomo attempt_import to defer the import of dependent packages until they are used (or to check if the package exists). See src/omlt/dependencies.py. This should address issue #96.

The function attempt_import offers a lot of extra functionality - not sure whether we need to use all of it.

E.g., to check if keras (or onnx) is available, use: from omlt.dependencies import keras_available

E.g., to import keras (or onnx) use: from omlt.dependencies import keras

If you then try to use keras and it is not installed, Pyomo's attempt import will throw an exception.

Legal Acknowledgement\ By contributing to this software project, I agree my contributions are submitted under the BSD license. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

codecov[bot] commented 2 years ago

Codecov Report

Merging #97 (0f55ad2) into main (d688364) will decrease coverage by 0.11%. The diff coverage is 77.77%.

@@            Coverage Diff             @@
##             main      #97      +/-   ##
==========================================
- Coverage   95.08%   94.97%   -0.12%     
==========================================
  Files          25       26       +1     
  Lines        1364     1372       +8     
  Branches      189      191       +2     
==========================================
+ Hits         1297     1303       +6     
  Misses         37       37              
- Partials       30       32       +2     
Impacted Files Coverage Δ
src/omlt/io/__init__.py 60.00% <60.00%> (-40.00%) :arrow_down:
src/omlt/dependencies.py 100.00% <100.00%> (ø)
src/omlt/formulation.py 92.64% <100.00%> (+0.10%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

jalving commented 2 years ago

a couple quick notes: