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])}
Problem: problem
Driver:  ScipyOptimizeDriver
  success     : True
  iterations  : 5
  runtime     : 1.3579E-02 s
  model_evals : 5
  model_time  : 1.0307E-03 s
  deriv_evals : 4
  deriv_time  : 3.3619E-03 s
  exit_status : SUCCESS

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.0002547050000885065 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00020707700014099828 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.00015951799991853477 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00024049000012382749 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.0002640029999838589 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00026441399995746906 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.0002449179999075568 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00023858600002313324 secs
{('f_xy', 'x'): array([[0.5]])}
{('f_xy', 'y'): array([[-0.5]])}
{('c', 'x'): array([[-1.]])}
{('c', 'y'): array([[1.]])}
Problem: problem2
Driver:  ScipyOptimizeDriver
  success     : True
  iterations  : 5
  runtime     : 1.7869E-02 s
  model_evals : 5
  model_time  : 1.8189E-03 s
  deriv_evals : 4
  deriv_time  : 1.2817E-02 s
  exit_status : SUCCESS