Skip to content

Commit

Permalink
Implement ENTMOOT in Bofire (#278)
Browse files Browse the repository at this point in the history
* Convert features and constraints to entmoot

* EntingStrategy functional and datamodel

* Ask implemented for Enting with example

* Convert Enting to Predictive

* Implement multi objective and maximization

* Refactor, move files to appropriate directories

* Enting docstrings and test for domain conversion

* Multiple candidates generated in ask

* Implement new entmoot constraints

* Implement new entmoot Maximize objective

* Implement new entmoot EntingParams

* Implement entmoot.ConstraintList

* Create data models for Enting parameters

* Update field default factory for entingparams

Co-authored-by: Johannes P. Dürholt <[email protected]>

* Test serialization for enting

* Intial Enting tests, add to bofire api

* Add tests for functionality of Enting Stratey

* Update bofire/data_models/strategies/predictives/enting.py

Co-authored-by: Johannes P. Dürholt <[email protected]>

* Typing updates to enting

* Merge entmoot utils into enting

* Fix assumed ordering of features in tests

* Create entmoot extra

* Flatten Enting parameters

* Enting tests for parameter consistency

* Add specs test for entmoot

* Clarified behaviour of kappa_fantasy in enting

* Clean up batch proposals for enting

* Safer imports in test_enting

* Move enting helper methods

* Fix enting imports/installs; minor bugs in tests

* Fix import-dependent type hints

* Commit to trigger workflow

* Fix problematic imports in test_enting

* Add entmoot to tests that need it

* More changes to fix pipeline

* Add ignores for pyright

* Check if gurobi license is available; remove notebook

* Mark tests requiring Gurobi as slow

* Add EntingStrategy to types

* Add Enting to mapper

---------

Co-authored-by: Johannes P. Dürholt <[email protected]>
  • Loading branch information
TobyBoyne and jduerholt authored Mar 15, 2024
1 parent ca8515f commit 86f1220
Show file tree
Hide file tree
Showing 10 changed files with 731 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
shell: bash -l {0}
run: |
conda install -c conda-forge cyipopt
pip install ".[optimization,tests,cheminfo,xgb]"
pip install ".[optimization,tests,cheminfo,xgb,entmoot]"
- name: Run tests, Python ${{ matrix.python-version }}
shell: bash -l {0}
run: pytest -ra --cov=bofire --cov-report term-missing tests
Expand All @@ -64,7 +64,7 @@ jobs:
pip install --upgrade git+https://github.com/cornellius-gp/gpytorch.git
export ALLOW_LATEST_GPYTORCH_LINOP=true
pip install --upgrade git+https://github.com/pytorch/botorch.git
pip install ".[optimization,tests,cheminfo,xgb]"
pip install ".[optimization,tests,cheminfo,xgb,entmoot]"
- name: Run tests, Python ${{ matrix.python-version }}
shell: bash -l {0}
run: pytest -ra --cov=bofire --cov-report term-missing tests
Expand All @@ -86,7 +86,7 @@ jobs:
shell: bash -l {0}
run: |
conda install -c conda-forge cyipopt
pip install ".[optimization,tests,cheminfo,xgb]"
pip install ".[optimization,tests,cheminfo,xgb,entmoot]"
- name: Run notebooks
shell: bash -l {0}
run: python scripts/run_tutorials.py -p "$(pwd)"
Expand Down
2 changes: 2 additions & 0 deletions bofire/data_models/strategies/actual_strategy_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from bofire.data_models.strategies.doe import DoEStrategy
from bofire.data_models.strategies.factorial import FactorialStrategy
from bofire.data_models.strategies.predictives.enting import EntingStrategy
from bofire.data_models.strategies.predictives.mobo import MoboStrategy
from bofire.data_models.strategies.predictives.qehvi import QehviStrategy
from bofire.data_models.strategies.predictives.qnehvi import QnehviStrategy
Expand All @@ -24,6 +25,7 @@
QehviStrategy,
QnehviStrategy,
QparegoStrategy,
EntingStrategy,
SpaceFillingStrategy,
RandomStrategy,
DoEStrategy,
Expand Down
2 changes: 2 additions & 0 deletions bofire/data_models/strategies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bofire.data_models.strategies.factorial import FactorialStrategy
from bofire.data_models.strategies.meta_strategy_type import MetaStrategy
from bofire.data_models.strategies.predictives.botorch import LSRBO, BotorchStrategy
from bofire.data_models.strategies.predictives.enting import EntingStrategy
from bofire.data_models.strategies.predictives.mobo import MoboStrategy
from bofire.data_models.strategies.predictives.multiobjective import (
MultiobjectiveStrategy,
Expand Down Expand Up @@ -55,6 +56,7 @@
QehviStrategy,
QnehviStrategy,
QparegoStrategy,
EntingStrategy,
MoboStrategy,
]

Expand Down
78 changes: 78 additions & 0 deletions bofire/data_models/strategies/predictives/enting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from typing import Any, Dict, Literal, Type

from pydantic import PositiveFloat, PositiveInt

from bofire.data_models.constraints.api import (
Constraint,
LinearEqualityConstraint,
LinearInequalityConstraint,
NChooseKConstraint,
)
from bofire.data_models.features.api import (
CategoricalDescriptorInput,
CategoricalInput,
ContinuousInput,
ContinuousOutput,
DiscreteInput,
Feature,
)
from bofire.data_models.objectives.api import (
MaximizeObjective,
MinimizeObjective,
Objective,
)
from bofire.data_models.strategies.predictives.predictive import PredictiveStrategy


class EntingStrategy(PredictiveStrategy):
type: Literal["EntingStrategy"] = "EntingStrategy"

# uncertainty model parameters
beta: PositiveFloat = 1.96
bound_coeff: PositiveFloat = 0.5
acq_sense: Literal["exploration", "penalty"] = "exploration"
dist_trafo: Literal["normal", "standard"] = "normal"
dist_metric: Literal["euclidean_squared", "l1", "l2"] = "euclidean_squared"
cat_metric: Literal["overlap", "of", "goodall4"] = "overlap"

# lightgbm training hyperparameters
# see https://lightgbm.readthedocs.io/en/latest/Parameters.html
num_boost_round: PositiveInt = 100
max_depth: PositiveInt = 3
min_data_in_leaf: PositiveInt = 1
min_data_per_group: PositiveInt = 1
verbose: Literal[-1, 0, 1, 2] = -1

# pyomo parameters
solver_name: str = "gurobi"
solver_verbose: bool = False
solver_params: Dict[str, Any] = {}

# kappa_fantasy determines a bound on the predicted value of an unseen point
# used for making batch predictions, y* = mean + kappa_fantasy * std
# for a both min and max problems, a positive value is 'pesimistic'
# and a negative value is 'optimistic'
# a value of zero implies future observations will be exactly the mean
kappa_fantasy: float = 1.96

@classmethod
def is_constraint_implemented(cls, my_type: Type[Constraint]) -> bool:
return my_type in [
LinearEqualityConstraint,
LinearInequalityConstraint,
NChooseKConstraint,
]

@classmethod
def is_feature_implemented(cls, my_type: Type[Feature]) -> bool:
return my_type in [
CategoricalInput,
DiscreteInput,
CategoricalDescriptorInput,
ContinuousInput,
ContinuousOutput,
]

@classmethod
def is_objective_implemented(cls, my_type: Type[Objective]) -> bool:
return my_type in [MinimizeObjective, MaximizeObjective]
1 change: 1 addition & 0 deletions bofire/strategies/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from bofire.strategies.doe_strategy import DoEStrategy
from bofire.strategies.mapper import map
from bofire.strategies.predictives.botorch import BotorchStrategy
from bofire.strategies.predictives.enting import EntingStrategy
from bofire.strategies.predictives.predictive import PredictiveStrategy
from bofire.strategies.predictives.qehvi import QehviStrategy
from bofire.strategies.predictives.qnehvi import QnehviStrategy
Expand Down
2 changes: 2 additions & 0 deletions bofire/strategies/mapper_actual.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bofire.data_models.strategies.api as data_models
from bofire.strategies.doe_strategy import DoEStrategy
from bofire.strategies.factorial import FactorialStrategy
from bofire.strategies.predictives.enting import EntingStrategy
from bofire.strategies.predictives.mobo import MoboStrategy
from bofire.strategies.predictives.qehvi import QehviStrategy
from bofire.strategies.predictives.qnehvi import QnehviStrategy
Expand All @@ -27,6 +28,7 @@
data_models.QehviStrategy: QehviStrategy,
data_models.QnehviStrategy: QnehviStrategy,
data_models.QparegoStrategy: QparegoStrategy,
data_models.EntingStrategy: EntingStrategy,
data_models.SpaceFillingStrategy: SpaceFillingStrategy,
data_models.DoEStrategy: DoEStrategy,
data_models.FactorialStrategy: FactorialStrategy,
Expand Down
Loading

0 comments on commit 86f1220

Please sign in to comment.