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 | 0.396250 | 2.640978 | dummy_constant | 0.396250 | 2.640978 | 6.204351 | 4.594552 | 0.005459 | False |
| 1 | 2.961564 | 0.081350 | dummy_constant | 2.961564 | 0.081350 | 7.686978 | 6.234565 | 0.005325 | False |
| 2 | 1.290266 | 2.146668 | dummy_constant | 1.290266 | 2.146668 | 5.345063 | 3.336036 | 0.005366 | False |
| 3 | 0.590756 | 2.381635 | dummy_constant | 0.590756 | 2.381635 | 5.094438 | 3.548786 | 0.008032 | False |
| 4 | 2.419884 | 0.244090 | dummy_constant | 2.419884 | 0.244090 | 4.919183 | 3.751443 | 0.005973 | False |
| 5 | 2.701814 | 2.424048 | dummy_constant | 2.701814 | 2.424048 | 12.111035 | 8.549947 | 0.000152 | False |
| 6 | 0.283200 | 1.712623 | dummy_constant | 0.283200 | 1.712623 | 2.100082 | 1.517456 | 0.000149 | False |
| 7 | 0.457955 | 0.859955 | dummy_constant | 0.457955 | 0.859955 | -0.053218 | 0.131336 | 0.000510 | False |
| 8 | 0.864841 | 0.814762 | dummy_constant | 0.864841 | 0.814762 | 0.322945 | 0.232184 | 0.002456 | False |
| 9 | 2.678089 | 2.359611 | dummy_constant | 2.678089 | 2.359611 | 11.686751 | 8.202224 | 0.000141 | 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+gbbdbaad38
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 | 6.204351 | 4.594552 | 0.396250 | 2.640978 | False | 0.005459 | 0.396250 | 2.640978 |
| 1 | dummy_constant | 7.686978 | 6.234565 | 2.961564 | 0.081350 | False | 0.005325 | 2.961564 | 0.081350 |
| 2 | dummy_constant | 5.345063 | 3.336036 | 1.290266 | 2.146668 | False | 0.005366 | 1.290266 | 2.146668 |
| 3 | dummy_constant | 5.094438 | 3.548786 | 0.590756 | 2.381635 | False | 0.008032 | 0.590756 | 2.381635 |
| 4 | dummy_constant | 4.919183 | 3.751443 | 2.419884 | 0.244090 | False | 0.005973 | 2.419884 | 0.244090 |
| 5 | dummy_constant | 12.111035 | 8.549947 | 2.701814 | 2.424048 | False | 0.000152 | 2.701814 | 2.424048 |
| 6 | dummy_constant | 2.100082 | 1.517456 | 0.283200 | 1.712623 | False | 0.000149 | 0.283200 | 1.712623 |
| 7 | dummy_constant | -0.053218 | 0.131336 | 0.457955 | 0.859955 | False | 0.000510 | 0.457955 | 0.859955 |
| 8 | dummy_constant | 0.322945 | 0.232184 | 0.864841 | 0.814762 | False | 0.002456 | 0.864841 | 0.814762 |
| 9 | dummy_constant | 11.686751 | 8.202224 | 2.678089 | 2.359611 | False | 0.000141 | 2.678089 | 2.359611 |
| 10 | dummy_constant | 2.216815 | 1.231739 | 0.893537 | 1.537722 | False | 0.001056 | 0.893537 | 1.537722 |
| 11 | dummy_constant | 2.801618 | 1.527829 | 1.144740 | 1.554580 | False | 0.002880 | 1.144740 | 1.554580 |
| 12 | dummy_constant | -0.712393 | 0.059531 | 0.500237 | 0.256010 | False | 0.003812 | 0.500237 | 0.256010 |
| 13 | dummy_constant | 6.659747 | 4.702479 | 2.643535 | 0.828231 | False | 0.006181 | 2.643535 | 0.828231 |
| 14 | dummy_constant | 3.768464 | 2.947549 | 2.184655 | 0.169111 | False | 0.003812 | 2.184655 | 0.169111 |
| 15 | dummy_constant | 7.495456 | 5.814136 | 0.281998 | 2.901377 | False | 0.007142 | 0.281998 | 2.901377 |
| 16 | dummy_constant | 6.908470 | 4.502774 | 2.043510 | 1.956142 | False | 0.007546 | 2.043510 | 1.956142 |
| 17 | dummy_constant | 6.867898 | 4.530724 | 2.445481 | 1.363613 | False | 0.009077 | 2.445481 | 1.363613 |
| 18 | dummy_constant | 9.900965 | 6.775191 | 2.502659 | 2.162693 | False | 0.006336 | 2.502659 | 2.162693 |
| 19 | dummy_constant | 8.190889 | 6.395249 | 0.283397 | 3.019590 | False | 0.015083 | 0.283397 | 3.019590 |