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. |
| invalid_desvar_behavior | warn | ['warn', 'raise', 'ignore'] | N/A | Behavior 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.
Paraboloid class definition
class Paraboloid(om.ExplicitComponent):
"""
Evaluates the equation f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3.
"""
def setup(self):
self.add_input('x', val=0.0)
self.add_input('y', val=0.0)
self.add_output('f_xy', val=0.0)
def setup_partials(self):
self.declare_partials('*', '*')
def compute(self, inputs, outputs):
"""
f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3
Optimal solution (minimum): x = 6.6667; y = -7.3333
"""
x = inputs['x']
y = inputs['y']
outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0
def compute_partials(self, inputs, partials):
"""
Jacobian for our paraboloid.
"""
x = inputs['x']
y = inputs['y']
partials['f_xy', 'x'] = 2.0*x - 6.0 + y
partials['f_xy', 'y'] = 2.0*y + 8.0 + x
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()
[1790952268.406976] [runnervm8df0l:8527 :0] ib_iface.c:1269 UCX ERROR mana_0: iface 0x55f1da97bad0 failed to create UD QP TX wr:256 sge:6 inl:64 resp:0 RX wr:4096 sge:1 resp:0 failed: Operation not supported
[1790952268.407231] [runnervm8df0l:8527 :0] ucp_worker.c:1412 UCX ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error
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])}
[runnervm8df0l:08527] pml_ucx.c:313 Error: Failed to create UCP worker
Problem: problem
Driver: ScipyOptimizeDriver
success : True
iterations : 5
runtime : 4.4355E-02 s
model_evals : 5
model_time : 9.3493E-04 s
deriv_evals : 4
deriv_time : 3.2594E-02 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.00025904199992510257 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00018405399998755456 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.00015852600006383 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00014337900006466953 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.00018654699999842705 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.0001304499999150721 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.00016180800002985052 secs
In mode: fwd.
('y', [1])
Elapsed Time: 0.00012904599998364574 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.5434E-02 s
model_evals : 5
model_time : 6.9401E-04 s
deriv_evals : 4
deriv_time : 1.1649E-02 s
exit_status : SUCCESS