Skip to content

Commit

Permalink
Merge pull request #87 from ChristopherMayes/pydantic_bugfix
Browse files Browse the repository at this point in the history
Fix pydantic bug in tests/ add pinned version for botorch
  • Loading branch information
roussel-ryan authored Jan 10, 2023
2 parents d9e5560 + 4f6262c commit 0132d96
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 817 deletions.
810 changes: 13 additions & 797 deletions docs/examples/basic/checkpointing_and_restarts.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/bayes_opt/benchmarking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- pydantic>=1.10.0
- pyyaml
- pytorch
- botorch>=0.6.5
- botorch==0.7.3
- gpytorch
- pandas
- ipywidgets
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ deap
numpy
pyyaml
torch
botorch>=0.6.5
botorch==0.7.3
gpytorch
pandas
pydantic>=1.10.0
Expand Down
15 changes: 6 additions & 9 deletions tests/generators/bayesian/test_expected_improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@

from xopt.evaluator import Evaluator
from xopt.generators.bayesian.bayesian_exploration import BayesianExplorationOptions
from xopt.generators.bayesian.expected_improvement import (
ExpectedImprovementGenerator,
)
from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator

from xopt.resources.testing import TEST_VOCS_BASE, TEST_VOCS_DATA, xtest_callable


class TestExpectedImprovement:
def test_init(self):
ucb_gen = ExpectedImprovementGenerator(TEST_VOCS_BASE)
ucb_gen.options.dict()
ucb_gen.options.schema()
ei_gen = ExpectedImprovementGenerator(TEST_VOCS_BASE)
ei_gen.options.dict()
ei_gen.options.json()
# ei_gen.options.schema() wait till pydantic v2 for fix

with pytest.raises(ValueError):
ExpectedImprovementGenerator(
TEST_VOCS_BASE, BayesianExplorationOptions()
)
ExpectedImprovementGenerator(TEST_VOCS_BASE, BayesianExplorationOptions())

def test_generate(self):
gen = ExpectedImprovementGenerator(
Expand Down
14 changes: 7 additions & 7 deletions tests/generators/bayesian/test_upper_confidence_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ class TestUpperConfidenceBoundGenerator:
def test_init(self):
ucb_gen = UpperConfidenceBoundGenerator(TEST_VOCS_BASE)
ucb_gen.options.dict()
ucb_gen.options.schema()
ucb_gen.options.json()
# ucb_gen.options.schema() wait till pydantic v2 for fix

with pytest.raises(ValueError):
UpperConfidenceBoundGenerator(
TEST_VOCS_BASE, BayesianExplorationOptions()
)
UpperConfidenceBoundGenerator(TEST_VOCS_BASE, BayesianExplorationOptions())

def test_generate(self):
gen = UpperConfidenceBoundGenerator(
Expand Down Expand Up @@ -96,10 +95,11 @@ def test_positivity(self):
ucb_gen = UpperConfidenceBoundGenerator(
TEST_VOCS_BASE,
)
ucb_gen.add_data(pd.DataFrame({"x1": -1., "x2": -1., "y1": 100., "c1": -100},
index=[0]))
ucb_gen.add_data(
pd.DataFrame({"x1": -1.0, "x2": -1.0, "y1": 100.0, "c1": -100}, index=[0])
)
ucb_gen.train_model()
# evaluate acqf
acqf = ucb_gen.get_acquisition(ucb_gen.model)
with torch.no_grad():
assert acqf(torch.tensor((-1., -1.)).reshape(1, 1, 2)) >= 0.0
assert acqf(torch.tensor((-1.0, -1.0)).reshape(1, 1, 2)) >= 0.0
2 changes: 1 addition & 1 deletion xopt/generators/bayesian/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OptimOptions(XoptBaseModel):
)


class ModelOptions(BaseModel):
class ModelOptions(XoptBaseModel):
"""Options for defining the GP model in BO"""

function: Callable
Expand Down

0 comments on commit 0132d96

Please sign in to comment.