Checkpointing and Restarts¶
If xopt_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. If
data_dump_file is provided Xopt will additionally write the evaluation data to a
csv file.
In [1]:
Copied!
# Import the class
from xopt import Xopt
# Make a proper input file.
YAML = """
xopt_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 = """
xopt_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.995402 | 1.238104 | dummy_constant | 2.995402 | 1.238104 | 9.405344 | 6.771830 | 0.003076 | False |
| 1 | 3.041621 | 2.169322 | dummy_constant | 3.041621 | 2.169322 | 13.045755 | 9.246477 | 0.007521 | False |
| 2 | 1.401294 | 2.676583 | dummy_constant | 1.401294 | 2.676583 | 8.114047 | 5.549845 | 0.004707 | False |
| 3 | 2.775756 | 2.516782 | dummy_constant | 2.775756 | 2.516782 | 12.968082 | 9.246474 | 0.003330 | False |
| 4 | 0.540622 | 0.819615 | dummy_constant | 0.540622 | 0.819615 | 0.063588 | 0.103804 | 0.004943 | False |
| 5 | 1.573406 | 1.568322 | dummy_constant | 1.573406 | 1.568322 | 3.835274 | 2.293512 | 0.000936 | False |
| 6 | 2.573393 | 2.069255 | dummy_constant | 2.573393 | 2.069255 | 9.920086 | 6.761522 | 0.004875 | False |
| 7 | 0.008123 | 2.811269 | dummy_constant | 0.008123 | 2.811269 | 6.803408 | 5.583909 | 0.004959 | False |
| 8 | 1.179441 | 0.688654 | dummy_constant | 1.179441 | 0.688654 | 0.921936 | 0.497231 | 0.000128 | False |
| 9 | 2.890945 | 2.228585 | dummy_constant | 2.890945 | 2.228585 | 12.371027 | 8.704626 | 0.001159 | 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: 3.3.0
Data size: 10
Config as YAML:
data_dump_file: null
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
xopt_dump_file: dump.yml
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 | 9.405344 | 6.771830 | 2.995402 | 1.238104 | False | 0.003076 | 2.995402 | 1.238104 |
| 1 | dummy_constant | 13.045755 | 9.246477 | 3.041621 | 2.169322 | False | 0.007521 | 3.041621 | 2.169322 |
| 2 | dummy_constant | 8.114047 | 5.549845 | 1.401294 | 2.676583 | False | 0.004707 | 1.401294 | 2.676583 |
| 3 | dummy_constant | 12.968082 | 9.246474 | 2.775756 | 2.516782 | False | 0.003330 | 2.775756 | 2.516782 |
| 4 | dummy_constant | 0.063588 | 0.103804 | 0.540622 | 0.819615 | False | 0.004943 | 0.540622 | 0.819615 |
| 5 | dummy_constant | 3.835274 | 2.293512 | 1.573406 | 1.568322 | False | 0.000936 | 1.573406 | 1.568322 |
| 6 | dummy_constant | 9.920086 | 6.761522 | 2.573393 | 2.069255 | False | 0.004875 | 2.573393 | 2.069255 |
| 7 | dummy_constant | 6.803408 | 5.583909 | 0.008123 | 2.811269 | False | 0.004959 | 0.008123 | 2.811269 |
| 8 | dummy_constant | 0.921936 | 0.497231 | 1.179441 | 0.688654 | False | 0.000128 | 1.179441 | 0.688654 |
| 9 | dummy_constant | 12.371027 | 8.704626 | 2.890945 | 2.228585 | False | 0.001159 | 2.890945 | 2.228585 |
| 10 | dummy_constant | 8.391149 | 5.584647 | 1.964052 | 2.355047 | False | 0.002851 | 1.964052 | 2.355047 |
| 11 | dummy_constant | 14.108294 | 10.155758 | 2.952278 | 2.535212 | False | 0.003828 | 2.952278 | 2.535212 |
| 12 | dummy_constant | 7.709433 | 5.638309 | 2.872411 | 0.599873 | False | 0.004243 | 2.872411 | 0.599873 |
| 13 | dummy_constant | 11.155818 | 7.721278 | 2.035385 | 2.816003 | False | 0.000149 | 2.035385 | 2.816003 |
| 14 | dummy_constant | 10.760877 | 7.773896 | 3.123746 | 1.443321 | False | 0.000154 | 3.123746 | 1.443321 |
| 15 | dummy_constant | 0.385113 | 0.469828 | 0.201946 | 1.117245 | False | 0.011349 | 0.201946 | 1.117245 |
| 16 | dummy_constant | 10.221151 | 7.379781 | 1.357088 | 3.077825 | False | 0.003247 | 1.357088 | 3.077825 |
| 17 | dummy_constant | 1.650107 | 1.130546 | 0.392751 | 1.557848 | False | 0.002393 | 0.392751 | 1.557848 |
| 18 | dummy_constant | 12.949492 | 9.187255 | 2.068704 | 3.093535 | False | 0.000813 | 2.068704 | 3.093535 |
| 19 | dummy_constant | 7.169743 | 4.708915 | 2.452997 | 1.445895 | False | 0.004595 | 2.452997 | 1.445895 |