cog-imperial / entmoot

Multiobjective black-box optimization using gradient-boosted trees
https://entmoot.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
56 stars 12 forks source link

import Enting fails when gurobipy not installed #20

Closed R-M-Lee closed 11 months ago

R-M-Lee commented 1 year ago

I did pip install entmoot then pip install Pyomo. No gurobipy in the environment

ModuleNotFoundError                       Traceback (most recent call last)
----> 1 from entmoot import Enting

File [c:\Users\leer8\Miniconda3\envs\entmoot_test\lib\site-packages\entmoot\__init__.py:1](file:///C:/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/__init__.py:1)
----> [1](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/__init__.py?line=0) from .optimizer import Optimizer
      [2](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/__init__.py?line=1) from .optimizer import entmoot_minimize
      [3](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/__init__.py?line=2) from .space import Space

File [c:\Users\leer8\Miniconda3\envs\entmoot_test\lib\site-packages\entmoot\optimizer\__init__.py:3](file:///C:/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py:3)
      [1](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=0) from .optimizer import Optimizer
      [2](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=1) from .entmoot_minimize import entmoot_minimize
----> [3](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=2) from .entmootopti import EntmootOpti
      [5](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=4) __all__ = [
      [6](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=5)     "Optimizer","entmoot_minimize"
      [7](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/__init__.py?line=6) ]

File [c:\Users\leer8\Miniconda3\envs\entmoot_test\lib\site-packages\entmoot\optimizer\entmootopti.py:3](file:///C:/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/entmootopti.py:3)
      [1](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/entmootopti.py?line=0) from typing import Callable, Optional
----> [3](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/entmootopti.py?line=2) import gurobipy
      [4](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/entmootopti.py?line=3) import lightgbm as lgb
      [5](file:///c%3A/Users/leer8/Miniconda3/envs/entmoot_test/lib/site-packages/entmoot/optimizer/entmootopti.py?line=4) import opti

ModuleNotFoundError: No module named 'gurobipy'
R-M-Lee commented 1 year ago

I just noticed that the version on PyPI is from April 2022. Sorry. Will test with the current master branch

R-M-Lee commented 1 year ago

This is still a problem when I use the correct version, since this happens

from entmoot.optimizers.gurobi_opt import GurobiOptimizer

in entmoot/__init__.py

and gurobi_opt imports gurobipy. So we can either really make things optional and ensure that a pyomo-only installation is viable (same for gurobi-only I guess), or require both gurobipy and pyomo. They are not involved to install so I am ok with either