# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
#   orphan: true
# ---

# + tags=["remove-input", "remove-output", "active-ipynb"]
# try:
#     from openmdao.utils.notebook_utils import notebook_mode
# except ImportError:
#     !python -m pip install openmdao[notebooks]
# -

# # 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.

# + tags=["remove-input", "remove-output"]
from openmdao.utils.notebook_utils import get_code
from myst_nb import glue
glue("code_src62", get_code("openmdao.test_suite.components.paraboloid.Paraboloid"), display=False)
# -

# :::{Admonition} `Paraboloid` class definition 
# :class: dropdown
#
# {glue:}`code_src62`
# :::

# +
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*')
# -

prob.check_partials(compact_print=True, includes=['*d1', '*e1'])

prob.check_partials(compact_print=True, includes=['abc1cab'])

# + pycharm={"name": "#%%\n"}
prob.check_partials(compact_print=True, includes='*c*c*', excludes=['*e*'])

StarcoderdataJupyterScriptsDedupFiltered