Checkpointing and Restarts¶
If dump_file is provided Xopt will save the data and the Xopt configuration in a
yaml file. This can be used directly to create a new Xopt object.
In [1]:
Copied!
# Import the class
from xopt import Xopt
# Make a proper input file.
YAML = """
dump_file: dump.yml
generator:
name: random
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives: {y1: MINIMIZE, y2: MINIMIZE}
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
function_kwargs:
a: 999
"""
# Import the class
from xopt import Xopt
# Make a proper input file.
YAML = """
dump_file: dump.yml
generator:
name: random
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives: {y1: MINIMIZE, y2: MINIMIZE}
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
function_kwargs:
a: 999
"""
Checkpoints¶
Since we specified a dump file Xopt will dump the data and all of the options required to create a new Xopt object that continues the run.
In [2]:
Copied!
# create Xopt object.
X = Xopt.from_yaml(YAML)
# take 10 steps and view data
for _ in range(10):
X.step()
X.data
# create Xopt object.
X = Xopt.from_yaml(YAML)
# take 10 steps and view data
for _ in range(10):
X.step()
X.data
Out[2]:
| x1 | x2 | a | y1 | y2 | c1 | c2 | xopt_runtime | xopt_error | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.530406 | 0.612859 | dummy_constant | 0.530406 | 0.612859 | -0.383746 | 0.013662 | 0.005888 | False |
| 1 | 1.570831 | 0.806462 | dummy_constant | 1.570831 | 0.806462 | 2.091695 | 1.240597 | 0.011829 | False |
| 2 | 0.746581 | 2.294889 | dummy_constant | 0.746581 | 2.294889 | 4.792444 | 3.282430 | 0.009375 | False |
| 3 | 0.209587 | 2.564201 | dummy_constant | 0.209587 | 2.564201 | 5.592774 | 4.345267 | 0.004334 | False |
| 4 | 3.116085 | 1.406082 | dummy_constant | 3.116085 | 1.406082 | 10.599237 | 7.664883 | 0.003601 | False |
| 5 | 0.613554 | 2.381518 | dummy_constant | 0.613554 | 2.381518 | 5.110804 | 3.553006 | 0.002428 | False |
| 6 | 1.771964 | 0.770425 | dummy_constant | 1.771964 | 0.770425 | 2.637275 | 1.691023 | 0.005695 | False |
| 7 | 0.795419 | 2.511736 | dummy_constant | 0.795419 | 2.511736 | 5.922168 | 4.134354 | 0.001292 | False |
| 8 | 1.943711 | 2.673328 | dummy_constant | 1.943711 | 2.673328 | 10.005266 | 6.807655 | 0.000283 | False |
| 9 | 2.970542 | 1.402472 | dummy_constant | 2.970542 | 1.402472 | 9.719565 | 6.918033 | 0.000280 | False |
Create Xopt object from dump file¶
In [3]:
Copied!
X2 = Xopt.from_file("dump.yml")
X2
X2 = Xopt.from_file("dump.yml")
X2
Out[3]:
Xopt
________________________________
Version: 0.1.dev1+gfcd953a52
Data size: 10
Config as YAML:
dump_file: dump.yml
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
function_kwargs:
a: 999
raise_probability: 0
random_sleep: 0
sleep: 0
max_workers: 1
vectorized: false
generator:
name: random
returns_id: false
supports_batch_generation: true
supports_constraints: true
supports_discrete_variables: true
supports_multi_objective: true
supports_single_objective: true
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: MinimizeObjective
y2:
dtype: null
type: MinimizeObjective
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 [4]:
Copied!
for _ in range(10):
X2.step()
X2.data
for _ in range(10):
X2.step()
X2.data
Out[4]:
| a | c1 | c2 | x1 | x2 | xopt_error | xopt_runtime | y1 | y2 | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | dummy_constant | -0.383746 | 0.013662 | 0.530406 | 0.612859 | False | 0.005888 | 0.530406 | 0.612859 |
| 1 | dummy_constant | 2.091695 | 1.240597 | 1.570831 | 0.806462 | False | 0.011829 | 1.570831 | 0.806462 |
| 2 | dummy_constant | 4.792444 | 3.282430 | 0.746581 | 2.294889 | False | 0.009375 | 0.746581 | 2.294889 |
| 3 | dummy_constant | 5.592774 | 4.345267 | 0.209587 | 2.564201 | False | 0.004334 | 0.209587 | 2.564201 |
| 4 | dummy_constant | 10.599237 | 7.664883 | 3.116085 | 1.406082 | False | 0.003601 | 3.116085 | 1.406082 |
| 5 | dummy_constant | 5.110804 | 3.553006 | 0.613554 | 2.381518 | False | 0.002428 | 0.613554 | 2.381518 |
| 6 | dummy_constant | 2.637275 | 1.691023 | 1.771964 | 0.770425 | False | 0.005695 | 1.771964 | 0.770425 |
| 7 | dummy_constant | 5.922168 | 4.134354 | 0.795419 | 2.511736 | False | 0.001292 | 0.795419 | 2.511736 |
| 8 | dummy_constant | 10.005266 | 6.807655 | 1.943711 | 2.673328 | False | 0.000283 | 1.943711 | 2.673328 |
| 9 | dummy_constant | 9.719565 | 6.918033 | 2.970542 | 1.402472 | False | 0.000280 | 2.970542 | 1.402472 |
| 10 | dummy_constant | 8.105645 | 5.963148 | 2.939775 | 0.603187 | False | 0.003822 | 2.939775 | 0.603187 |
| 11 | dummy_constant | 1.558418 | 0.914443 | 0.738579 | 1.426026 | False | 0.005368 | 0.738579 | 1.426026 |
| 12 | dummy_constant | 0.788670 | 0.922598 | 1.359987 | 0.072193 | False | 0.001895 | 1.359987 | 0.072193 |
| 13 | dummy_constant | -0.157775 | 0.061258 | 0.456094 | 0.743579 | False | 0.005700 | 0.456094 | 0.743579 |
| 14 | dummy_constant | 7.272062 | 5.160998 | 0.935225 | 2.729703 | False | 0.005955 | 0.935225 | 2.729703 |
| 15 | dummy_constant | 0.702962 | 0.888425 | 0.058340 | 1.332683 | False | 0.011187 | 0.058340 | 1.332683 |
| 16 | dummy_constant | 0.954605 | 0.711522 | 1.336234 | 0.389388 | False | 0.008469 | 1.336234 | 0.389388 |
| 17 | dummy_constant | 0.366294 | 0.569378 | 1.155144 | 0.125614 | False | 0.006312 | 1.155144 | 0.125614 |
| 18 | dummy_constant | 4.787769 | 2.947370 | 1.772860 | 1.652040 | False | 0.002356 | 1.772860 | 1.652040 |
| 19 | dummy_constant | 13.793165 | 9.854741 | 2.282240 | 3.084253 | False | 0.005332 | 2.282240 | 3.084253 |