Case Recorder Settings

Table of CaseRecorder Options

Below is a table of options that can be applied to the user’s CaseRecorder

Recorder Options Table

Record Options

Driver

System

Solver

Problem

record_constraints

X

X

record_desvars

X

X

record_objectives

X

X

record_derivatives

X

X

record_responses

X

X

record_inputs

X

X

X

X

record_outputs

X

X

X

X

record_residuals

X

X

X

record_abs_error

X

record_rel_error

X

record_solver_residuals

X

includes

X

X

X

X

excludes

X

X

X

X

options_excludes

X

Specifying a Case Prefix

It is possible to record data from multiple executions by specifying a prefix that will be used to differentiate the cases. This prefix can be specified when calling run_model or run_driver and will be prepended to the case ID in the recorded case data:

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

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

recorder = om.SqliteRecorder("cases.sql", record_viewer_data=False)
prob.model.add_recorder(recorder)
prob.driver.add_recorder(recorder)

prob.set_solver_print(0)

prob.run_model(case_prefix='Model_Run1')
prob.run_driver(case_prefix='Driver_Run1')

prob.run_model('Model_Run2')
prob.run_driver('Driver_Run2')

prob.cleanup()

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

# all cases recorded by the root system
model_cases = cr.list_cases('root', recurse=False)
print('\n'.join(model_cases))
Model_Run1_rank0:root._solve_nonlinear|0
Driver_Run1_rank0:Driver|0|root._solve_nonlinear|0
Model_Run2_rank0:root._solve_nonlinear|0
Driver_Run2_rank0:Driver|0|root._solve_nonlinear|0
# all cases recorded by the driver
driver_cases = cr.list_cases('driver', recurse=False)
print('\n'.join(driver_cases))
Driver_Run1_rank0:Driver|0
Driver_Run2_rank0:Driver|0

Note

A recorder can be attached to more than one object. Also, more than one recorder can be attached to an object.

Note

In this example, we have disabled the saving of data needed by the standalone \(N^2\) visualizer and debugging tool by setting record_viewer_data to False.

Recording Options Include and Exclude Matching

The includes and excludes recording options provide support for Unix shell-style wildcards, which are not the same as regular expressions. The documentation for the fnmatchcase function from the Python standard library documents the wildcards.

Recording Options Precedence

The recording options precedence that determines what gets recorded can sometime be a little confusing. Here is an example that might help. The code shows how the record_desvars and includes options interact.

import openmdao.api as om
from openmdao.test_suite.components.paraboloid import Paraboloid

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

model.add_subsystem('comp', Paraboloid(), promotes=['*'])
model.add_subsystem('con', om.ExecComp('c = x - y'), promotes=['*'])

model.set_input_defaults('x', val=50.0)
model.set_input_defaults('y', val=50.0)

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

model.add_design_var('x', lower=-50.0, upper=50.0)
model.add_design_var('y', lower=-50.0, upper=50.0)
model.add_objective('f_xy')
model.add_constraint('c', lower=15.0)

filename = "cases.sql"
recorder = om.SqliteRecorder(filename)

prob.driver.add_recorder(recorder)
prob.driver.recording_options['record_desvars'] = True
prob.driver.recording_options['record_outputs'] = True
prob.driver.recording_options['includes'] = []
prob.driver.recording_options['excludes'] = []

prob.set_solver_print(0)
prob.setup()
prob.run_driver()
prob.cleanup()

# First case with record_desvars = True and includes = []
cr = om.CaseReader(filename)
case = cr.get_case(-1)

print(sorted(case.outputs.keys()))
['c', 'f_xy', 'x', 'y']
# Second case with record_desvars = False and includes = []
recorder = om.SqliteRecorder(filename)
prob.driver.add_recorder(recorder)
prob.driver.recording_options['record_desvars'] = False
prob.driver.recording_options['record_outputs'] = True
prob.driver.recording_options['includes'] = []

prob.setup()
prob.run_driver()
/home/travis/miniconda/envs/PY3.8/lib/python3.8/site-packages/openmdao/recorders/recording_manager.py:266: UserWarning:The model is being run again, if the options or scaling of any components has changed then only their new values will be recorded.
prob.cleanup()

cr = om.CaseReader(filename)
case = cr.get_case(0)

print(sorted(case.outputs.keys()))
['c', 'f_xy']
# Third case with record_desvars = True and includes = ['*']
recorder = om.SqliteRecorder(filename)
prob.driver.add_recorder(recorder)
prob.driver.recording_options['record_desvars'] = True
prob.driver.recording_options['record_outputs'] = True
prob.driver.recording_options['includes'] = ['*']

prob.setup()
prob.run_driver()
prob.cleanup()

cr = om.CaseReader(filename)
case = cr.get_case(0)

print(sorted(case.outputs.keys()))
['c', 'f_xy', 'x', 'y']
# Fourth case with record_desvars = False, record_outputs = True, and includes = ['*']
recorder = om.SqliteRecorder(filename)
prob.driver.add_recorder(recorder)
prob.driver.recording_options['record_desvars'] = False
prob.driver.recording_options['record_outputs'] = True
prob.driver.recording_options['includes'] = ['*']

prob.setup()
prob.run_driver()
prob.cleanup()

cr = om.CaseReader(filename)
case = cr.get_case(0)

print(sorted(case.outputs.keys()))
['c', 'f_xy', 'x', 'y']