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 | 2.381004 | 0.140705 | dummy_constant | 2.381004 | 0.140705 | 4.630357 | 3.667269 | 0.002987 | False |
| 1 | 0.466658 | 1.318627 | dummy_constant | 0.466658 | 1.318627 | 0.889868 | 0.671262 | 0.005348 | False |
| 2 | 1.473228 | 0.924675 | dummy_constant | 1.473228 | 0.924675 | 2.115176 | 1.127522 | 0.002902 | False |
| 3 | 2.088087 | 2.561370 | dummy_constant | 2.088087 | 2.561370 | 9.925950 | 6.771265 | 0.005528 | False |
| 4 | 0.475260 | 0.611193 | dummy_constant | 0.475260 | 0.611193 | -0.359729 | 0.012976 | 0.005337 | False |
| 5 | 2.044254 | 1.997952 | dummy_constant | 2.044254 | 1.997952 | 7.072460 | 4.628580 | 0.002085 | False |
| 6 | 2.182171 | 2.746243 | dummy_constant | 2.182171 | 2.746243 | 11.328701 | 7.875303 | 0.002792 | False |
| 7 | 1.803125 | 2.015556 | dummy_constant | 1.803125 | 2.015556 | 6.250717 | 3.995044 | 0.005333 | False |
| 8 | 0.050474 | 2.609034 | dummy_constant | 0.050474 | 2.609034 | 5.714356 | 4.650097 | 0.005118 | False |
| 9 | 1.104214 | 2.474527 | dummy_constant | 1.104214 | 2.474527 | 6.251768 | 4.263830 | 0.002467 | 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+gca942dd06
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_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 | 4.630357 | 3.667269 | 2.381004 | 0.140705 | False | 0.002987 | 2.381004 | 0.140705 |
| 1 | dummy_constant | 0.889868 | 0.671262 | 0.466658 | 1.318627 | False | 0.005348 | 0.466658 | 1.318627 |
| 2 | dummy_constant | 2.115176 | 1.127522 | 1.473228 | 0.924675 | False | 0.002902 | 1.473228 | 0.924675 |
| 3 | dummy_constant | 9.925950 | 6.771265 | 2.088087 | 2.561370 | False | 0.005528 | 2.088087 | 2.561370 |
| 4 | dummy_constant | -0.359729 | 0.012976 | 0.475260 | 0.611193 | False | 0.005337 | 0.475260 | 0.611193 |
| 5 | dummy_constant | 7.072460 | 4.628580 | 2.044254 | 1.997952 | False | 0.002085 | 2.044254 | 1.997952 |
| 6 | dummy_constant | 11.328701 | 7.875303 | 2.182171 | 2.746243 | False | 0.002792 | 2.182171 | 2.746243 |
| 7 | dummy_constant | 6.250717 | 3.995044 | 1.803125 | 2.015556 | False | 0.005333 | 1.803125 | 2.015556 |
| 8 | dummy_constant | 5.714356 | 4.650097 | 0.050474 | 2.609034 | False | 0.005118 | 0.050474 | 2.609034 |
| 9 | dummy_constant | 6.251768 | 4.263830 | 1.104214 | 2.474527 | False | 0.002467 | 1.104214 | 2.474527 |
| 10 | dummy_constant | 12.063585 | 8.459473 | 2.969696 | 2.036253 | False | 0.001385 | 2.969696 | 2.036253 |
| 11 | dummy_constant | 12.436208 | 8.777576 | 2.326409 | 2.832768 | False | 0.004836 | 2.326409 | 2.832768 |
| 12 | dummy_constant | 0.627196 | 0.395286 | 1.119894 | 0.604963 | False | 0.002570 | 1.119894 | 0.604963 |
| 13 | dummy_constant | 7.999889 | 5.716348 | 2.832177 | 1.026592 | False | 0.002306 | 2.832177 | 1.026592 |
| 14 | dummy_constant | 6.546474 | 4.556136 | 2.571320 | 1.015528 | False | 0.003198 | 2.571320 | 1.015528 |
| 15 | dummy_constant | 4.108527 | 2.754514 | 0.815390 | 2.129430 | False | 0.002889 | 0.815390 | 2.129430 |
| 16 | dummy_constant | 6.315827 | 4.202700 | 1.228995 | 2.416055 | False | 0.006118 | 1.228995 | 2.416055 |
| 17 | dummy_constant | -0.340396 | 0.152093 | 0.207226 | 0.757637 | False | 0.004160 | 0.207226 | 0.757637 |
| 18 | dummy_constant | 4.059001 | 2.510427 | 1.064425 | 1.980490 | False | 0.000162 | 1.064425 | 1.980490 |
| 19 | dummy_constant | 3.518303 | 2.351236 | 0.717913 | 2.017811 | False | 0.004666 | 0.717913 | 2.017811 |