From 4ae1bea312bcf9aaeee05ea2b091aac4c9baa885 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 15 Dec 2023 09:02:14 -0800 Subject: [PATCH 01/10] Make Ax optional for optimas --- optimas/generators/__init__.py | 22 +++++++++++++++---- .../ax/import_error_dummy_generator.py | 18 +++++++++++++++ pyproject.toml | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 optimas/generators/ax/import_error_dummy_generator.py diff --git a/optimas/generators/__init__.py b/optimas/generators/__init__.py index dbdde09d..896c7c05 100644 --- a/optimas/generators/__init__.py +++ b/optimas/generators/__init__.py @@ -1,7 +1,21 @@ -from .ax.service.single_fidelity import AxSingleFidelityGenerator -from .ax.service.multi_fidelity import AxMultiFidelityGenerator -from .ax.service.ax_client import AxClientGenerator -from .ax.developer.multitask import AxMultitaskGenerator +# Import Ax generators +try: + from .ax.service.single_fidelity import AxSingleFidelityGenerator + from .ax.service.multi_fidelity import AxMultiFidelityGenerator + from .ax.service.ax_client import AxClientGenerator + from .ax.developer.multitask import AxMultitaskGenerator +except ImportError as e: + if e.__str__() == "No module named 'ax'": + # Replace generators by dummy generators that will + # raise an error only if the user tries to instantiate them + # and tell them to install ax-platform + from .ax.import_error_dummy_generator import AxImportErrorDummyGenerator + AxSingleFidelityGenerator = AxImportErrorDummyGenerator + AxMultiFidelityGenerator = AxImportErrorDummyGenerator + AxClientGenerator = AxImportErrorDummyGenerator + AxMultitaskGenerator = AxImportErrorDummyGenerator + +# Import optimas native generators from .grid_sampling import GridSamplingGenerator from .line_sampling import LineSamplingGenerator from .random_sampling import RandomSamplingGenerator diff --git a/optimas/generators/ax/import_error_dummy_generator.py b/optimas/generators/ax/import_error_dummy_generator.py new file mode 100644 index 00000000..976ad00c --- /dev/null +++ b/optimas/generators/ax/import_error_dummy_generator.py @@ -0,0 +1,18 @@ +"""Contains the definition of dummy generator that raises an import error""" + +class AxImportErrorDummyGenerator(object): + """Class that raises an error when instantiated, telling + the user to install ax-platform. + + This class replaces all other Ax-based classes, + when Ax is not installed + """ + + def __init__( + self, *args, **kwargs + ) -> None: + raise RuntimeError( + "You need to install ax-platform, in order " + "to use Ax-based generators in optimas.\n" + "e.g. with `pip install ax-platform >= 0.3.4`" + ) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 99893642..41607547 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ classifiers = [ dependencies = [ 'libensemble @ git+https://github.com/Libensemble/libensemble@develop', 'jinja2', - 'ax-platform >= 0.3.4', 'mpi4py', ] dynamic = ['version'] @@ -33,6 +32,7 @@ dynamic = ['version'] test = [ 'flake8', 'pytest', + 'pandas', 'matplotlib', ] From d1a1ac96ba3ff7058dfd5d42b8d469f434a9b471 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:05:23 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- optimas/generators/__init__.py | 1 + optimas/generators/ax/import_error_dummy_generator.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/optimas/generators/__init__.py b/optimas/generators/__init__.py index 896c7c05..7075139c 100644 --- a/optimas/generators/__init__.py +++ b/optimas/generators/__init__.py @@ -10,6 +10,7 @@ # raise an error only if the user tries to instantiate them # and tell them to install ax-platform from .ax.import_error_dummy_generator import AxImportErrorDummyGenerator + AxSingleFidelityGenerator = AxImportErrorDummyGenerator AxMultiFidelityGenerator = AxImportErrorDummyGenerator AxClientGenerator = AxImportErrorDummyGenerator diff --git a/optimas/generators/ax/import_error_dummy_generator.py b/optimas/generators/ax/import_error_dummy_generator.py index 976ad00c..e27e0d46 100644 --- a/optimas/generators/ax/import_error_dummy_generator.py +++ b/optimas/generators/ax/import_error_dummy_generator.py @@ -1,5 +1,6 @@ """Contains the definition of dummy generator that raises an import error""" + class AxImportErrorDummyGenerator(object): """Class that raises an error when instantiated, telling the user to install ax-platform. @@ -8,11 +9,9 @@ class AxImportErrorDummyGenerator(object): when Ax is not installed """ - def __init__( - self, *args, **kwargs - ) -> None: + def __init__(self, *args, **kwargs) -> None: raise RuntimeError( "You need to install ax-platform, in order " "to use Ax-based generators in optimas.\n" "e.g. with `pip install ax-platform >= 0.3.4`" - ) \ No newline at end of file + ) From 493dc645da43ae5ab58f64b12d2bedefd7bfacf8 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 15 Dec 2023 09:07:00 -0800 Subject: [PATCH 03/10] Raise error if it is not an Ax import error --- optimas/generators/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/optimas/generators/__init__.py b/optimas/generators/__init__.py index 896c7c05..63d009e0 100644 --- a/optimas/generators/__init__.py +++ b/optimas/generators/__init__.py @@ -14,6 +14,8 @@ AxMultiFidelityGenerator = AxImportErrorDummyGenerator AxClientGenerator = AxImportErrorDummyGenerator AxMultitaskGenerator = AxImportErrorDummyGenerator + else: + raise(e) # Import optimas native generators from .grid_sampling import GridSamplingGenerator From 27f81c8930c27806f65ec5419fa89b3322b61ba6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:08:05 +0000 Subject: [PATCH 04/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- optimas/generators/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimas/generators/__init__.py b/optimas/generators/__init__.py index 60ace035..237fb921 100644 --- a/optimas/generators/__init__.py +++ b/optimas/generators/__init__.py @@ -16,7 +16,7 @@ AxClientGenerator = AxImportErrorDummyGenerator AxMultitaskGenerator = AxImportErrorDummyGenerator else: - raise(e) + raise (e) # Import optimas native generators from .grid_sampling import GridSamplingGenerator From b310826781b12c98f339eaa2651f06838aec1dcc Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Mon, 18 Dec 2023 06:45:43 -0800 Subject: [PATCH 05/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ángel Ferran Pousa --- pyproject.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 41607547..b7da747e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ classifiers = [ dependencies = [ 'libensemble @ git+https://github.com/Libensemble/libensemble@develop', 'jinja2', + 'pandas', 'mpi4py', ] dynamic = ['version'] @@ -32,10 +33,12 @@ dynamic = ['version'] test = [ 'flake8', 'pytest', - 'pandas', + 'ax-platform >= 0.3.4', 'matplotlib', ] - +full = [ + 'ax-platform >= 0.3.4', +] [project.urls] Documentation = 'https://optimas.readthedocs.io/' From b8ea1be4076377888f7fe2f527d53e47303360ad Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 20 Dec 2023 10:49:52 -0800 Subject: [PATCH 06/10] Fix Docstyle --- optimas/generators/ax/import_error_dummy_generator.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/optimas/generators/ax/import_error_dummy_generator.py b/optimas/generators/ax/import_error_dummy_generator.py index e27e0d46..87dc1fa0 100644 --- a/optimas/generators/ax/import_error_dummy_generator.py +++ b/optimas/generators/ax/import_error_dummy_generator.py @@ -1,9 +1,8 @@ -"""Contains the definition of dummy generator that raises an import error""" +"""Contains the definition of dummy generator that raises an import error.""" class AxImportErrorDummyGenerator(object): - """Class that raises an error when instantiated, telling - the user to install ax-platform. + """Class that raises an error when instantiated, telling the user to install ax-platform. This class replaces all other Ax-based classes, when Ax is not installed From 133c87cfbdf021943b36225bd0f718959514b333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ferran=20Pousa?= Date: Fri, 22 Dec 2023 14:40:58 +0100 Subject: [PATCH 07/10] Change `full` to `all` --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b5d577a9..3ae663d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,9 +37,10 @@ test = [ 'ax-platform >= 0.3.4', 'matplotlib', ] -full = [ +all = [ 'ax-platform >= 0.3.4', ] + [project.urls] Documentation = 'https://optimas.readthedocs.io/' From 6a79a7b330927ff421f06f0c3c4719315a3277d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ferran=20Pousa?= Date: Fri, 22 Dec 2023 15:27:17 +0100 Subject: [PATCH 08/10] Update docs --- doc/source/user_guide/dependencies.rst | 43 +++++++++++++++++-- doc/source/user_guide/installation_juwels.rst | 5 ++- doc/source/user_guide/installation_local.rst | 25 +++++++++-- .../user_guide/installation_maxwell.rst | 5 ++- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/doc/source/user_guide/dependencies.rst b/doc/source/user_guide/dependencies.rst index d7eeddc5..9286a3bf 100644 --- a/doc/source/user_guide/dependencies.rst +++ b/doc/source/user_guide/dependencies.rst @@ -1,9 +1,46 @@ +.. _dependencies: + Dependencies ============ Optimas relies on the following packages: -* `mpi4py `_ - Python bindings for MPI. Required for launching parallel simulations. -* `libEnsemble `_ - The backbone of optimas, orchestrates the concurrent evaluation of simulations, the resource detection and allocation, and the communication between simulations and manager. * `jinja2 `_ - Needed to generate simulation scripts from templates. -* `Ax `_ - Algorithms for Bayesian optimization. +* `libEnsemble `_ - The backbone of optimas, orchestrates the concurrent evaluation of simulations, the resource detection and allocation, and the communication between simulations and manager. +* `mpi4py `_ - Python bindings for MPI. Required for launching parallel simulations. +* `pandas `_ - Enable output as pandas DataFrames. +* `pydantic `_ - Input validation and object serialization. +* (optional) `Ax `_ - Algorithms for Bayesian optimization. + + +The installed dependencies will determine which generators are available for use. +See table below for a summary. + +.. list-table:: Available generators and their dependencies + :widths: 35 25 25 + :header-rows: 1 + + * - Generator + - ``pip install optimas`` + - ``pip install optimas[all]`` + * - :class:`~optimas.generators.LineSamplingGenerator` + - ✅ + - ✅ + * - :class:`~optimas.generators.GridSamplingGenerator` + - ✅ + - ✅ + * - :class:`~optimas.generators.RandomSamplingGenerator` + - ✅ + - ✅ + * - :class:`~optimas.generators.AxSingleFidelityGenerator` + - ❌ + - ✅ + * - :class:`~optimas.generators.AxMultiFidelityGenerator` + - ❌ + - ✅ + * - :class:`~optimas.generators.AxMultitaskGenerator` + - ❌ + - ✅ + * - :class:`~optimas.generators.AxClientGenerator` + - ❌ + - ✅ diff --git a/doc/source/user_guide/installation_juwels.rst b/doc/source/user_guide/installation_juwels.rst index 7653abf6..2cc70303 100644 --- a/doc/source/user_guide/installation_juwels.rst +++ b/doc/source/user_guide/installation_juwels.rst @@ -42,11 +42,12 @@ Activate the environment source $PROJECT//pyenvs/optimas_env/bin/activate -Install ``optimas`` +Install ``optimas`` with all dependencies if you plan to do Bayesian optimization +(see :ref:`dependencies` for more details). .. code:: - pip install optimas + pip install optimas[all] Installing FBPIC and Wake-T (optional) diff --git a/doc/source/user_guide/installation_local.rst b/doc/source/user_guide/installation_local.rst index e9f738d3..072d9a61 100644 --- a/doc/source/user_guide/installation_local.rst +++ b/doc/source/user_guide/installation_local.rst @@ -31,10 +31,29 @@ On Windows: conda install -c conda-forge mpi4py msmpi -Install optimas -~~~~~~~~~~~~~~~ -Install the latest release from PyPI +Install optimas from PyPI (recommended) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This will install the latest stable release. + +Installing with only the **basic** dependencies: .. code:: pip install optimas + +Installing with **all** dependencies: + +.. code:: + + pip install optimas[all] + +Use this option if you plan to do Bayesian optimization +(see :ref:`dependencies` for more details). + +Install from GitHub +~~~~~~~~~~~~~~~~~~~ +This will install the latest development version with all dependencies. + +.. code:: + + pip install "optimas[all] @ git+https://github.com/optimas-org/optimas.git" diff --git a/doc/source/user_guide/installation_maxwell.rst b/doc/source/user_guide/installation_maxwell.rst index 363155d6..da9f5e74 100644 --- a/doc/source/user_guide/installation_maxwell.rst +++ b/doc/source/user_guide/installation_maxwell.rst @@ -51,11 +51,12 @@ Install ``mpi4py`` pip install mpi4py --no-cache-dir -Install ``optimas`` +Install ``optimas`` with all dependencies if you plan to do Bayesian optimization +(see :ref:`dependencies` for more details). .. code:: - pip install optimas + pip install optimas[all] Installing FBPIC and Wake-T (optional) From 4c1531455fdef396b2c770e57621695d562ec87e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:27:31 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/source/user_guide/installation_local.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/installation_local.rst b/doc/source/user_guide/installation_local.rst index 072d9a61..9483c748 100644 --- a/doc/source/user_guide/installation_local.rst +++ b/doc/source/user_guide/installation_local.rst @@ -56,4 +56,4 @@ This will install the latest development version with all dependencies. .. code:: - pip install "optimas[all] @ git+https://github.com/optimas-org/optimas.git" + pip install "optimas[all] @ git+https://github.com/optimas-org/optimas.git" From d8c4022f4e83d532b1668b94fdc9d3f96f245d01 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 22 Dec 2023 07:57:10 -0800 Subject: [PATCH 10/10] Update Perlmutter installation instructions --- doc/source/user_guide/installation_perlmutter.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/installation_perlmutter.rst b/doc/source/user_guide/installation_perlmutter.rst index 6255e488..d00b944f 100644 --- a/doc/source/user_guide/installation_perlmutter.rst +++ b/doc/source/user_guide/installation_perlmutter.rst @@ -17,7 +17,7 @@ environment, in which to install *optimas*. python3 -m venv $HOME/sw/perlmutter/gpu/venvs/optimas source $HOME/sw/perlmutter/gpu/venvs/optimas/bin/activate - python3 -m pip install optimas + pip install optimas[all] Running an optimas job ~~~~~~~~~~~~~~~~~~~~~~