Driver Debug Printing

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

Option Default Acceptable Values Acceptable Types Description
debug_print[] ['desvars', 'nl_cons', 'ln_cons', 'objs', 'totals']['list'] List of what type of Driver variables to print at each iteration.

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
{'con.c': array([0.])}

Linear constraints
None

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

Linear constraints
None

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

Linear constraints
None

Objectives
{'comp.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
{'con.c': array([-15.])}

Linear constraints
None

Objectives
{'comp.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
{'con.c': array([-15.])}

Linear constraints
None

Objectives
{'comp.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.00018891099989559734 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00015410900005008443 secs
{('comp.f_xy', 'x'): array([[144.]])}
{('comp.f_xy', 'y'): array([[158.]])}
{('con.c', 'x'): array([[-1.]])}
{('con.c', 'y'): array([[1.]])}
Driver total derivatives for iteration: 3
-----------------------------------------

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

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

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