Skip to content

Commit d6221cc

Browse files
committed
Fix import of AxModelManager
1 parent b057090 commit d6221cc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

optimas/generators/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from .ax.service.multi_fidelity import AxMultiFidelityGenerator
55
from .ax.service.ax_client import AxClientGenerator
66
from .ax.developer.multitask import AxMultitaskGenerator
7-
except ImportError as e:
8-
if e.__str__() == "No module named 'ax'":
7+
except (ImportError, ModuleNotFoundError) as e:
8+
if e.__str__().startswith("No module named 'ax"):
99
# Replace generators by dummy generators that will
1010
# raise an error only if the user tries to instantiate them
1111
# and tell them to install ax-platform

optimas/utils/ax/ax_model_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
ax_installed = True
3131
except ImportError:
32+
from .import_error_dummy_class import AxImportErrorDummyClass
33+
AxClient = AxImportErrorDummyClass
34+
TorchModelBridge = AxImportErrorDummyClass
3235
ax_installed = False
3336

37+
3438
from optimas.core import VaryingParameter, Objective
3539
from optimas.utils.other import convert_to_dataframe
3640

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Contains the definition of dummy class that raises an import error."""
2+
3+
4+
class AxImportErrorDummyClass(object):
5+
"""Class that raises an error when instantiated, telling the user to install ax-platform.
6+
7+
This class replaces all other Ax-based classes, when Ax is not installed
8+
"""
9+
10+
def __init__(self, *args, **kwargs) -> None:
11+
raise RuntimeError(
12+
"You need to install ax-platform, in order "
13+
"to use Ax-based generators in optimas.\n"
14+
"e.g. with `pip install ax-platform > 0.5.0`"
15+
)

0 commit comments

Comments
 (0)