Driver Debug Printing#

When working with a model, it may sometimes be helpful to print out the design variables, constraints, and objectives as the Driver iterates. OpenMDAO provides options on the Driver to let you do that.

Driver Options#

OptionDefaultAcceptable ValuesAcceptable TypesDescription
debug_print[]['desvars', 'nl_cons', 'ln_cons', 'objs', 'totals']['list']List of what type of Driver variables to print at each iteration.
invalid_desvar_behaviorwarn['warn', 'raise', 'ignore']N/ABehavior of driver if the initial value of a design variable exceeds its bounds. The default value may beset using the `OPENMDAO_INVALID_DESVAR_BEHAVIOR` environment variable to one of the valid options.

Usage#

This example shows how to use the Driver debug printing options. The debug_print option is a list of strings. Valid strings include ‘desvars’, ‘ln_cons’, ‘nl_cons’, and ‘objs’. Note that the values for the design variables printed are unscaled, physical values.

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', 50.0)
model.set_input_defaults('y', 50.0)

prob.set_solver_print(level=0)

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

prob.driver.options['debug_print'] = ['desvars','ln_cons','nl_cons','objs']

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', upper=-15.0)

prob.setup()

prob.run_driver()
Driver debug print for iter coord: rank0:ScipyOptimize_SLSQP|0
--------------------------------------------------------------
Design Vars
{'x': array([50.]), 'y': array([50.])}
Nonlinear constraints
{'c': array([0.])}

Linear constraints
None

Objectives
{'f_xy': array([7622.])}
Driver debug print for iter coord: rank0:ScipyOptimize_SLSQP|1
--------------------------------------------------------------
Design Vars
{'x': array([50.]), 'y': array([50.])}
Nonlinear constraints
{'c': array([0.])}

Linear constraints
None

Objectives
{'f_xy': array([7622.])}
Driver debug print for iter coord: rank0:ScipyOptimize_SLSQP|2
--------------------------------------------------------------
Design Vars
{'x': array([-35.]), 'y': array([-50.])}
Nonlinear constraints
{'c': array([-15.])}

Linear constraints
None

Objectives
{'f_xy': array([5307.])}
Driver debug print for iter coord: rank0:ScipyOptimize_SLSQP|3
--------------------------------------------------------------
Design Vars
{'x': array([7.16706813]), 'y': array([-7.83293187])}
Nonlinear constraints
{'c': array([-15.])}

Linear constraints
None

Objectives
{'f_xy': array([-27.08333285])}
Driver debug print for iter coord: rank0:ScipyOptimize_SLSQP|4
--------------------------------------------------------------
Design Vars
{'x': array([7.16666667]), 'y': array([-7.83333333])}
Nonlinear constraints
{'c': array([-15.])}

Linear constraints
None

Objectives
{'f_xy': array([-27.08333333])}
False

We can also use the debug printing to print some basic information about the derivative calculations so that you can see which derivative is being solved, how long it takes, and the computed values by including the ‘totals’ string in the “debug_print” list.

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', 50.0)
model.set_input_defaults('y', 50.0)

prob.set_solver_print(level=0)

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

prob.driver.options['debug_print'] = ['totals']

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', upper=-15.0)

prob.setup()

prob.run_driver()
Driver total derivatives for iteration: 2
-----------------------------------------

In mode: fwd.
('x', [0])
Elapsed Time: 0.00028836599994974677 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.0002885669998704543 secs
{('f_xy', 'x'): array([[144.]])}
{('f_xy', 'y'): array([[158.]])}
{('c', 'x'): array([[-1.]])}
{('c', 'y'): array([[1.]])}
Driver total derivatives for iteration: 3
-----------------------------------------

In mode: fwd.
('x', [0])
Elapsed Time: 0.00016215099981309322 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.0002767739999853802 secs
{('f_xy', 'x'): array([[-126.]])}
{('f_xy', 'y'): array([[-127.]])}
{('c', 'x'): array([[-1.]])}
{('c', 'y'): array([[1.]])}
Driver total derivatives for iteration: 4
-----------------------------------------

In mode: fwd.
('x', [0])
Elapsed Time: 0.00024526500010324526 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.0002591820000361622 secs
{('f_xy', 'x'): array([[0.50120438]])}
{('f_xy', 'y'): array([[-0.49879562]])}
{('c', 'x'): array([[-1.]])}
{('c', 'y'): array([[1.]])}
Driver total derivatives for iteration: 5
-----------------------------------------

In mode: fwd.
('x', [0])
Elapsed Time: 0.0001566710000133753 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00022037899998395005 secs
{('f_xy', 'x'): array([[0.5]])}
{('f_xy', 'y'): array([[-0.5]])}
{('c', 'x'): array([[-1.]])}
{('c', 'y'): array([[1.]])}
False