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.851928 | 1.153893 | dummy_constant | 0.851928 | 1.153893 | 1.130362 | 0.551429 | 0.001341 | False |
| 1 | 2.170701 | 0.060850 | dummy_constant | 2.170701 | 0.060850 | 3.625532 | 2.984094 | 0.006454 | False |
| 2 | 2.996292 | 2.338614 | dummy_constant | 2.996292 | 2.338614 | 13.485065 | 9.611978 | 0.005802 | False |
| 3 | 2.831915 | 0.358936 | dummy_constant | 2.831915 | 0.358936 | 7.191747 | 5.457724 | 0.005307 | False |
| 4 | 2.162177 | 2.415128 | dummy_constant | 2.162177 | 2.415128 | 9.444390 | 6.430547 | 0.005292 | False |
| 5 | 3.013477 | 2.064154 | dummy_constant | 3.013477 | 2.064154 | 12.440077 | 8.764141 | 0.014759 | False |
| 6 | 2.057616 | 1.079872 | dummy_constant | 2.057616 | 1.079872 | 4.387824 | 2.762420 | 0.003203 | False |
| 7 | 0.521651 | 2.120103 | dummy_constant | 0.521651 | 2.120103 | 3.842236 | 2.625204 | 0.002096 | False |
| 8 | 0.036396 | 2.500759 | dummy_constant | 0.036396 | 2.500759 | 5.157821 | 4.217966 | 0.001690 | False |
| 9 | 0.676976 | 0.501316 | dummy_constant | 0.676976 | 0.501316 | -0.218856 | 0.031322 | 0.005422 | 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+g210ad3716
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 | 1.130362 | 0.551429 | 0.851928 | 1.153893 | False | 0.001341 | 0.851928 | 1.153893 |
| 1 | dummy_constant | 3.625532 | 2.984094 | 2.170701 | 0.060850 | False | 0.006454 | 2.170701 | 0.060850 |
| 2 | dummy_constant | 13.485065 | 9.611978 | 2.996292 | 2.338614 | False | 0.005802 | 2.996292 | 2.338614 |
| 3 | dummy_constant | 7.191747 | 5.457724 | 2.831915 | 0.358936 | False | 0.005307 | 2.831915 | 0.358936 |
| 4 | dummy_constant | 9.444390 | 6.430547 | 2.162177 | 2.415128 | False | 0.005292 | 2.162177 | 2.415128 |
| 5 | dummy_constant | 12.440077 | 8.764141 | 3.013477 | 2.064154 | False | 0.014759 | 3.013477 | 2.064154 |
| 6 | dummy_constant | 4.387824 | 2.762420 | 2.057616 | 1.079872 | False | 0.003203 | 2.057616 | 1.079872 |
| 7 | dummy_constant | 3.842236 | 2.625204 | 0.521651 | 2.120103 | False | 0.002096 | 0.521651 | 2.120103 |
| 8 | dummy_constant | 5.157821 | 4.217966 | 0.036396 | 2.500759 | False | 0.001690 | 0.036396 | 2.500759 |
| 9 | dummy_constant | -0.218856 | 0.031322 | 0.676976 | 0.501316 | False | 0.005422 | 0.676976 | 0.501316 |
| 10 | dummy_constant | 10.360075 | 7.125502 | 2.168540 | 2.583621 | False | 0.007471 | 2.168540 | 2.583621 |
| 11 | dummy_constant | 12.993853 | 9.249873 | 2.450295 | 2.833715 | False | 0.001891 | 2.450295 | 2.833715 |
| 12 | dummy_constant | 0.271671 | 0.344466 | 1.084116 | 0.442775 | False | 0.002564 | 1.084116 | 0.442775 |
| 13 | dummy_constant | 11.447329 | 8.037053 | 2.478655 | 2.530265 | False | 0.004568 | 2.478655 | 2.530265 |
| 14 | dummy_constant | 2.721356 | 1.553897 | 1.409755 | 1.352199 | False | 0.005753 | 1.409755 | 1.352199 |
| 15 | dummy_constant | 3.090637 | 1.873494 | 1.797266 | 0.936571 | False | 0.004896 | 1.797266 | 0.936571 |
| 16 | dummy_constant | 2.050743 | 1.472184 | 0.291724 | 1.695326 | False | 0.011810 | 0.291724 | 1.695326 |
| 17 | dummy_constant | 1.367836 | 0.745240 | 1.124415 | 1.096108 | False | 0.008451 | 1.124415 | 1.096108 |
| 18 | dummy_constant | -0.451881 | 0.075354 | 0.718024 | 0.333209 | False | 0.006241 | 0.718024 | 0.333209 |
| 19 | dummy_constant | 2.990395 | 1.646800 | 1.610339 | 1.143388 | False | 0.009071 | 1.610339 | 1.143388 |