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
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives:
y1: EXPLORE
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
"""
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
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives:
y1: EXPLORE
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
"""
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: 0.1.dev1+g46cc86a6b
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
train_config: null
train_kwargs: null
train_method: lbfgs
train_model: true
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:
discrete_max_batch_size: 2048
discrete_max_choices: 4096
max_iter: 1000
max_time: 5.0
mixed_max_discrete_configurations: 512
n_restarts: 20
name: LBFGS
returns_id: false
supports_batch_generation: true
supports_constraints: true
supports_contextual_variables: true
supports_discrete_variables: true
supports_multi_objective: true
supports_no_objective: true
supports_single_objective: true
turbo_controller: null
use_cuda: false
vocs:
constants:
a:
dtype: null
type: Constant
value: dummy_constant
constraints:
c1:
dtype: null
type: GreaterThanConstraint
value: 0.0
c2:
dtype: null
type: LessThanConstraint
value: 0.5
objectives:
y1:
dtype: null
type: ExploreObjective
observables: {}
variables:
x1:
default_value: null
domain:
- 0.0
- 3.14159
dtype: null
type: ContinuousVariable
x2:
default_value: null
domain:
- 0.0
- 3.14159
dtype: null
type: ContinuousVariable
serialize_inline: false
serialize_torch: false
stopping_condition: null
strict: true
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 c2 \ 0 0.596286 0.256373 dummy_constant 0.596286 0.256373 -0.676441 0.068625 1 1.490711 2.012031 dummy_constant 1.490711 2.012031 5.341743 3.267744 2 2.307613 2.003695 dummy_constant 2.307613 2.003695 8.296845 5.528563 3 1.637783 1.517861 dummy_constant 1.637783 1.517861 3.904142 2.330592 4 2.657714 0.599857 dummy_constant 2.657714 0.599857 6.514980 4.665703 5 0.000000 2.582827 dummy_constant 0.000000 2.582827 5.570994 4.588167 6 0.000000 0.111089 dummy_constant 0.000000 0.111089 -1.087659 0.401252 7 0.958514 0.340364 dummy_constant 0.958514 0.340364 -0.033341 0.235719 8 0.968388 0.992126 dummy_constant 0.968388 0.992126 0.823960 0.461575 9 0.803133 0.953018 dummy_constant 0.803133 0.953018 0.532564 0.297115 xopt_runtime xopt_error 0 0.003036 False 1 0.000275 False 2 0.000263 False 3 0.000265 False 4 0.000269 False 5 0.005077 False 6 0.001464 False 7 0.005866 False 8 0.006000 False 9 0.003152 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)