{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input",
     "remove-output",
     "active-ipynb"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from openmdao.utils.notebook_utils import notebook_mode\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Checking Partial Derivatives on a Subset of a Model\n",
    "## Includes and Excludes\n",
    "\n",
    "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.\n",
    "\n",
    "You can use both arguments together to hone in on the precise set of components you wish to check."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "from openmdao.utils.notebook_utils import get_code\n",
    "from myst_nb import glue\n",
    "glue(\"code_src62\", get_code(\"openmdao.test_suite.components.paraboloid.Paraboloid\"), display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ":::{Admonition} `Paraboloid` class definition \n",
    ":class: dropdown\n",
    "\n",
    "{glue:}`code_src62`\n",
    ":::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "from openmdao.test_suite.components.paraboloid import Paraboloid\n",
    "\n",
    "prob = om.Problem()\n",
    "model = prob.model\n",
    "\n",
    "sub = model.add_subsystem('c1c', om.Group())\n",
    "sub.add_subsystem('d1', Paraboloid())\n",
    "sub.add_subsystem('e1', Paraboloid())\n",
    "\n",
    "sub2 = model.add_subsystem('sss', om.Group())\n",
    "sub3 = sub2.add_subsystem('sss2', om.Group())\n",
    "sub2.add_subsystem('d1', Paraboloid())\n",
    "sub3.add_subsystem('e1', Paraboloid())\n",
    "\n",
    "model.add_subsystem('abc1cab', Paraboloid())\n",
    "\n",
    "prob.setup()\n",
    "prob.run_model()\n",
    "\n",
    "prob.check_partials(compact_print=True, includes='*c*c*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prob.check_partials(compact_print=True, includes=['*d1', '*e1'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prob.check_partials(compact_print=True, includes=['abc1cab'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "prob.check_partials(compact_print=True, includes='*c*c*', excludes=['*e*'])"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  },
  "orphan": true
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
