Checking Partial Derivatives on a Subset of a Model

Includes and Excludes

When you have a model with a large number of components, you may want to reduce the number of components you check so that the output is small and readable. The check_partials method has two arguments: “includes” and “excludes” that help you specify a reduced set. Both of these arguments are lists of strings that default to None. If you specify “includes”, and give it a list containing strings, then only the components whose full pathnames match one of the patterns in those strings are included in the check. Wildcards are acceptable in the string patterns. Likewise, if you specify excludes, then components whose pathname matches the given patterns will be excluded from the check.

You can use both arguments together to hone in on the precise set of components you wish to check.

import openmdao.api as om
from openmdao.test_suite.components.paraboloid import Paraboloid

prob = om.Problem()
model = prob.model

sub = model.add_subsystem('c1c', om.Group())
sub.add_subsystem('d1', Paraboloid())
sub.add_subsystem('e1', Paraboloid())

sub2 = model.add_subsystem('sss', om.Group())
sub3 = sub2.add_subsystem('sss2', om.Group())
sub2.add_subsystem('d1', Paraboloid())
sub3.add_subsystem('e1', Paraboloid())

model.add_subsystem('abc1cab', Paraboloid())

prob.setup()
prob.run_model()

prob.check_partials(compact_print=True, includes='*c*c*')
------------------------------
Component: Paraboloid 'c1c.d1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
------------------------------
Component: Paraboloid 'c1c.e1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
-------------------------------
Component: Paraboloid 'abc1cab'
-------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07

#############################################################
Sub Jacobian with Largest Relative Error: Paraboloid 'c1c.d1'
#############################################################
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------
'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
{'c1c.d1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'c1c.e1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'abc1cab': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}}}
prob.check_partials(compact_print=True, includes=['*d1', '*e1'])
------------------------------
Component: Paraboloid 'c1c.d1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
------------------------------
Component: Paraboloid 'c1c.e1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
-----------------------------------
Component: Paraboloid 'sss.sss2.e1'
-----------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
------------------------------
Component: Paraboloid 'sss.d1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07

#############################################################
Sub Jacobian with Largest Relative Error: Paraboloid 'c1c.d1'
#############################################################
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------
'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
{'c1c.d1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'c1c.e1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'sss.sss2.e1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'sss.d1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}}}
prob.check_partials(compact_print=True, includes=['abc1cab'])
-------------------------------
Component: Paraboloid 'abc1cab'
-------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07

##############################################################
Sub Jacobian with Largest Relative Error: Paraboloid 'abc1cab'
##############################################################
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------
'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
{'abc1cab': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}}}
prob.check_partials(compact_print=True, includes='*c*c*', excludes=['*e*'])
------------------------------
Component: Paraboloid 'c1c.d1'
------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07
-------------------------------
Component: Paraboloid 'abc1cab'
-------------------------------
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------

'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
'f_xy'     wrt 'y'          | 8.0000e+00 | 8.0000e+00 | 9.9943e-07 | 1.2493e-07

#############################################################
Sub Jacobian with Largest Relative Error: Paraboloid 'c1c.d1'
#############################################################
'<output>' wrt '<variable>' | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
-------------------------------------------------------------------------------
'f_xy'     wrt 'x'          | 6.0000e+00 | 6.0000e+00 | 9.9925e-07 | 1.6654e-07
{'c1c.d1': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}},
 'abc1cab': {('f_xy', 'x'): {'J_fwd': array([[-6.]]),
   'J_fd': array([[-5.999999]]),
   'abs error': ErrorTuple(forward=9.992502327804687e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=6.0, reverse=None, fd=5.999999000749767),
   'rel error': ErrorTuple(forward=1.6654173319955572e-07, reverse=None, forward_reverse=None)},
  ('f_xy', 'y'): {'J_fwd': array([[8.]]),
   'J_fd': array([[8.000001]]),
   'abs error': ErrorTuple(forward=9.994307674787706e-07, reverse=None, forward_reverse=None),
   'magnitude': MagnitudeTuple(forward=8.0, reverse=None, fd=8.000000999430767),
   'rel error': ErrorTuple(forward=1.2492883032763172e-07, reverse=None, forward_reverse=None)}}}