Bayesian exploration from YAML¶
In [1]:
Copied!
from xopt import Xopt
# set values if testing
import os
import warnings
warnings.filterwarnings("ignore")
SMOKE_TEST = os.environ.get("SMOKE_TEST")
YAML = """
generator:
name: bayesian_exploration
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
observables: [y1]
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
"""
from xopt import Xopt
# set values if testing
import os
import warnings
warnings.filterwarnings("ignore")
SMOKE_TEST = os.environ.get("SMOKE_TEST")
YAML = """
generator:
name: bayesian_exploration
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
observables: [y1]
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
"""
In [2]:
Copied!
X = Xopt.from_yaml(YAML)
# for testing purposes only
if SMOKE_TEST:
X.generator.numerical_optimizer.n_restarts = 1
X.generator.n_monte_carlo_samples = 1
X
X = Xopt.from_yaml(YAML)
# for testing purposes only
if SMOKE_TEST:
X.generator.numerical_optimizer.n_restarts = 1
X.generator.n_monte_carlo_samples = 1
X
Out[2]:
Xopt
________________________________
Version: 2.6.11.dev7+g4d3d82eb9.d20260128
Data size: 0
Config as YAML:
dump_file: null
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
function_kwargs:
raise_probability: 0
random_sleep: 0
sleep: 0
max_workers: 1
vectorized: false
generator:
computation_time: null
custom_objective: null
fixed_features: null
gp_constructor:
covar_modules: {}
custom_noise_prior: null
mean_modules: {}
name: standard
trainable_mean_keys: []
transform_inputs: true
use_cached_hyperparameters: false
use_low_noise_prior: false
max_travel_distances: null
model: null
n_candidates: 1
n_interpolate_points: null
n_monte_carlo_samples: 128
name: bayesian_exploration
numerical_optimizer:
max_iter: 2000
max_time: 5.0
n_restarts: 20
name: LBFGS
supports_batch_generation: true
supports_constraints: true
turbo_controller: null
use_cuda: false
serialize_inline: false
serialize_torch: false
stopping_condition: null
strict: true
vocs:
constants:
a: dummy_constant
constraints:
c1:
- GREATER_THAN
- 0.0
c2:
- LESS_THAN
- 0.5
objectives: {}
observables:
- y1
variables:
x1:
- 0.0
- 3.14159
x2:
- 0.0
- 3.14159
In [3]:
Copied!
X.random_evaluate(5)
for i in range(5):
print(f"step {i}")
X.step()
X.random_evaluate(5)
for i in range(5):
print(f"step {i}")
X.step()
step 0
step 1
step 2
step 3
step 4
In [4]:
Copied!
print(X.data)
print(X.data)
x1 x2 a y1 y2 c1 \
0 1.255230 0.374899 dummy_constant 1.255230 0.374899 0.723009
1 1.010773 2.139188 dummy_constant 1.010773 2.139188 4.526651
2 3.041586 2.912028 dummy_constant 3.041586 2.912028 16.637148
3 0.643048 1.734052 dummy_constant 0.643048 1.734052 2.337991
4 1.263552 1.502613 dummy_constant 1.263552 1.502613 2.835380
5 0.000000 0.699618 dummy_constant 0.000000 0.699618 -0.610535
6 0.867427 0.932457 dummy_constant 0.867427 0.932457 0.538140
7 0.421899 1.057411 dummy_constant 0.421899 1.057411 0.198293
8 0.975373 0.491890 dummy_constant 0.975373 0.491890 0.156167
9 0.264374 1.066923 dummy_constant 0.264374 1.066923 0.281742
c2 xopt_runtime xopt_error
0 0.586023 0.000159 False
1 2.947826 0.000135 False
2 12.277536 0.000136 False
3 1.543348 0.000129 False
4 1.588244 0.000128 False
5 0.289847 0.000153 False
6 0.322021 0.000155 False
7 0.316807 0.000151 False
8 0.226046 0.000111 False
9 0.376921 0.000156 False
In [5]:
Copied!
# plot results
ax = X.data.plot("x1", "x2")
ax.set_aspect("equal")
# plot results
ax = X.data.plot("x1", "x2")
ax.set_aspect("equal")
In [6]:
Copied!
fig, ax = X.generator.visualize_model(show_feasibility=True, n_grid=100)
fig, ax = X.generator.visualize_model(show_feasibility=True, n_grid=100)