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

enable xopt init from yaml file #151

Merged
merged 14 commits into from
Oct 4, 2023
1,877 changes: 394 additions & 1,483 deletions docs/examples/basic/xopt_parallel.ipynb

Large diffs are not rendered by default.

282 changes: 218 additions & 64 deletions docs/examples/cnsga/cnsga_tnk.ipynb

Large diffs are not rendered by default.

65 changes: 0 additions & 65 deletions docs/examples/cnsga/test.csv

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/execute_notebooks.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NOTEBOOKS=$(find . -type f -name "*.ipynb" -not -path '*/.*')

SKIP="parallel"
SKIP="Xparallel"

echo $NOTEBOOKS

Expand Down
5 changes: 0 additions & 5 deletions tests/generators/bayesian/test_bax.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_generate(self):
vocs=test_vocs,
algorithm=alg,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.data = TEST_VOCS_DATA

Expand All @@ -128,7 +127,6 @@ def test_generate(self):
vocs=test_vocs,
algorithm=alg,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.data = TEST_VOCS_DATA

Expand All @@ -143,7 +141,6 @@ def test_cuda(self):
)

if torch.cuda.is_available():
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.data = TEST_VOCS_DATA

Expand All @@ -158,7 +155,6 @@ def test_in_xopt(self):
vocs=TEST_VOCS_BASE,
algorithm=alg,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1

xopt = Xopt(generator=gen, evaluator=evaluator, vocs=TEST_VOCS_BASE)
Expand All @@ -174,7 +170,6 @@ def test_file_saving(self):
gen = BaxGenerator(
vocs=TEST_VOCS_BASE, algorithm=alg, algorithm_results_file="test"
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1

xopt = Xopt(generator=gen, evaluator=evaluator, vocs=TEST_VOCS_BASE)
Expand Down
3 changes: 0 additions & 3 deletions tests/generators/bayesian/test_bayesian_exploration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_generate(self):
gen = BayesianExplorationGenerator(
vocs=ele,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1
gen.data = TEST_VOCS_DATA
Expand All @@ -34,7 +33,6 @@ def test_generate(self):
gen = BayesianExplorationGenerator(
vocs=ele,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1
gen.data = TEST_VOCS_DATA
Expand All @@ -47,7 +45,6 @@ def test_generate(self):
def test_in_xopt(self):
evaluator = Evaluator(function=xtest_callable)
gen = BayesianExplorationGenerator(vocs=TEST_VOCS_BASE)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1
gen.data = TEST_VOCS_DATA
Expand Down
4 changes: 1 addition & 3 deletions tests/generators/bayesian/test_custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ class ConstraintPrior(torch.nn.Module):
def forward(self, X):
return X.squeeze(dim=-1) ** 2

gp_constructor = StandardModelConstructor(
mean_modules={"c": ConstraintPrior()}
)
gp_constructor = StandardModelConstructor(mean_modules={"c": ConstraintPrior()})
generator = ExpectedImprovementGenerator(
vocs=my_vocs, gp_constructor=gp_constructor
)
Expand Down
3 changes: 0 additions & 3 deletions tests/generators/bayesian/test_expected_improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_generate(self):
gen = ExpectedImprovementGenerator(
vocs=TEST_VOCS_BASE,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1
gen.data = TEST_VOCS_DATA
Expand All @@ -38,7 +37,6 @@ def test_generate_w_overlapping_objectives_constraints(self):
gen = ExpectedImprovementGenerator(
vocs=test_vocs,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1
gen.data = TEST_VOCS_DATA
Expand All @@ -51,7 +49,6 @@ def test_in_xopt(self):
gen = ExpectedImprovementGenerator(
vocs=TEST_VOCS_BASE,
)
gen.numerical_optimizer.n_raw_samples = 1
gen.numerical_optimizer.n_restarts = 1
gen.n_monte_carlo_samples = 1

Expand Down
23 changes: 12 additions & 11 deletions tests/generators/bayesian/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def test_constrained_mobo(self):
numerical_optimizer:
name: LBFGS
n_restarts: 1
n_raw_samples: 2

evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
Expand All @@ -74,7 +73,6 @@ def test_mobo(self):
numerical_optimizer:
name: LBFGS
n_restarts: 2
n_raw_samples: 2
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
vocs:
Expand All @@ -100,7 +98,6 @@ def test_restart_torch_inline_serialization(self):
numerical_optimizer:
name: LBFGS
n_restarts: 1
n_raw_samples: 2
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
vocs:
Expand All @@ -125,10 +122,13 @@ def test_restart_torch_inline_serialization(self):
assert X2.generator.vocs.variable_names == ["x1", "x2"]
assert X2.generator.numerical_optimizer.n_restarts == 1
assert np.allclose(
X2.generator.data[X2.vocs.all_names].to_numpy(),
X.data[X.vocs.all_names].to_numpy()
X2.generator.data[X2.vocs.all_names].to_numpy(),
X.data[X.vocs.all_names].to_numpy(),
)
assert (
X.generator.model.state_dict().__str__()
== X2.generator.model.state_dict().__str__()
)
assert X.generator.model.state_dict().__str__() == X2.generator.model.state_dict().__str__()

X2.step()

Expand All @@ -145,7 +145,6 @@ def test_restart_torch_serialization(self):
numerical_optimizer:
name: LBFGS
n_restarts: 1
n_raw_samples: 2
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
vocs:
Expand All @@ -171,7 +170,10 @@ def test_restart_torch_serialization(self):
X2.generator.data[X2.vocs.all_names].to_numpy(),
X.data[X.vocs.all_names].to_numpy(),
)
assert X.generator.model.state_dict().__str__() == X2.generator.model.state_dict().__str__()
assert (
X.generator.model.state_dict().__str__()
== X2.generator.model.state_dict().__str__()
)

X2.step()

Expand All @@ -187,7 +189,6 @@ def test_restart(self):
numerical_optimizer:
name: LBFGS
n_restarts: 1
n_raw_samples: 2

evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
Expand Down Expand Up @@ -218,10 +219,10 @@ def test_restart(self):

X2.step()

@pytest.fixture(scope='module', autouse=True)
@pytest.fixture(scope="module", autouse=True)
def clean_up(self):
yield
files = ['dump.yml', 'mobo_model.pt', 'dump_inline.yml']
files = ["dump.yml", "mobo_model.pt", "dump_inline.yml"]
for f in files:
if os.path.exists(f):
os.remove(f)
Loading