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

[]

N/A

[‘list’]

List of what type of Driver variables to print at each iteration. Valid items in list are ‘desvars’, ‘ln_cons’, ‘nl_cons’, ‘objs’, ‘totals’

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])}

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, Solving variable(s) using simul coloring:
('x', [0])
Elapsed Time: 0.00017595291137695312 

In mode: fwd, Solving variable(s) using simul coloring:
('y', [1])
Elapsed Time: 0.0001087188720703125 

{('comp.f_xy', '_auto_ivc.v0'): array([[144.]])}
{('comp.f_xy', '_auto_ivc.v1'): array([[158.]])}
{('con.c', '_auto_ivc.v0'): array([[-1.]])}
{('con.c', '_auto_ivc.v1'): array([[1.]])}

Driver total derivatives for iteration: 3
-----------------------------------------

In mode: fwd, Solving variable(s) using simul coloring:
('x', [0])
Elapsed Time: 0.00013589859008789062 

In mode: fwd, Solving variable(s) using simul coloring:
('y', [1])
Elapsed Time: 0.00010538101196289062 

{('comp.f_xy', '_auto_ivc.v0'): array([[-126.]])}
{('comp.f_xy', '_auto_ivc.v1'): array([[-127.]])}
{('con.c', '_auto_ivc.v0'): array([[-1.]])}
{('con.c', '_auto_ivc.v1'): array([[1.]])}

Driver total derivatives for iteration: 4
-----------------------------------------

In mode: fwd, Solving variable(s) using simul coloring:
('x', [0])
Elapsed Time: 0.0001323223114013672 

In mode: fwd, Solving variable(s) using simul coloring:
('y', [1])
Elapsed Time: 0.00010442733764648438 

{('comp.f_xy', '_auto_ivc.v0'): array([[0.50120438]])}
{('comp.f_xy', '_auto_ivc.v1'): array([[-0.49879562]])}
{('con.c', '_auto_ivc.v0'): array([[-1.]])}
{('con.c', '_auto_ivc.v1'): array([[1.]])}

Driver total derivatives for iteration: 5
-----------------------------------------

In mode: fwd, Solving variable(s) using simul coloring:
('x', [0])
Elapsed Time: 0.0001266002655029297 

In mode: fwd, Solving variable(s) using simul coloring:
('y', [1])
Elapsed Time: 0.00011420249938964844 

{('comp.f_xy', '_auto_ivc.v0'): array([[0.5]])}
{('comp.f_xy', '_auto_ivc.v1'): array([[-0.5]])}
{('con.c', '_auto_ivc.v0'): array([[-1.]])}
{('con.c', '_auto_ivc.v1'): array([[1.]])}