Problem Recording

You might also want to attach a recorder to the Problem itself. This allows you to record an arbitrary case at a point of your choosing. This feature can be useful if you only record a limited number of variables during the run but would like to see a more complete list of values after the run.

The options are a subset of those for driver recording.

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_abs_error True [True, False] ['bool'] Set to True to record absolute error of model nonlinear solver
record_constraintsTrue [True, False] ['bool'] Set to True to record constraints at the problem level
record_derivativesFalse [True, False] ['bool'] Set to True to record derivatives for the problem level
record_desvars True [True, False] ['bool'] Set to True to record design variables at the problem level
record_inputs False [True, False] ['bool'] Set True to record inputs at the problem level.
record_objectives True [True, False] ['bool'] Set to True to record objectives at the problem level
record_outputs True [True, False] ['bool'] Set True to record outputs at the problem level.
record_rel_error True [True, False] ['bool'] Set to True to record relative error of model nonlinear solver
record_residuals False [True, False] ['bool'] Set True to record residuals at the problem level.
record_responses False [True, False] ['bool'] Set True to record constraints and objectives at the problem level.

Note

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

Problem 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)

prob.driver = om.ScipyOptimizeDriver(optimizer='SLSQP', tol=1e-9)

prob.add_recorder(om.SqliteRecorder("cases.sql"))

prob.recording_options['includes'] = []
prob.recording_options['record_objectives'] = True
prob.recording_options['record_constraints'] = True
prob.recording_options['record_desvars'] = True

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.record('final')
prob.cleanup()

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

# get list of cases recorded on problem
problem_cases = cr.list_cases('problem')
problem
final
# get list of output variables recorded on problem
cr.list_source_vars('problem')
inputs outputs residuals
con1
con2
obj
x
z
{'inputs': [], 'outputs': ['con1', 'con2', 'obj', 'x', 'z'], 'residuals': []}
# get the recorded case
case = cr.get_case('final')
case.get_objectives()
{'obj': array([3.18339395])}
case.get_design_vars()
{'x': array([0.]), 'z': array([1.97763888, 0.        ])}
case.get_constraints()
{'con1': array([-8.60893579e-11]), 'con2': array([-20.24472223])}