File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 4
4
from .ax .service .multi_fidelity import AxMultiFidelityGenerator
5
5
from .ax .service .ax_client import AxClientGenerator
6
6
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" ) :
9
9
# Replace generators by dummy generators that will
10
10
# raise an error only if the user tries to instantiate them
11
11
# and tell them to install ax-platform
Original file line number Diff line number Diff line change 29
29
30
30
ax_installed = True
31
31
except ImportError :
32
+ from .import_error_dummy_class import AxImportErrorDummyClass
33
+ AxClient = AxImportErrorDummyClass
34
+ TorchModelBridge = AxImportErrorDummyClass
32
35
ax_installed = False
33
36
37
+
34
38
from optimas .core import VaryingParameter , Objective
35
39
from optimas .utils .other import convert_to_dataframe
36
40
Original file line number Diff line number Diff line change
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
+ )
You can’t perform that action at this time.
0 commit comments