Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of DoEStrategy data model class #448

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
98668ae
add draft of restrucuted doe class
jduerholt Oct 11, 2024
d83e241
refactoring doe
Dec 4, 2024
8441817
Merge branch 'main' into refactor/doe_data_model
dlinzner-bcs Dec 4, 2024
fca9559
add formulaic to be installed always
Dec 4, 2024
a825e68
add formulaic to be installed always
Dec 4, 2024
ba22c38
add formulaic to be installed always
Dec 4, 2024
f760838
add formulaic to be installed always
Dec 4, 2024
035d8db
check style
Dec 4, 2024
ea9011d
check style
Dec 4, 2024
19b4bae
check style
Dec 4, 2024
73d4461
remove enumns
Dec 5, 2024
bf21702
remove enumns
Dec 5, 2024
08d8565
remove enumns
Dec 5, 2024
94453f6
fix branch and bound
Dec 5, 2024
6c7ebce
move delta into criterion
Dec 5, 2024
9487eda
move delta into criterion
Dec 5, 2024
652d7a0
move delta into criterion
Dec 5, 2024
152e96d
move delta into criterion
Dec 5, 2024
35e9bcb
move default criterion
Dec 5, 2024
545acc8
move default criterion
Dec 5, 2024
45428b2
move default criterion
Dec 5, 2024
e9ab45f
move default criterion
Dec 5, 2024
028a2c0
refactor formulas and number of experiments
Dec 6, 2024
2d4a850
pyright
Dec 6, 2024
8706a59
fix test
Dec 10, 2024
b0863e1
Merge remote-tracking branch 'origin/main' into refactor/doe_data_model
Dec 10, 2024
ca5fc52
fix test
Dec 10, 2024
a69654f
fix test
Dec 11, 2024
7aa8dfa
fix test
Dec 12, 2024
6136202
fix tutorial
Dec 12, 2024
388e79e
fix tutorial
Dec 12, 2024
5374b4b
fix tutorial
Dec 12, 2024
b61e512
fix test
Dec 12, 2024
e1028d1
fix test
Dec 12, 2024
980869e
fix getting started
Dec 12, 2024
80e30c8
aarons review
Dec 16, 2024
ee2ffbd
rmv unneded tests
Dec 17, 2024
e499762
formulaic version fixed bc of breaking changes
Dec 17, 2024
ce7ba15
add explanatory text to doe basic examples
R-M-Lee Dec 17, 2024
78bf5c9
typo in basic_examples.ipynb
R-M-Lee Dec 17, 2024
54e799c
format basic doe example
R-M-Lee Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bofire/data_models/strategies/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from typing import Union

from bofire.data_models.strategies.actual_strategy_type import ActualStrategy
from bofire.data_models.strategies.doe import DoEStrategy
from bofire.data_models.strategies.doe import (
AnyDoEOptimalityCriterion,
AnyOptimalityCriterion,
AOptimalityCriterion,
DoEStrategy,
DOptimalityCriterion,
EOptimalityCriterion,
GOptimalityCriterion,
KOptimalityCriterion,
SpaceFillingCriterion,
)
from bofire.data_models.strategies.factorial import FactorialStrategy
from bofire.data_models.strategies.fractional_factorial import (
FractionalFactorialStrategy,
Expand Down
101 changes: 86 additions & 15 deletions bofire/data_models/strategies/doe.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,98 @@
from typing import Literal, Optional, Type, Union
from typing import Dict, Literal, Optional, Type, Union

from formulaic import Formula
from formulaic.errors import FormulaSyntaxError
from pydantic import Field, field_validator

from bofire.data_models.base import BaseModel
from bofire.data_models.constraints.api import Constraint
from bofire.data_models.features.api import Feature, MolecularInput
from bofire.data_models.objectives.api import Objective
from bofire.data_models.strategies.strategy import Strategy
from bofire.data_models.types import Bounds
from bofire.strategies.enum import OptimalityCriterionEnum


class DoEStrategy(Strategy):
type: Literal["DoEStrategy"] = "DoEStrategy"
PREDEFINED_MODEL_TYPES = Literal[
"linear",
"linear-and-quadratic",
"linear-and-interactions",
"fully-quadratic",
]


class OptimalityCriterion(BaseModel):
type: str
delta: float = 1e-6
transform_range: Optional[Bounds] = None


class SpaceFillingCriterion(OptimalityCriterion):
type: Literal["SpaceFillingCriterion"] = "SpaceFillingCriterion" # type: ignore


class DoEOptimalityCriterion(OptimalityCriterion):
type: str
formula: Union[
Literal[
"linear",
"linear-and-quadratic",
"linear-and-interactions",
"fully-quadratic",
],
PREDEFINED_MODEL_TYPES,
str,
]
"""
model_type (str, Formula): keyword or formulaic Formula describing the model. Known keywords
are "linear", "linear-and-interactions", "linear-and-quadratic", "fully-quadratic".
"""

@field_validator("formula")
@classmethod
def validate_formula(cls, formula: str) -> str:
if formula not in PREDEFINED_MODEL_TYPES.__args__: # type: ignore
# check that it is a valid formula
try:
Formula(formula)
except FormulaSyntaxError:
raise ValueError(f"Invalid formula: {formula}")
return formula


class DOptimalityCriterion(DoEOptimalityCriterion):
type: Literal["DOptimalityCriterion"] = "DOptimalityCriterion" # type: ignore


class EOptimalityCriterion(DoEOptimalityCriterion):
type: Literal["EOptimalityCriterion"] = "EOptimalityCriterion" # type: ignore


class AOptimalityCriterion(DoEOptimalityCriterion):
type: Literal["AOptimalityCriterion"] = "AOptimalityCriterion" # type: ignore


class GOptimalityCriterion(DoEOptimalityCriterion):
type: Literal["GOptimalityCriterion"] = "GOptimalityCriterion" # type: ignore


class KOptimalityCriterion(DoEOptimalityCriterion):
type: Literal["KOptimalityCriterion"] = "KOptimalityCriterion" # type: ignore


AnyDoEOptimalityCriterion = Union[
KOptimalityCriterion,
GOptimalityCriterion,
AOptimalityCriterion,
EOptimalityCriterion,
DOptimalityCriterion,
]

AnyOptimalityCriterion = Union[
AnyDoEOptimalityCriterion,
SpaceFillingCriterion,
]


class DoEStrategy(Strategy):
type: Literal["DoEStrategy"] = "DoEStrategy" # type: ignore

criterion: AnyOptimalityCriterion = Field(
default_factory=lambda: DOptimalityCriterion(formula="fully-quadratic")
)
optimization_strategy: Literal[
"default",
"exhaustive",
Expand All @@ -28,11 +102,8 @@ class DoEStrategy(Strategy):
"iterative",
] = "default"

verbose: bool = False

objective: OptimalityCriterionEnum = OptimalityCriterionEnum.D_OPTIMALITY

transform_range: Optional[Bounds] = None
verbose: bool = False # get rid of this at a later stage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the transform_range gone?

ipopt_options: Optional[Dict] = None

@classmethod
def is_constraint_implemented(cls, my_type: Type[Constraint]) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion bofire/data_models/strategies/space_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SpaceFillingStrategy(Strategy):

"""

type: Literal["SpaceFillingStrategy"] = "SpaceFillingStrategy"
type: Literal["SpaceFillingStrategy"] = "SpaceFillingStrategy" # type: ignore
sampling_fraction: Annotated[float, Field(gt=0, lt=1)] = 0.3
ipopt_options: dict = {"maxiter": 200, "disp": 0}

Expand Down
Loading
Loading