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.

Driver Recording Options

Option

Default

Acceptable Values

Acceptable Types

Description

excludes

[]

N/A

[‘list’]

Patterns for vars to exclude in recording (processed post-includes). Uses fnmatch wildcards

includes

[]

N/A

[‘list’]

Patterns for variables to include in recording. Uses fnmatch wildcards

record_constraints

True

[True, False]

[‘bool’]

Set to True to record constraints at the driver level

record_derivatives

False

[True, False]

[‘bool’]

Set to True to record derivatives at the driver level

record_desvars

True

[True, False]

[‘bool’]

Set to True to record design variables at the driver level

record_inputs

True

[True, False]

[‘bool’]

Set to True to record inputs at the driver level

record_model_metadata

True

[True, False]

[‘bool’]

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

record_outputs

True

[True, False]

[‘bool’]

Set True to record outputs at the driver level.

record_residuals

False

[True, False]

[‘bool’]

Set True to record residuals at the driver level.

record_responses

False

[True, False]

[‘bool’]

Set True to record constraints and objectives at the driver level

Note

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

Driver Recording Example

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.set_solver_print(0)
prob.run_driver()
Optimization terminated successfully.    (Exit mode 0)
            Current function value: 3.183393951725958
            Iterations: 6
            Function evaluations: 6
            Gradient evaluations: 6
Optimization Complete
-----------------------------------
prob.cleanup()

cr = om.CaseReader("cases.sql")

driver_cases = cr.list_cases('driver')

last_case = cr.get_case(driver_cases[-1])

objectives = last_case.get_objectives()
design_vars = last_case.get_design_vars()
constraints = last_case.get_constraints()

print(objectives['obj'])
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
[3.18339395]
print(design_vars['x'])
[0.]
print(constraints['con1'])
[-8.646861e-11]
print(last_case.inputs['obj_cmp.x'])
[0.]
print(last_case.outputs['z'])
[1.97763888 0.        ]
print(last_case.residuals['obj'])
[3.88027388e-11]