# Using Solver Options#

All solvers (both nonlinear and linear) have a number of options that you access via the options attribute that control its behavior:

OptionDefaultAcceptable ValuesAcceptable TypesDescription
atol1e-10N/AN/Aabsolute error tolerance
err_on_non_convergeFalse[True, False]['bool']When True, AnalysisError will be raised if we don't converge.
iprint1N/A['int']whether to print output
maxiter10N/A['int']maximum number of iterations
rtol1e-10N/AN/Arelative error tolerance

## Iteration Limit and Convergence Tolerances#

Here is how you would change the iteration limit and convergence tolerances for NonlinearBlockGS.

import numpy as np

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

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

nlbgs = prob.model.nonlinear_solver = om.NonlinearBlockGS()

nlbgs.options['maxiter'] = 20
nlbgs.options['atol'] = 1e-6
nlbgs.options['rtol'] = 1e-6

prob.setup()
prob.set_val('x', 1.)
prob.set_val('z', np.array([5.0, 2.0]))
prob.run_model()

print(prob.get_val('y1'))
print(prob.get_val('y2'))

NL: NLBGS Converged in 5 iterations
[25.5883027]
[12.05848818]


## Displaying Solver Convergence Info#

Solvers can all print out some information about their convergence history. If you want to control that printing behavior you can use the iprint option in the solver.

iprint = -1: Print nothing

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

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

prob.setup()

newton = prob.model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
scipy = prob.model.linear_solver = om.ScipyKrylov()

newton.options['maxiter'] = 2

# use a real bad initial guess
prob.set_val('y1', 10000)
prob.set_val('y2', -26)

newton.options['iprint'] = -1
scipy.options['iprint'] = -1
prob.run_model()


iprint = 0: Print only errors or convergence failures.

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

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

prob.setup()

newton = prob.model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
scipy = prob.model.linear_solver = om.ScipyKrylov()

newton.options['maxiter'] = 1

prob.set_val('y1', 10000)
prob.set_val('y2', -26)

newton.options['iprint'] = 0
scipy.options['iprint'] = 0

prob.run_model()

NL: NewtonSolver 'NL: Newton' on system '' failed to converge in 1 iterations.


iprint = 1: Print a convergence summary, as well as errors and convergence failures.

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

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

prob.setup()

newton = prob.model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
scipy = prob.model.linear_solver = om.ScipyKrylov()

newton.options['maxiter'] = 20

prob.set_val('y1', 10000)
prob.set_val('y2', -26)

newton.options['iprint'] = 1
scipy.options['iprint'] = 0
prob.run_model()

NL: Newton Converged in 2 iterations


iprint = 2: Print the residual for every solver iteration.

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

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

prob.setup()

newton = prob.model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
scipy = prob.model.linear_solver = om.ScipyKrylov()

newton.options['maxiter'] = 20

prob.set_val('y1', 10000)
prob.set_val('y2', -26)

newton.options['iprint'] = 2
scipy.options['iprint'] = 1
prob.run_model()

NL: Newton 0 ; 1.95729619e+11 1
NL: Newton 1 ; 1.60660573e+13 82.0829129
NL: Newton 2 ; 0.118870341 6.07319123e-13
NL: Newton Converged


## Controlling Solver Output in Large Models#

When you have a large model with multiple solvers, it is easier to use a shortcut method that recurses over the entire model. The set_solver_print method on problem can be used to set the iprint to one of four specific values for all solvers in the model while specifically controlling depth (how many systems deep) and the solver type (linear, nonlinear, or both.)

To print everything, just call set_solver_print with a level of “2”.

import numpy as np
from openmdao.test_suite.components.double_sellar import SubSellar

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

model.connect('sub1.sub2.g1.y2', 'g2.x')
model.connect('g2.y2', 'sub1.sub2.g1.x')

model.nonlinear_solver = om.NewtonSolver()
model.linear_solver = om.ScipyKrylov()
model.nonlinear_solver.options['solve_subsystems'] = True
model.nonlinear_solver.options['max_sub_solves'] = 0

g1.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g1.linear_solver = om.LinearBlockGS()

g2.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g2.linear_solver = om.ScipyKrylov()
g2.linear_solver.precon = om.LinearBlockGS()
g2.linear_solver.precon.options['maxiter'] = 2

prob.set_solver_print(level=2)

prob.setup()
prob.set_val('z', np.array([5.0, 2.0]))
prob.run_model()

+
+  ============
+  sub1.sub2.g1
+  ============
+  NL: Newton 0 ; 27.6990975 1
+  |
+  |  ============
+  |  sub1.sub2.g1
+  |  ============
+  |  LN: LNBGS 0 ; 27.6990975 1
+  |  LN: LNBGS 1 ; 4.08 0.147297218
+  |  LN: LNBGS 2 ; 0.408 0.0147297218
+  |  LN: LNBGS 3 ; 0.0408 0.00147297218
+  |  LN: LNBGS 4 ; 0.00408 0.000147297218
+  |  LN: LNBGS 5 ; 0.000408 1.47297218e-05
+  |  LN: LNBGS 6 ; 4.08e-05 1.47297218e-06
+  |  LN: LNBGS 7 ; 4.08e-06 1.47297218e-07
+  |  LN: LNBGS 8 ; 4.07999998e-07 1.47297217e-08
+  |  LN: LNBGS 9 ; 4.07999998e-08 1.47297217e-09
+  |  LN: LNBGS 10 ; 4.08000034e-09 1.4729723e-10
+  |  LN: LNBGSSolver 'LN: LNBGS' on system 'sub1.sub2.g1' failed to converge in 10 iterations.
+  |  LS: BCHK 0 ; 7.63720546 0.275720372
+  NL: Newton 1 ; 7.63720546 0.275720372
+  |
+  |  ============
+  |  sub1.sub2.g1
+  |  ============
+  |  LN: LNBGS 0 ; 35.8626295 1
+  |  LN: LNBGS 1 ; 5.31210051 0.148123565
+  |  LN: LNBGS 2 ; 0.108228014 0.00301784938
+  |  LN: LNBGS 3 ; 0.00220502286 6.14852533e-05
+  |  LN: LNBGS 4 ; 4.49248361e-05 1.2526922e-06
+  |  LN: LNBGS 5 ; 9.15292506e-07 2.55221806e-08
+  |  LN: LNBGS 6 ; 1.86480453e-08 5.19985445e-10
+  |  LN: LNBGS 7 ; 3.79932752e-10 1.05941131e-11
+  |  LN: LNBGS Converged
+  |  LS: BCHK 0 ; 0.00229800815 0.000300896468
+  NL: Newton 2 ; 0.00229800815 8.29632863e-05
+  |
+  |  ============
+  |  sub1.sub2.g1
+  |  ============
+  |  LN: LNBGS 0 ; 7.63037967 1
+  |  LN: LNBGS 1 ; 1.52607593 0.2
+  |  LN: LNBGS 2 ; 0.030168883 0.00395378531
+  |  LN: LNBGS 3 ; 0.000596406432 7.81620913e-05
+  |  LN: LNBGS 4 ; 1.1790315e-05 1.54518064e-06
+  |  LN: LNBGS 5 ; 2.3308187e-07 3.05465626e-08
+  |  LN: LNBGS 6 ; 4.60777837e-09 6.03872752e-10
+  |  LN: LNBGS 7 ; 9.10908321e-11 1.19379161e-11
+  |  LN: LNBGS Converged
+  |  LS: BCHK 0 ; 2.16279761e-10 9.41161853e-08
+  NL: Newton 3 ; 2.16279761e-10 7.80818802e-12
+  NL: Newton Converged
+
+  ==
+  g2
+  ==
+  NL: Newton 0 ; 10.8584882 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.8584882 1
+  |  | precon: LNBGS 1 ; 1.08584882 0.1
+  |  | precon: LNBGS 2 ; 0.108584882 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.8584882 1
+  |  | precon: LNBGS 1 ; 1.08584882 0.1
+  |  | precon: LNBGS 2 ; 0.108584882 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.6413184 1
+  |  | precon: LNBGS 1 ; 1.06413184 0.1
+  |  | precon: LNBGS 2 ; 0.106413184 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 2.49800181e-16 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 2.49800181e-18 0.01
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 2 ; 0 0
+  |  LS: BCHK 0 ; 2.674353 0.246291469
+  NL: Newton 1 ; 2.674353 0.246291469
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 12.66543 1
+  |  | precon: LNBGS 1 ; 1.56456798 0.123530585
+  |  | precon: LNBGS 2 ; 0.0472420672 0.00373000105
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 24.0487147 1
+  |  | precon: LNBGS 1 ; 2.59147581 0.107759431
+  |  | precon: LNBGS 2 ; 0.0782495077 0.00325379167
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.6727044 1
+  |  | precon: LNBGS 1 ; 0.532934672 0.199399033
+  |  | precon: LNBGS 2 ; 0.016091941 0.00602084577
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 7.12525342e-16 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 7.74934974e-18 0.0108758935
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.68222378 1
+  |  | precon: LNBGS 1 ; 0.539919121 0.20129533
+  |  | precon: LNBGS 2 ; 0.0163028361 0.00607810438
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 2 ; 3.01138717e-05 4.22635799e+10
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67584873 1
+  |  | precon: LNBGS 1 ; 0.53864468 0.201298629
+  |  | precon: LNBGS 2 ; 0.0162643545 0.00607820399
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 3 ; 1.35468819e-19 0.000190124914
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 4 ; 1.61653308e-21 2.26873766e-06
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.72207698 1
+  |  | precon: LNBGS 1 ; 0.547945113 0.2012967
+  |  | precon: LNBGS 2 ; 0.0165451806 0.00607814575
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 5 ; 0.000814635071 1.1433068e+12
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67587396 1
+  |  | precon: LNBGS 1 ; 0.538659315 0.2013022
+  |  | precon: LNBGS 2 ; 0.0162647964 0.00607831184
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 6 ; 1.91049564e-18 0.00268130202
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 7 ; 1.17783423e-20 1.65304188e-05
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.72207703 1
+  |  | precon: LNBGS 1 ; 0.54794514 0.201296706
+  |  | precon: LNBGS 2 ; 0.0165451814 0.00607814595
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 8 ; 0.000814635071 1.1433068e+12
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 9 ; 0 0
+  |  LS: BCHK 0 ; 0.0165539668 0.00618989595
+  NL: Newton 2 ; 0.0165539668 0.00152451857
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67426796 1
+  |  | precon: LNBGS 1 ; 0.538263012 0.201274898
+  |  | precon: LNBGS 2 ; 0.0159647335 0.00596975834
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 5.34823697 1
+  |  | precon: LNBGS 1 ; 1.07614315 0.20121456
+  |  | precon: LNBGS 2 ; 0.0319181109 0.00596796872
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0472941148 1
+  |  | precon: LNBGS 1 ; 0.00151048882 0.0319381984
+  |  | precon: LNBGS 2 ; 4.48006846e-05 0.000947278214
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 3.57122253e-14 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 4.48087082e-05 0.00270682603
+  NL: Newton 3 ; 4.48087082e-05 4.12660654e-06
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0164643302 1
+  |  | precon: LNBGS 1 ; 0.000380381222 0.0231033524
+  |  | precon: LNBGS 2 ; 1.12740071e-05 0.000684753463
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0329734648 1
+  |  | precon: LNBGS 1 ; 0.00076192069 0.0231070861
+  |  | precon: LNBGS 2 ; 2.25823431e-05 0.000684864125
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 8.99693667e-05 1
+  |  | precon: LNBGS 1 ; 2.49687009e-06 0.0277524471
+  |  | precon: LNBGS 2 ; 7.40039978e-08 0.000822546613
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 8.07507045e-14 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 7.40039979e-08 0.00165155392
+  NL: Newton 4 ; 7.40039979e-08 6.81531322e-09
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 4.49566895e-05 1
+  |  | precon: LNBGS 1 ; 1.16263519e-06 0.0258612278
+  |  | precon: LNBGS 2 ; 3.44589359e-08 0.000766491847
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 8.98393882e-05 1
+  |  | precon: LNBGS 1 ; 2.32307575e-06 0.0258580985
+  |  | precon: LNBGS 2 ; 6.88528262e-08 0.000766399099
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 6.3701655e-08 1
+  |  | precon: LNBGS 1 ; 1.88678521e-09 0.0296190925
+  |  | precon: LNBGS 2 ; 5.59217642e-11 0.00087786988
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 0 ; 1.33391965e-13 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 5.59214897e-11 0.000755654982
+  NL: Newton 5 ; 5.59214897e-11 5.15002539e-12
+  NL: Newton Converged
NL: Newton 0 ; 2.37397296 1
|  LN: SCIPY 0 ; 0.0983596964 1
|  LN: SCIPY 1 ; 0.0693696177 0.705264658
|  LN: SCIPY 2 ; 0.0140631674 0.142976929
|  LN: SCIPY 3 ; 2.18130031e-16 2.21767695e-15
|  LS: BCHK 0 ; 0.00515047967 0.00216956121
NL: Newton 1 ; 0.00515047967 0.00216956121
|  LN: SCIPY 0 ; 43.4785647 1
|  LN: SCIPY 1 ; 31.5021075 0.72454341
|  LN: SCIPY 2 ; 6.15996484 0.141678201
|  LN: SCIPY 3 ; 1.27073172e-14 2.92266254e-16
|  LS: BCHK 0 ; 7.76418953e-08 1.50746921e-05
NL: Newton 2 ; 7.76418953e-08 3.27054674e-08
|  LN: SCIPY 0 ; 47073.4629 1
|  LN: SCIPY 1 ; 9397.23772 0.199629199
|  LN: SCIPY 2 ; 6363.98153 0.135192551
|  LN: SCIPY 3 ; 8.31781461e-12 1.76698592e-16
|  LN: SCIPY 4 ; 0 0
|  LS: BCHK 0 ; 1.77635684e-15 2.28788444e-08
NL: Newton 3 ; 1.77635684e-15 7.48263298e-16
NL: Newton Converged


To print everything for nonlinear solvers, and nothing for the linear solvers, first turn everything on, as shown above, and then call set_solver_print again to set a level of “-1” on just the linear solvers (using the type_ argument), so that we suppress everything, including the messages when the linear block Gauss-Seidel solver hits the maximum iteration limit. You can call the set_solver_print method multiple times to stack different solver print types in your model.

from openmdao.test_suite.components.double_sellar import SubSellar

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

model.connect('sub1.sub2.g1.y2', 'g2.x')
model.connect('g2.y2', 'sub1.sub2.g1.x')

model.nonlinear_solver = om.NewtonSolver()
model.linear_solver = om.ScipyKrylov()
model.nonlinear_solver.options['solve_subsystems'] = True
model.nonlinear_solver.options['max_sub_solves'] = 0

g1.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g1.linear_solver = om.LinearBlockGS()

g2.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g2.linear_solver = om.ScipyKrylov()
g2.linear_solver.precon = om.LinearBlockGS()
g2.linear_solver.precon.options['maxiter'] = 2

prob.set_solver_print(level=2)
prob.set_solver_print(level=-1, type_='LN')

prob.setup()
prob.set_val('z', np.array([5.0, 2.0]))
prob.run_model()

+
+  ============
+  sub1.sub2.g1
+  ============
+  NL: Newton 0 ; 27.6990975 1
+  |  LS: BCHK 0 ; 7.63720546 0.275720372
+  NL: Newton 1 ; 7.63720546 0.275720372
+  |  LS: BCHK 0 ; 0.00229800815 0.000300896468
+  NL: Newton 2 ; 0.00229800815 8.29632863e-05
+  |  LS: BCHK 0 ; 2.16279761e-10 9.41161853e-08
+  NL: Newton 3 ; 2.16279761e-10 7.80818802e-12
+  NL: Newton Converged
+
+  ==
+  g2
+  ==
+  NL: Newton 0 ; 10.8584882 1
+  |  LS: BCHK 0 ; 2.674353 0.246291469
+  NL: Newton 1 ; 2.674353 0.246291469
+  |  LS: BCHK 0 ; 0.0165539668 0.00618989595
+  NL: Newton 2 ; 0.0165539668 0.00152451857
+  |  LS: BCHK 0 ; 4.48087082e-05 0.00270682603
+  NL: Newton 3 ; 4.48087082e-05 4.12660654e-06
+  |  LS: BCHK 0 ; 7.40039979e-08 0.00165155392
+  NL: Newton 4 ; 7.40039979e-08 6.81531322e-09
+  |  LS: BCHK 0 ; 5.59214897e-11 0.000755654982
+  NL: Newton 5 ; 5.59214897e-11 5.15002539e-12
+  NL: Newton Converged
NL: Newton 0 ; 2.37397296 1
|  LS: BCHK 0 ; 0.00515047967 0.00216956121
NL: Newton 1 ; 0.00515047967 0.00216956121
|  LS: BCHK 0 ; 7.76418953e-08 1.50746921e-05
NL: Newton 2 ; 7.76418953e-08 3.27054674e-08
|  LS: BCHK 0 ; 1.77635684e-15 2.28788444e-08
NL: Newton 3 ; 1.77635684e-15 7.48263298e-16
NL: Newton Converged


If we just want to print solver output for the first level of this multi-level model, we first turn off all printing, and then set a print level of “2” with a depth argument of “2” so that we only print the top solver and the solver in ‘g2’, but not the solver in ‘sub1.sub2.g1’.

from openmdao.test_suite.components.double_sellar import SubSellar

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

model.connect('sub1.sub2.g1.y2', 'g2.x')
model.connect('g2.y2', 'sub1.sub2.g1.x')

model.nonlinear_solver = om.NewtonSolver()
model.linear_solver = om.ScipyKrylov()
model.nonlinear_solver.options['solve_subsystems'] = True
model.nonlinear_solver.options['max_sub_solves'] = 0

g1.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g1.linear_solver = om.LinearBlockGS()

g2.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g2.linear_solver = om.ScipyKrylov()
g2.linear_solver.precon = om.LinearBlockGS()
g2.linear_solver.precon.options['maxiter'] = 2

prob.set_solver_print(level=0)
prob.set_solver_print(level=2, depth=2)

prob.setup()
prob.set_val('z', np.array([5.0, 2.0]))
prob.run_model()

+  |  LN: LNBGSSolver 'LN: LNBGS' on system 'sub1.sub2.g1' failed to converge in 10 iterations.
+
+  ==
+  g2
+  ==
+  NL: Newton 0 ; 10.8584882 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.8584882 1
+  |  | precon: LNBGS 1 ; 1.08584882 0.1
+  |  | precon: LNBGS 2 ; 0.108584882 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.8584882 1
+  |  | precon: LNBGS 1 ; 1.08584882 0.1
+  |  | precon: LNBGS 2 ; 0.108584882 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 10.6413184 1
+  |  | precon: LNBGS 1 ; 1.06413184 0.1
+  |  | precon: LNBGS 2 ; 0.106413184 0.01
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 2.49800181e-16 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 2.49800181e-18 0.01
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 2 ; 0 0
+  |  LS: BCHK 0 ; 2.674353 0.246291469
+  NL: Newton 1 ; 2.674353 0.246291469
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 12.66543 1
+  |  | precon: LNBGS 1 ; 1.56456798 0.123530585
+  |  | precon: LNBGS 2 ; 0.0472420672 0.00373000105
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 24.0487147 1
+  |  | precon: LNBGS 1 ; 2.59147581 0.107759431
+  |  | precon: LNBGS 2 ; 0.0782495077 0.00325379167
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.6727044 1
+  |  | precon: LNBGS 1 ; 0.532934672 0.199399033
+  |  | precon: LNBGS 2 ; 0.016091941 0.00602084577
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 7.12525342e-16 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 7.74934974e-18 0.0108758935
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.68222378 1
+  |  | precon: LNBGS 1 ; 0.539919121 0.20129533
+  |  | precon: LNBGS 2 ; 0.0163028361 0.00607810438
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 2 ; 3.01138717e-05 4.22635799e+10
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67584873 1
+  |  | precon: LNBGS 1 ; 0.53864468 0.201298629
+  |  | precon: LNBGS 2 ; 0.0162643545 0.00607820399
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 3 ; 1.35468819e-19 0.000190124914
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 4 ; 1.61653308e-21 2.26873766e-06
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.72207698 1
+  |  | precon: LNBGS 1 ; 0.547945113 0.2012967
+  |  | precon: LNBGS 2 ; 0.0165451806 0.00607814575
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 5 ; 0.000814635071 1.1433068e+12
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67587396 1
+  |  | precon: LNBGS 1 ; 0.538659315 0.2013022
+  |  | precon: LNBGS 2 ; 0.0162647964 0.00607831184
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 6 ; 1.91049564e-18 0.00268130202
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 7 ; 1.17783423e-20 1.65304188e-05
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.72207703 1
+  |  | precon: LNBGS 1 ; 0.54794514 0.201296706
+  |  | precon: LNBGS 2 ; 0.0165451814 0.00607814595
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 8 ; 0.000814635071 1.1433068e+12
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 9 ; 0 0
+  |  LS: BCHK 0 ; 0.0165539668 0.00618989595
+  NL: Newton 2 ; 0.0165539668 0.00152451857
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 2.67426796 1
+  |  | precon: LNBGS 1 ; 0.538263012 0.201274898
+  |  | precon: LNBGS 2 ; 0.0159647335 0.00596975834
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 5.34823697 1
+  |  | precon: LNBGS 1 ; 1.07614315 0.20121456
+  |  | precon: LNBGS 2 ; 0.0319181109 0.00596796872
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0472941148 1
+  |  | precon: LNBGS 1 ; 0.00151048882 0.0319381984
+  |  | precon: LNBGS 2 ; 4.48006846e-05 0.000947278214
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 3.57122253e-14 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 4.48087082e-05 0.00270682603
+  NL: Newton 3 ; 4.48087082e-05 4.12660654e-06
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0164643302 1
+  |  | precon: LNBGS 1 ; 0.000380381222 0.0231033524
+  |  | precon: LNBGS 2 ; 1.12740071e-05 0.000684753463
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0.0329734648 1
+  |  | precon: LNBGS 1 ; 0.00076192069 0.0231070861
+  |  | precon: LNBGS 2 ; 2.25823431e-05 0.000684864125
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 8.99693667e-05 1
+  |  | precon: LNBGS 1 ; 2.49687009e-06 0.0277524471
+  |  | precon: LNBGS 2 ; 7.40039978e-08 0.000822546613
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  LN: SCIPY 0 ; 8.07507045e-14 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 7.40039979e-08 0.00165155392
+  NL: Newton 4 ; 7.40039979e-08 6.81531322e-09
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 4.49566895e-05 1
+  |  | precon: LNBGS 1 ; 1.16263519e-06 0.0258612278
+  |  | precon: LNBGS 2 ; 3.44589359e-08 0.000766491847
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 8.98393882e-05 1
+  |  | precon: LNBGS 1 ; 2.32307575e-06 0.0258580985
+  |  | precon: LNBGS 2 ; 6.88528262e-08 0.000766399099
+  |  | precon:LN: LNBGSSolver 'LN: LNBGS' on system 'g2' failed to converge in 2 iterations.
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 6.3701655e-08 1
+  |  | precon: LNBGS 1 ; 1.88678521e-09 0.0296190925
+  |  | precon: LNBGS 2 ; 5.59217642e-11 0.00087786988
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 0 ; 1.33391965e-13 1
+  |  | precon:
+  |  | precon:==
+  |  | precon:g2
+  |  | precon:==
+  |  | precon: LNBGS 0 ; 0 0
+  |  | precon:LN: LNBGS Converged
+  |  LN: SCIPY 1 ; 0 0
+  |  LS: BCHK 0 ; 5.59214897e-11 0.000755654982
+  NL: Newton 5 ; 5.59214897e-11 5.15002539e-12
+  NL: Newton Converged
NL: Newton 0 ; 2.37397296 1

|  LN: SCIPY 0 ; 0.0983596964 1
|  LN: SCIPY 1 ; 0.0693696177 0.705264658
|  LN: SCIPY 2 ; 0.0140631674 0.142976929
|  LN: SCIPY 3 ; 2.18130031e-16 2.21767695e-15
|  LS: BCHK 0 ; 0.00515047967 0.00216956121
NL: Newton 1 ; 0.00515047967 0.00216956121
|  LN: SCIPY 0 ; 43.4785647 1
|  LN: SCIPY 1 ; 31.5021075 0.72454341
|  LN: SCIPY 2 ; 6.15996484 0.141678201
|  LN: SCIPY 3 ; 1.27073172e-14 2.92266254e-16
|  LS: BCHK 0 ; 7.76418953e-08 1.50746921e-05
NL: Newton 2 ; 7.76418953e-08 3.27054674e-08
|  LN: SCIPY 0 ; 47073.4629 1
|  LN: SCIPY 1 ; 9397.23772 0.199629199
|  LN: SCIPY 2 ; 6363.98153 0.135192551
|  LN: SCIPY 3 ; 8.31781461e-12 1.76698592e-16
|  LN: SCIPY 4 ; 0 0
|  LS: BCHK 0 ; 1.77635684e-15 2.28788444e-08
NL: Newton 3 ; 1.77635684e-15 7.48263298e-16
NL: Newton Converged


The set_solver_print method can also be called on Systems. For instance, if we want to print detailed output from group ‘g2’ down, we can first call set_solver_print on the problem or the top level model with a level of “-1”, and then call it on group ‘g2’ with a level of “2”.

from openmdao.test_suite.components.double_sellar import SubSellar

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

model.connect('sub1.sub2.g1.y2', 'g2.x')
model.connect('g2.y2', 'sub1.sub2.g1.x')

model.nonlinear_solver = om.NewtonSolver()
model.linear_solver = om.ScipyKrylov()
model.nonlinear_solver.options['solve_subsystems'] = True
model.nonlinear_solver.options['max_sub_solves'] = 0

g1.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g1.linear_solver = om.LinearBlockGS()

g2.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
g2.linear_solver = om.ScipyKrylov()
g2.linear_solver.precon = om.LinearBlockGS()
g2.linear_solver.precon.options['maxiter'] = 2

prob.set_solver_print(level=-1, type_='all')
g2.set_solver_print(level=2, type_='NL')

prob.setup()
prob.run_model()

+
+  ==
+  g2
+  ==
+  NL: Newton 0 ; 0.295012438 1
+  |  LS: BCHK 0 ; 0.0110545084 0.0374713301
+  NL: Newton 1 ; 0.0110545084 0.0374713301
+  |  LS: BCHK 0 ; 0.00687558034 0.621970698
+  NL: Newton 2 ; 0.00687558034 0.0233060694
+  |  LS: BCHK 0 ; 0.00124205541 0.180647356
+  NL: Newton 3 ; 0.00124205541 0.00421017982
+  |  LS: BCHK 0 ; 0.000137418458 0.110637945
+  NL: Newton 4 ; 0.000137418458 0.000465805642
+  |  LS: BCHK 0 ; 8.09548135e-07 0.00589111642
+  NL: Newton 5 ; 8.09548135e-07 2.74411527e-06
+  |  LS: BCHK 0 ; 9.24332674e-08 0.114178841
+  NL: Newton 6 ; 9.24332674e-08 3.13319899e-07
+  |  LS: BCHK 0 ; 1.81463298e-08 0.196318169
+  NL: Newton 7 ; 1.81463298e-08 6.15103889e-08
+  |  LS: BCHK 0 ; 3.26172223e-09 0.179745561
+  NL: Newton 8 ; 3.26172223e-09 1.10562194e-08
+  |  LS: BCHK 0 ; 3.61296326e-10 0.110768576
+  NL: Newton 9 ; 3.61296326e-10 1.22468167e-09
+  |  LS: BCHK 0 ; 0.000188750805 522426.582
+  NL: Newton 10 ; 0.000188750805 0.000639806261
+  NL: NewtonSolver 'NL: Newton' on system 'g2' failed to converge in 10 iterations.