Checking Total Derivatives

If you want to check the analytic derivatives of your model (or just part of it) against finite difference or complex-step approximations, you can use check_totals(). You should always converge your model before calling this method. By default, this method checks the derivatives of all of the driver responses (objectives, constraints) with respect to the des_vars, though you can also specify the variables you want to check. Derivatives are computed and compared in an unscaled form by default, but you can optionally request for them to be computed in scaled form using the ref and ref0 that were declared when adding the constraints, objectives, and des_vars.

Note

You should probably not use this method until you’ve used check_partials() to verify the partials for each component in your model. check_totals() is a blunt instrument, since it can only tell you that there is a problem, but will not give you much insight into which component or group is causing the problem.

Problem.check_totals(of=None, wrt=None, out_stream=DEFAULT_OUT_STREAM, compact_print=False, driver_scaling=False, abs_err_tol=1e-06, rel_err_tol=1e-06, method='fd', step=None, form=None, step_calc='abs', show_progress=False)[source]

Check total derivatives for the model vs. finite difference.

Parameters
oflist of variable name strings or None

Variables whose derivatives will be computed. Default is None, which uses the driver’s objectives and constraints.

wrtlist of variable name strings or None

Variables with respect to which the derivatives will be computed. Default is None, which uses the driver’s desvars.

out_streamfile-like object

Where to send human readable output. By default it goes to stdout. Set to None to suppress.

compact_printbool

Set to True to just print the essentials, one line per input-output pair.

driver_scalingbool

When True, return derivatives that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is False, which is unscaled.

abs_err_tolfloat

Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.

rel_err_tolfloat

Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.

methodstr

Method, ‘fd’ for finite difference or ‘cs’ for complex step. Default is ‘fd’

stepfloat

Step size for approximation. Default is None, which means 1e-6 for ‘fd’ and 1e-40 for ‘cs’.

formstring

Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Default None, which defaults to ‘forward’ for FD.

step_calcstring

Step type for finite difference, can be ‘abs’ for absolute’, or ‘rel’ for relative. Default is ‘abs’.

show_progressbool

True to show progress of check_totals

Returns
Dict of Dicts of Tuples of Floats
First key:

is the (output, input) tuple of strings;

Second key:

is one of [‘rel error’, ‘abs error’, ‘magnitude’, ‘fdstep’];

For ‘rel error’, ‘abs error’, ‘magnitude’ the value is: A tuple containing norms for

forward - fd, adjoint - fd, forward - adjoint.

Please check out the Complex Step Guidelines for more information on how to use it on a model.

Examples

You can check specific combinations of variables by specifying them manually:

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.setup()
prob.run_model()
NL: NLBGS Converged in 8 iterations
# manually specify which derivatives to check
prob.check_totals(of=['obj', 'con1'], wrt=['x', 'z'])
NL: NLBGS Converged in 4 iterations
NL: NLBGS Converged in 5 iterations
NL: NLBGS Converged in 5 iterations
-------------------------------------
Group: SellarDerivatives 'Full Model'
-------------------------------------
  Full Model: 'con1' wrt 'x'
    Analytic Magnitude: 9.806145e-01
          Fd Magnitude: 9.806169e-01 (fd:None)
    Absolute Error (Jan - Jfd) : 2.407248e-06 *

    Relative Error (Jan - Jfd) / Jfd : 2.454831e-06 *

    Raw Analytic Derivative (Jfor)
[[-0.98061448]]

    Raw FD Derivative (Jfd)
[[-0.98061688]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con1' wrt 'z'
    Analytic Magnitude: 9.641989e+00
          Fd Magnitude: 9.641993e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 4.447254e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.612380e-07

    Raw Analytic Derivative (Jfor)
[[-9.61002186 -0.78449158]]

    Raw FD Derivative (Jfd)
[[-9.61002547 -0.78449417]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj' wrt 'x'
    Analytic Magnitude: 2.980614e+00
          Fd Magnitude: 2.980617e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 3.404818e-06 *

    Relative Error (Jan - Jfd) / Jfd : 1.142320e-06 *

    Raw Analytic Derivative (Jfor)
[[2.98061391]]

    Raw FD Derivative (Jfd)
[[2.98061732]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj' wrt 'z'
    Analytic Magnitude: 9.774287e+00
          Fd Magnitude: 9.774291e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 4.448707e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.551437e-07

    Raw Analytic Derivative (Jfor)
[[9.61001056 1.78448534]]

    Raw FD Derivative (Jfd)
[[9.61001417 1.78448793]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{('obj', 'x'): {'J_fwd': array([[2.98061391]]),
  'J_fd': array([[2.98061732]]),
  'abs error': ErrorTuple(forward=3.404818106123031e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.980613913484287, reverse=None, fd=2.980617318302393),
  'rel error': ErrorTuple(forward=1.1423197755766383e-06, reverse=None, forward_reverse=None)},
 ('obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]),
  'J_fd': array([[9.61001417, 1.78448793]]),
  'abs error': ErrorTuple(forward=4.448706700918802e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.77429125733397),
  'rel error': ErrorTuple(forward=4.5514366042456444e-07, reverse=None, forward_reverse=None)},
 ('con1', 'x'): {'J_fwd': array([[-0.98061448]]),
  'J_fd': array([[-0.98061688]]),
  'abs error': ErrorTuple(forward=2.407248433144993e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.9806144751949949, reverse=None, fd=0.980616882443428),
  'rel error': ErrorTuple(forward=2.454830705287054e-06, reverse=None, forward_reverse=None)},
 ('con1', 'z'): {'J_fwd': array([[-9.61002186, -0.78449158]]),
  'J_fd': array([[-9.61002547, -0.78449417]]),
  'abs error': ErrorTuple(forward=4.4472535743135455e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.641988753864103, reverse=None, fd=9.641992568542056),
  'rel error': ErrorTuple(forward=4.6123802136325483e-07, reverse=None, forward_reverse=None)}}

Check all the derivatives that the driver will need:

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.model.add_design_var('x', lower=-100, upper=100)
prob.model.add_design_var('z', lower=-100, upper=100)
prob.model.add_objective('obj')
prob.model.add_constraint('con1', upper=0.0)
prob.model.add_constraint('con2', upper=0.0)

prob.setup()

# We don't call run_driver() here because we don't
# actually want the optimizer to run
prob.run_model()
NL: NLBGS Converged in 8 iterations
# check derivatives of all obj+constraints w.r.t all design variables
prob.check_totals()
NL: NLBGS Converged in 4 iterations
NL: NLBGS Converged in 5 iterations
NL: NLBGS Converged in 5 iterations
-------------------------------------
Group: SellarDerivatives 'Full Model'
-------------------------------------
  Full Model: 'con_cmp1.con1' wrt 'x'
    Analytic Magnitude: 9.806145e-01
          Fd Magnitude: 9.806169e-01 (fd:None)
    Absolute Error (Jan - Jfd) : 2.407248e-06 *

    Relative Error (Jan - Jfd) / Jfd : 2.454831e-06 *

    Raw Analytic Derivative (Jfor)
[[-0.98061448]]

    Raw FD Derivative (Jfd)
[[-0.98061688]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp1.con1' wrt 'z'
    Analytic Magnitude: 9.641989e+00
          Fd Magnitude: 9.641993e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 4.447254e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.612380e-07

    Raw Analytic Derivative (Jfor)
[[-9.61002186 -0.78449158]]

    Raw FD Derivative (Jfd)
[[-9.61002547 -0.78449417]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'x'
    Analytic Magnitude: 9.692762e-02
          Fd Magnitude: 9.692786e-02 (fd:None)
    Absolute Error (Jan - Jfd) : 2.385894e-07

    Relative Error (Jan - Jfd) / Jfd : 2.461515e-06 *

    Raw Analytic Derivative (Jfor)
[[0.09692762]]

    Raw FD Derivative (Jfd)
[[0.09692786]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'z'
    Analytic Magnitude: 2.227817e+00
          Fd Magnitude: 2.227818e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 3.738610e-07

    Relative Error (Jan - Jfd) / Jfd : 1.678149e-07

    Raw Analytic Derivative (Jfor)
[[1.94989072 1.0775421 ]]

    Raw FD Derivative (Jfd)
[[1.94989099 1.07754236]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'x'
    Analytic Magnitude: 2.980614e+00
          Fd Magnitude: 2.980617e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 3.404818e-06 *

    Relative Error (Jan - Jfd) / Jfd : 1.142320e-06 *

    Raw Analytic Derivative (Jfor)
[[2.98061391]]

    Raw FD Derivative (Jfd)
[[2.98061732]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'z'
    Analytic Magnitude: 9.774287e+00
          Fd Magnitude: 9.774291e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 4.448707e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.551437e-07

    Raw Analytic Derivative (Jfor)
[[9.61001056 1.78448534]]

    Raw FD Derivative (Jfd)
[[9.61001417 1.78448793]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{('obj_cmp.obj', 'x'): {'J_fwd': array([[2.98061391]]),
  'J_fd': array([[2.98061732]]),
  'abs error': ErrorTuple(forward=3.404818106123031e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.980613913484287, reverse=None, fd=2.980617318302393),
  'rel error': ErrorTuple(forward=1.1423197755766383e-06, reverse=None, forward_reverse=None)},
 ('obj_cmp.obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]),
  'J_fd': array([[9.61001417, 1.78448793]]),
  'abs error': ErrorTuple(forward=4.448706700918802e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.77429125733397),
  'rel error': ErrorTuple(forward=4.5514366042456444e-07, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'x'): {'J_fwd': array([[-0.98061448]]),
  'J_fd': array([[-0.98061688]]),
  'abs error': ErrorTuple(forward=2.407248433144993e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.9806144751949949, reverse=None, fd=0.980616882443428),
  'rel error': ErrorTuple(forward=2.454830705287054e-06, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'z'): {'J_fwd': array([[-9.61002186, -0.78449158]]),
  'J_fd': array([[-9.61002547, -0.78449417]]),
  'abs error': ErrorTuple(forward=4.4472535743135455e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.641988753864103, reverse=None, fd=9.641992568542056),
  'rel error': ErrorTuple(forward=4.6123802136325483e-07, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'x'): {'J_fwd': array([[0.09692762]]),
  'J_fd': array([[0.09692786]]),
  'abs error': ErrorTuple(forward=2.38589368345421e-07, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.09692762402502489, reverse=None, fd=0.09692786261439323),
  'rel error': ErrorTuple(forward=2.461514799873363e-06, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'z'): {'J_fwd': array([[1.94989072, 1.0775421 ]]),
  'J_fd': array([[1.94989099, 1.07754236]]),
  'abs error': ErrorTuple(forward=3.7386098708941144e-07, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.2278174920246605, reverse=None, fd=2.2278178536542534),
  'rel error': ErrorTuple(forward=1.6781488059096632e-07, reverse=None, forward_reverse=None)}}

Use the driver scaled values during the check:

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.model.add_design_var('x', lower=-100, upper=100, ref=100.0, ref0=-100.0)
prob.model.add_design_var('z', lower=-100, upper=100)
prob.model.add_objective('obj')
prob.model.add_constraint('con1', upper=0.0, ref=3.0)
prob.model.add_constraint('con2', upper=0.0, ref=20.0)

prob.setup()

# We don't call run_driver() here because we don't
# actually want the optimizer to run
prob.run_model()
NL: NLBGS Converged in 8 iterations
# check derivatives of all driver vars using the declared scaling
prob.check_totals(driver_scaling=True)
NL: NLBGS Converged in 4 iterations
NL: NLBGS Converged in 5 iterations
NL: NLBGS Converged in 5 iterations
-------------------------------------
Group: SellarDerivatives 'Full Model'
-------------------------------------
  Full Model: 'con_cmp1.con1' wrt 'x'
    Analytic Magnitude: 6.537430e+01
          Fd Magnitude: 6.537446e+01 (fd:None)
    Absolute Error (Jan - Jfd) : 1.604832e-04 *

    Relative Error (Jan - Jfd) / Jfd : 2.454831e-06 *

    Raw Analytic Derivative (Jfor)
[[-65.37429835]]

    Raw FD Derivative (Jfd)
[[-65.37445883]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp1.con1' wrt 'z'
    Analytic Magnitude: 3.213996e+00
          Fd Magnitude: 3.213998e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 1.482418e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.612380e-07

    Raw Analytic Derivative (Jfor)
[[-3.20334062 -0.26149719]]

    Raw FD Derivative (Jfd)
[[-3.20334182 -0.26149806]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'x'
    Analytic Magnitude: 9.692762e-01
          Fd Magnitude: 9.692786e-01 (fd:None)
    Absolute Error (Jan - Jfd) : 2.385894e-06 *

    Relative Error (Jan - Jfd) / Jfd : 2.461515e-06 *

    Raw Analytic Derivative (Jfor)
[[0.96927624]]

    Raw FD Derivative (Jfd)
[[0.96927863]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'z'
    Analytic Magnitude: 1.113909e-01
          Fd Magnitude: 1.113909e-01 (fd:None)
    Absolute Error (Jan - Jfd) : 1.869305e-08

    Relative Error (Jan - Jfd) / Jfd : 1.678149e-07

    Raw Analytic Derivative (Jfor)
[[0.09749454 0.0538771 ]]

    Raw FD Derivative (Jfd)
[[0.09749455 0.05387712]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'x'
    Analytic Magnitude: 5.961228e+02
          Fd Magnitude: 5.961235e+02 (fd:None)
    Absolute Error (Jan - Jfd) : 6.809636e-04 *

    Relative Error (Jan - Jfd) / Jfd : 1.142320e-06 *

    Raw Analytic Derivative (Jfor)
[[596.1227827]]

    Raw FD Derivative (Jfd)
[[596.12346366]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'z'
    Analytic Magnitude: 9.774287e+00
          Fd Magnitude: 9.774291e+00 (fd:None)
    Absolute Error (Jan - Jfd) : 4.448707e-06 *

    Relative Error (Jan - Jfd) / Jfd : 4.551437e-07

    Raw Analytic Derivative (Jfor)
[[9.61001056 1.78448534]]

    Raw FD Derivative (Jfd)
[[9.61001417 1.78448793]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{('obj_cmp.obj', 'x'): {'J_fwd': array([[596.1227827]]),
  'J_fd': array([[596.12346366]]),
  'abs error': ErrorTuple(forward=0.0006809636212210535, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=596.1227826968574, reverse=None, fd=596.1234636604786),
  'rel error': ErrorTuple(forward=1.1423197755706786e-06, reverse=None, forward_reverse=None)},
 ('obj_cmp.obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]),
  'J_fd': array([[9.61001417, 1.78448793]]),
  'abs error': ErrorTuple(forward=4.448706700918802e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.77429125733397),
  'rel error': ErrorTuple(forward=4.5514366042456444e-07, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'x'): {'J_fwd': array([[-65.37429835]]),
  'J_fd': array([[-65.37445883]]),
  'abs error': ErrorTuple(forward=0.00016048322886774713, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=65.37429834633299, reverse=None, fd=65.37445882956186),
  'rel error': ErrorTuple(forward=2.4548307051557233e-06, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'z'): {'J_fwd': array([[-3.20334062, -0.26149719]]),
  'J_fd': array([[-3.20334182, -0.26149806]]),
  'abs error': ErrorTuple(forward=1.4824178580056967e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=3.213996251288034, reverse=None, fd=3.213997522847352),
  'rel error': ErrorTuple(forward=4.612380213325086e-07, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'x'): {'J_fwd': array([[0.96927624]]),
  'J_fd': array([[0.96927863]]),
  'abs error': ErrorTuple(forward=2.3858936832876765e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.969276240250249, reverse=None, fd=0.9692786261439323),
  'rel error': ErrorTuple(forward=2.4615147997015513e-06, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'z'): {'J_fwd': array([[0.09749454, 0.0538771 ]]),
  'J_fd': array([[0.09749455, 0.05387712]]),
  'abs error': ErrorTuple(forward=1.8693049353418763e-08, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.11139087460123304, reverse=None, fd=0.11139089268271268),
  'rel error': ErrorTuple(forward=1.678148805815238e-07, reverse=None, forward_reverse=None)}}

Display the results in a compact format:

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.model.add_design_var('x', lower=-100, upper=100)
prob.model.add_design_var('z', lower=-100, upper=100)
prob.model.add_objective('obj')
prob.model.add_constraint('con1', upper=0.0)
prob.model.add_constraint('con2', upper=0.0)

prob.setup()

# We don't call run_driver() here because we don't
# actually want the optimizer to run
prob.run_model()
NL: NLBGS Converged in 8 iterations
# check derivatives of all obj+constraints w.r.t all design variables
prob.check_totals(compact_print=True)
NL: NLBGS Converged in 4 iterations
NL: NLBGS Converged in 5 iterations
NL: NLBGS Converged in 5 iterations
-------------------------------------
Group: SellarDerivatives 'Full Model'
-------------------------------------
'<output>'                     wrt '<variable>'                   | calc mag.  | check mag. | a(cal-chk) | r(cal-chk)
---------------------------------------------------------------------------------------------------------------------

'con_cmp1.con1'                wrt 'x'                            | 9.8061e-01 | 9.8062e-01 | 2.4072e-06 | 2.4548e-06
'con_cmp1.con1'                wrt 'z'                            | 9.6420e+00 | 9.6420e+00 | 4.4473e-06 | 4.6124e-07
'con_cmp2.con2'                wrt 'x'                            | 9.6928e-02 | 9.6928e-02 | 2.3859e-07 | 2.4615e-06
'con_cmp2.con2'                wrt 'z'                            | 2.2278e+00 | 2.2278e+00 | 3.7386e-07 | 1.6781e-07
'obj_cmp.obj'                  wrt 'x'                            | 2.9806e+00 | 2.9806e+00 | 3.4048e-06 | 1.1423e-06
'obj_cmp.obj'                  wrt 'z'                            | 9.7743e+00 | 9.7743e+00 | 4.4487e-06 | 4.5514e-07
{('obj_cmp.obj', 'x'): {'J_fwd': array([[2.98061391]]),
  'J_fd': array([[2.98061732]]),
  'abs error': ErrorTuple(forward=3.404818106123031e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.980613913484287, reverse=None, fd=2.980617318302393),
  'rel error': ErrorTuple(forward=1.1423197755766383e-06, reverse=None, forward_reverse=None)},
 ('obj_cmp.obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]),
  'J_fd': array([[9.61001417, 1.78448793]]),
  'abs error': ErrorTuple(forward=4.448706700918802e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.77429125733397),
  'rel error': ErrorTuple(forward=4.5514366042456444e-07, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'x'): {'J_fwd': array([[-0.98061448]]),
  'J_fd': array([[-0.98061688]]),
  'abs error': ErrorTuple(forward=2.407248433144993e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.9806144751949949, reverse=None, fd=0.980616882443428),
  'rel error': ErrorTuple(forward=2.454830705287054e-06, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'z'): {'J_fwd': array([[-9.61002186, -0.78449158]]),
  'J_fd': array([[-9.61002547, -0.78449417]]),
  'abs error': ErrorTuple(forward=4.4472535743135455e-06, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.641988753864103, reverse=None, fd=9.641992568542056),
  'rel error': ErrorTuple(forward=4.6123802136325483e-07, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'x'): {'J_fwd': array([[0.09692762]]),
  'J_fd': array([[0.09692786]]),
  'abs error': ErrorTuple(forward=2.38589368345421e-07, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.09692762402502489, reverse=None, fd=0.09692786261439323),
  'rel error': ErrorTuple(forward=2.461514799873363e-06, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'z'): {'J_fwd': array([[1.94989072, 1.0775421 ]]),
  'J_fd': array([[1.94989099, 1.07754236]]),
  'abs error': ErrorTuple(forward=3.7386098708941144e-07, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.2278174920246605, reverse=None, fd=2.2278178536542534),
  'rel error': ErrorTuple(forward=1.6781488059096632e-07, reverse=None, forward_reverse=None)}}

Use complex step instead of finite difference for a more accurate check. We also tighten the tolerance on the nonlinear Gauss-Seidel solver so that we get more accurate converged values.

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.model.add_design_var('x', lower=-100, upper=100)
prob.model.add_design_var('z', lower=-100, upper=100)
prob.model.add_objective('obj')
prob.model.add_constraint('con1', upper=0.0)
prob.model.add_constraint('con2', upper=0.0)

prob.setup(force_alloc_complex=True)

# We don't call run_driver() here because we don't
# actually want the optimizer to run
prob.run_model()
NL: NLBGS Converged in 8 iterations
prob.model.nonlinear_solver.options['atol'] = 1e-15
prob.model.nonlinear_solver.options['rtol'] = 1e-15

# check derivatives with complex step
prob.check_totals(method='cs')
NL: NLBGS Converged in 7 iterations
NL: NLBGS Converged in 6 iterations
NL: NLBGS Converged in 7 iterations
-------------------------------------
Group: SellarDerivatives 'Full Model'
-------------------------------------
  Full Model: 'con_cmp1.con1' wrt 'x'
    Analytic Magnitude: 9.806145e-01
          Fd Magnitude: 9.806145e-01 (cs:None)
    Absolute Error (Jan - Jfd) : 2.139156e-11

    Relative Error (Jan - Jfd) / Jfd : 2.181444e-11

    Raw Analytic Derivative (Jfor)
[[-0.98061448]]

    Raw FD Derivative (Jfd)
[[-0.98061448]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp1.con1' wrt 'z'
    Analytic Magnitude: 9.641989e+00
          Fd Magnitude: 9.641989e+00 (cs:None)
    Absolute Error (Jan - Jfd) : 1.806088e-08

    Relative Error (Jan - Jfd) / Jfd : 1.873149e-09

    Raw Analytic Derivative (Jfor)
[[-9.61002186 -0.78449158]]

    Raw FD Derivative (Jfd)
[[-9.61002187 -0.78449158]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'x'
    Analytic Magnitude: 9.692762e-02
          Fd Magnitude: 9.692762e-02 (cs:None)
    Absolute Error (Jan - Jfd) : 1.010579e-10

    Relative Error (Jan - Jfd) / Jfd : 1.042612e-09

    Raw Analytic Derivative (Jfor)
[[0.09692762]]

    Raw FD Derivative (Jfd)
[[0.09692762]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'con_cmp2.con2' wrt 'z'
    Analytic Magnitude: 2.227817e+00
          Fd Magnitude: 2.227817e+00 (cs:None)
    Absolute Error (Jan - Jfd) : 3.399852e-10

    Relative Error (Jan - Jfd) / Jfd : 1.526091e-10

    Raw Analytic Derivative (Jfor)
[[1.94989072 1.0775421 ]]

    Raw FD Derivative (Jfd)
[[1.94989072 1.0775421 ]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'x'
    Analytic Magnitude: 2.980614e+00
          Fd Magnitude: 2.980614e+00 (cs:None)
    Absolute Error (Jan - Jfd) : 9.598641e-09

    Relative Error (Jan - Jfd) / Jfd : 3.220357e-09

    Raw Analytic Derivative (Jfor)
[[2.98061391]]

    Raw FD Derivative (Jfd)
[[2.98061392]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_cmp.obj' wrt 'z'
    Analytic Magnitude: 9.774287e+00
          Fd Magnitude: 9.774287e+00 (cs:None)
    Absolute Error (Jan - Jfd) : 1.806122e-08

    Relative Error (Jan - Jfd) / Jfd : 1.847830e-09

    Raw Analytic Derivative (Jfor)
[[9.61001056 1.78448534]]

    Raw FD Derivative (Jfd)
[[9.61001058 1.78448534]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{('obj_cmp.obj', 'x'): {'J_fwd': array([[2.98061391]]),
  'J_fd': array([[2.98061392]]),
  'abs error': ErrorTuple(forward=9.598640549057791e-09, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.980613913484287, reverse=None, fd=2.9806139230829274),
  'rel error': ErrorTuple(forward=3.220356878400965e-09, reverse=None, forward_reverse=None)},
 ('obj_cmp.obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]),
  'J_fd': array([[9.61001058, 1.78448534]]),
  'abs error': ErrorTuple(forward=1.806122365691278e-08, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.774287245923102),
  'rel error': ErrorTuple(forward=1.8478302511977225e-09, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'x'): {'J_fwd': array([[-0.98061448]]),
  'J_fd': array([[-0.98061448]]),
  'abs error': ErrorTuple(forward=2.139155519387259e-11, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.9806144751949949, reverse=None, fd=0.9806144752163864),
  'rel error': ErrorTuple(forward=2.1814439552457394e-11, reverse=None, forward_reverse=None)},
 ('con_cmp1.con1', 'z'): {'J_fwd': array([[-9.61002186, -0.78449158]]),
  'J_fd': array([[-9.61002187, -0.78449158]]),
  'abs error': ErrorTuple(forward=1.8060883775455938e-08, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=9.641988753864103, reverse=None, fd=9.64198877186817),
  'rel error': ErrorTuple(forward=1.873149222922874e-09, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'x'): {'J_fwd': array([[0.09692762]]),
  'J_fd': array([[0.09692762]]),
  'abs error': ErrorTuple(forward=1.0105788428305118e-10, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=0.09692762402502489, reverse=None, fd=0.096927623923967),
  'rel error': ErrorTuple(forward=1.0426117982869784e-09, reverse=None, forward_reverse=None)},
 ('con_cmp2.con2', 'z'): {'J_fwd': array([[1.94989072, 1.0775421 ]]),
  'J_fd': array([[1.94989072, 1.0775421 ]]),
  'abs error': ErrorTuple(forward=3.3998521971973103e-10, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=2.2278174920246605, reverse=None, fd=2.2278174916993536),
  'rel error': ErrorTuple(forward=1.52609098809254e-10, reverse=None, forward_reverse=None)}}

Note that you need to set the argument force_alloc_complex to True when you call setup. This makes sure that the vectors allocate space to pass complex numbers. All systems also have an attribute force_alloc_complex that can be queried during setup in case you need to set up your Component or Group differently to accomodate complex step.

import openmdao.api as om

class SimpleComp(om.ExplicitComponent):

    def setup(self):
        self.add_input('x', val=1.0)
        self.add_output('y', val=1.0)

        self.declare_partials(of='y', wrt='x')

        if self._force_alloc_complex:
            print("Vectors allocated for complex step.")

    def compute(self, inputs, outputs):
        outputs['y'] = 3.0*inputs['x']

    def compute_partials(self, inputs, partials):
        partials['y', 'x'] = 3.

prob = om.Problem()
prob.model.add_subsystem('comp', SimpleComp())

prob.model.add_design_var('comp.x', lower=-100, upper=100)
prob.model.add_objective('comp.y')

prob.setup(force_alloc_complex=True)

prob.run_model()

prob.check_totals(method='cs')
Vectors allocated for complex step.
-------------------------
Group: Group 'Full Model'
-------------------------
  Full Model: 'comp.y' wrt 'comp.x'
    Analytic Magnitude: 3.000000e+00
          Fd Magnitude: 3.000000e+00 (cs:None)
    Absolute Error (Jan - Jfd) : 0.000000e+00

    Relative Error (Jan - Jfd) / Jfd : 0.000000e+00

    Raw Analytic Derivative (Jfor)
[[3.]]

    Raw FD Derivative (Jfd)
[[3.]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{('comp.y', 'comp.x'): {'J_fwd': array([[3.]]),
  'J_fd': array([[3.]]),
  'abs error': ErrorTuple(forward=0.0, reverse=None, forward_reverse=None),
  'magnitude': MagnitudeTuple(forward=3.0, reverse=None, fd=3.0),
  'rel error': ErrorTuple(forward=0.0, reverse=None, forward_reverse=None)}}

Turn off standard output and just view the derivatives in the return:

import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarDerivatives

prob = om.Problem()
prob.model = SellarDerivatives()
prob.model.nonlinear_solver = om.NonlinearBlockGS()

prob.model.add_design_var('x', lower=-100, upper=100)
prob.model.add_design_var('z', lower=-100, upper=100)
prob.model.add_objective('obj')
prob.model.add_constraint('con1', upper=0.0)
prob.model.add_constraint('con2', upper=0.0)

prob.setup()

# We don't call run_driver() here because we don't
# actually want the optimizer to run
prob.run_model()
NL: NLBGS Converged in 8 iterations
# check derivatives of all obj+constraints w.r.t all design variables
totals = prob.check_totals(out_stream=None)
NL: NLBGS Converged in 4 iterations
NL: NLBGS Converged in 5 iterations
NL: NLBGS Converged in 5 iterations
print(totals)
{('obj_cmp.obj', 'x'): {'J_fwd': array([[2.98061391]]), 'J_fd': array([[2.98061732]]), 'abs error': ErrorTuple(forward=3.404818106123031e-06, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=2.980613913484287, reverse=None, fd=2.980617318302393), 'rel error': ErrorTuple(forward=1.1423197755766383e-06, reverse=None, forward_reverse=None)}, ('obj_cmp.obj', 'z'): {'J_fwd': array([[9.61001056, 1.78448534]]), 'J_fd': array([[9.61001417, 1.78448793]]), 'abs error': ErrorTuple(forward=4.448706700918802e-06, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=9.774287228158457, reverse=None, fd=9.77429125733397), 'rel error': ErrorTuple(forward=4.5514366042456444e-07, reverse=None, forward_reverse=None)}, ('con_cmp1.con1', 'x'): {'J_fwd': array([[-0.98061448]]), 'J_fd': array([[-0.98061688]]), 'abs error': ErrorTuple(forward=2.407248433144993e-06, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=0.9806144751949949, reverse=None, fd=0.980616882443428), 'rel error': ErrorTuple(forward=2.454830705287054e-06, reverse=None, forward_reverse=None)}, ('con_cmp1.con1', 'z'): {'J_fwd': array([[-9.61002186, -0.78449158]]), 'J_fd': array([[-9.61002547, -0.78449417]]), 'abs error': ErrorTuple(forward=4.4472535743135455e-06, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=9.641988753864103, reverse=None, fd=9.641992568542056), 'rel error': ErrorTuple(forward=4.6123802136325483e-07, reverse=None, forward_reverse=None)}, ('con_cmp2.con2', 'x'): {'J_fwd': array([[0.09692762]]), 'J_fd': array([[0.09692786]]), 'abs error': ErrorTuple(forward=2.38589368345421e-07, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=0.09692762402502489, reverse=None, fd=0.09692786261439323), 'rel error': ErrorTuple(forward=2.461514799873363e-06, reverse=None, forward_reverse=None)}, ('con_cmp2.con2', 'z'): {'J_fwd': array([[1.94989072, 1.0775421 ]]), 'J_fd': array([[1.94989099, 1.07754236]]), 'abs error': ErrorTuple(forward=3.7386098708941144e-07, reverse=None, forward_reverse=None), 'magnitude': MagnitudeTuple(forward=2.2278174920246605, reverse=None, fd=2.2278178536542534), 'rel error': ErrorTuple(forward=1.6781488059096632e-07, reverse=None, forward_reverse=None)}}