Driver Recording

A CaseRecorder is commonly attached to the problem’s Driver in order to gain insight into the convergence of the model as the driver finds a solution. By default, a recorder attached to a driver will record the design variables, constraints and objectives.

The driver recorder is capable of capturing any values from any part of the model, not just the design variables, constraints, and objectives.

Option Default Acceptable Values Acceptable Types Description Deprecation
excludes [] N/A ['list'] Patterns for vars to exclude in recording (processed post-includes). Uses fnmatch wildcardsN/A
includes [] N/A ['list'] Patterns for variables to include in recording. Uses fnmatch wildcards N/A
record_constraints True [True, False] ['bool'] Set to True to record constraints at the driver level N/A
record_derivatives False [True, False] ['bool'] Set to True to record derivatives at the driver level N/A
record_desvars True [True, False] ['bool'] Set to True to record design variables at the driver level N/A
record_inputs True [True, False] ['bool'] Set to True to record inputs at the driver level N/A
record_model_metadataTrue [True, False] ['bool'] Deprecated. Recording of model metadata will always be done The recording option, record_model_metadata, on Driver is deprecated. Recording of model metadata will always be done
record_objectives True [True, False] ['bool'] Set to True to record objectives at the driver level N/A
record_outputs True [True, False] ['bool'] Set True to record outputs at the driver level. N/A
record_residuals False [True, False] ['bool'] Set True to record residuals at the driver level. N/A
record_responses False [True, False] ['bool'] Set True to record constraints and objectives at the driver level N/A

Note

Note that the excludes option takes precedence over the includes option.

Driver Recording Example

In the example below, we first run a case while recording at the driver level. Then, we examine the objective, constraint, and design variable values at the last recorded case. Lastly, we print the full contents of the last case, including outputs from the problem that are not design variables, constraints, or objectives.

Specifically, y1 and y2 are some of those intermediate outputs that are recorded due to the use of:

driver.recording_options['includes'] = ['*']

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

import numpy as np

prob = om.Problem(model=SellarDerivatives())

model = prob.model
model.add_design_var('z', lower=np.array([-10.0, 0.0]),
                          upper=np.array([10.0, 10.0]))
model.add_design_var('x', lower=0.0, upper=10.0)
model.add_objective('obj')
model.add_constraint('con1', upper=0.0)
model.add_constraint('con2', upper=0.0)

driver = prob.driver = om.ScipyOptimizeDriver(optimizer='SLSQP', tol=1e-9)
driver.recording_options['includes'] = ['*']
driver.recording_options['record_objectives'] = True
driver.recording_options['record_constraints'] = True
driver.recording_options['record_desvars'] = True
driver.recording_options['record_inputs'] = True
driver.recording_options['record_outputs'] = True
driver.recording_options['record_residuals'] = True

recorder = om.SqliteRecorder("cases.sql")
driver.add_recorder(recorder)

prob.setup()
prob.run_driver()
NL: NLBGS Converged in 8 iterations
NL: NLBGS Converged in 1 iterations
NL: NLBGS Converged in 9 iterations
NL: NLBGS Converged in 10 iterations
NL: NLBGS Converged in 10 iterations
NL: NLBGS Converged in 9 iterations
NL: NLBGS Converged in 6 iterations
Optimization terminated successfully.    (Exit mode 0)
            Current function value: 3.1833939517255843
            Iterations: 6
            Function evaluations: 6
            Gradient evaluations: 6
Optimization Complete
-----------------------------------
False
prob.cleanup()
cr = om.CaseReader("cases.sql")
driver_cases = cr.list_cases('driver')
driver
rank0:ScipyOptimize_SLSQP|0
driver
rank0:ScipyOptimize_SLSQP|1
driver
rank0:ScipyOptimize_SLSQP|2
driver
rank0:ScipyOptimize_SLSQP|3
driver
rank0:ScipyOptimize_SLSQP|4
driver
rank0:ScipyOptimize_SLSQP|5
driver
rank0:ScipyOptimize_SLSQP|6
last_case = cr.get_case(driver_cases[-1])
print(last_case)
driver rank0:ScipyOptimize_SLSQP|6 {'z': array([1.97763888, 0.        ]), 'x': array([0.]), 'con1': array([-8.60893579e-11]), 'con2': array([-20.24472223]), 'y1': array([3.16]), 'y2': array([3.75527777]), 'obj': array([3.18339395])}
last_case.get_objectives()
{'obj': array([3.18339395])}
last_case.get_design_vars()
{'z': array([1.97763888, 0.        ]), 'x': array([0.])}
last_case.get_constraints()
{'con1': array([-8.60893579e-11]), 'con2': array([-20.24472223])}
last_case.inputs['obj_cmp.x']
array([0.])
last_case.outputs['z']
array([1.97763888, 0.        ])
last_case.residuals['obj']
array([3.88031829e-11])
last_case['y1']
array([3.16])