Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OMLT 1.0 missing required dependency #96

Closed
jsiirola opened this issue Oct 17, 2022 · 3 comments
Closed

OMLT 1.0 missing required dependency #96

jsiirola opened this issue Oct 17, 2022 · 3 comments

Comments

@jsiirola
Copy link

I believe that there is a missing required dependency in the OMLT 1.0 release: onnx is listed as a "testing" dependency, but is required in order to import anything from omlt.io.

Steps to reproduce:

% pip install --user omlt
Collecting omlt
  Downloading omlt-1.0-py2.py3-none-any.whl (29 kB)
Requirement already satisfied: importlib-metadata in [...] (from omlt) (4.8.1)
Requirement already satisfied: numpy in [...] (from omlt) (1.21.2)
Requirement already satisfied: pyomo in [...] (from omlt) (6.4.3.dev0)
Requirement already satisfied: networkx in [...] (from omlt) (2.6.3)
Requirement already satisfied: typing-extensions>=3.6.4 in [...] (from importlib-metadata->omlt) (3.10.0.2)
Requirement already satisfied: zipp>=0.5 in [...] (from importlib-metadata->omlt) (3.4.0)
Requirement already satisfied: ply in [...] (from pyomo->omlt) (3.11)
Installing collected packages: omlt
Successfully installed omlt-1.0
% python
Python 3.7.12 (default, Nov 10 2021, 15:38:43)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from omlt.io.keras_reader import load_keras_sequential
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/site-packages/omlt/io/__init__.py", line 1, in <module>
    from omlt.io.onnx import load_onnx_neural_network, write_onnx_model_with_bounds, load_onnx_neural_network_with_bounds
  File "[...]/site-packages/omlt/io/onnx.py", line 4, in <module>
    import onnx
ModuleNotFoundError: No module named 'onnx'

Possible solutions:

  • Don't import anything from omlt/io/__init__.py
  • Leverage a delayed import mechanism in omlt/io/onnx.py (e.g., something like pyomo.common.dependencies.attempt_import())
  • Add onnx as a required dependency
@jalving
Copy link
Collaborator

jalving commented Oct 17, 2022

I see, even if you have tensorflow installed, it will hit the onnx code when you try to use the keras reader.

I think I'm in favor of either/both of the first two suggestions. Maybe we shouldn't be importing anything in omlt/io/__init__.py and also attempt what Pyomo does.

I remember talking with @carldlaird about this. We'll come up with something to clean this up.

@jalving
Copy link
Collaborator

jalving commented Nov 27, 2022

@jsiirola this should now be fixed in main with PR #97. We are prepping to cut a new OMLT release soon.

@tsaycal
Copy link
Collaborator

tsaycal commented May 4, 2023

Thanks @jalving. The PR has been incorporated into OMLT 1.1.

@tsaycal tsaycal closed this as completed May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants