<jupyter_start><jupyter_text>Solver Debug PrintingWhen working with a model and you have a situation where a nonlinear solver is not converging, it may be helpful to know the complete set of input and output values from the initialization of the failing case so that it can be recreated for debugging purposes. `NonlinearSolver` provides the `debug_print` option for this purpose: NonlinearSolver Options<jupyter_code>import openmdao.api as om
om.show_options_table("openmdao.solvers.solver.NonlinearSolver")<jupyter_output><empty_output><jupyter_text>UsageThis example shows how to use the `debug_print` option for a `NonlinearSolver`. When this option is set to True, the values of the input and output variables will be displayed and written to a file if the solver fails to converge.<jupyter_code>from openmdao.utils.notebook_utils import get_code
from myst_nb import glue
glue("code_src67", get_code("openmdao.test_suite.scripts.circuit_analysis.Circuit"), display=False)<jupyter_output><empty_output><jupyter_text>:::{Admonition} `Circuit` class definition :class: dropdown{glue:}`code_src67`:::<jupyter_code>from distutils.version import LooseVersion
import numpy as np

import openmdao.api as om
from openmdao.test_suite.scripts.circuit_analysis import Circuit
from openmdao.utils.general_utils import printoptions

p = om.Problem()
model = p.model

model.add_subsystem('circuit', Circuit())

p.setup()

nl = model.circuit.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)

nl.options['iprint'] = 2
nl.options['debug_print'] = True
nl.options['err_on_non_converge'] = True

# set some poor initial guesses so that we don't converge
p.set_val('circuit.I_in', 0.1, units='A')
p.set_val('circuit.Vg', 0.0, units='V')
p.set_val('circuit.n1.V', 10.)
p.set_val('circuit.n2.V', 1e-3)

opts = {}
# formatting has changed in numpy 1.14 and beyond.
if LooseVersion(np.__version__) >= LooseVersion("1.14"):
    opts["legacy"] = '1.13'

with printoptions(**opts):
    # run the model
    try:
        p.run_model()
    except om.AnalysisError:
        pass

with open('solver_errors.0.out', 'r') as f:
    print(f.read())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1062152133580705, 'fraction_numerical': 0.011595547309833023, 'mean_word_length': 5.783018867924528, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '160201', 'license': 'Apache-2.0', 'n_tokens_mistral': 736, 'n_tokens_neox': 705, 'n_words': 203, 'path': 'openmdao/docs/openmdao_book/features/debugging/debugging_solvers.ipynb', 'repo_name': 'tong0711/OpenMDAO', 'size': '2156'}