{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f83f5ccc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:05.194213Z",
     "iopub.status.busy": "2026-10-02T14:40:05.193960Z",
     "iopub.status.idle": "2026-10-02T14:40:05.198772Z",
     "shell.execute_reply": "2026-10-02T14:40:05.197857Z"
    },
    "papermill": {
     "duration": 0.008583,
     "end_time": "2026-10-02T14:40:05.199628+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:05.191045+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "active-ipynb",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from openmdao.utils.notebook_utils import notebook_mode  # noqa: F401\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f3e5f86",
   "metadata": {
    "papermill": {
     "duration": 0.001505,
     "end_time": "2026-10-02T14:40:05.203044+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:05.201539+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Raising an AnalysisError\n",
    "\n",
    "This example demonstrates the effect of raising an `AnalysisError` in your Component's `compute` function.  The result depends on which driver and optimizer is used.  The `SNOPT` and `IPOPT` optimizers, used in conjunction with [pyOptSparseDriver](../../features/building_blocks/drivers/pyoptsparse_driver.ipynb), are good options if your model has invalid regions.\n",
    "\n",
    "\n",
    "## Model\n",
    "\n",
    "\n",
    "For this somewhat contrived case, we will assume some range of input values to our Component is invalid and raise an `AnalysisError` if those inputs are encountered.  We will use the [Paraboloid](../../basic_user_guide/single_disciplinary_optimization/first_analysis) as the basis for our example, modifying it so that it will raise an AnalysisError if the x or y inputs are within a specified range."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c253aa2f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:05.287420Z",
     "iopub.status.busy": "2026-10-02T14:40:05.287160Z",
     "iopub.status.idle": "2026-10-02T14:40:16.239933Z",
     "shell.execute_reply": "2026-10-02T14:40:16.239177Z"
    },
    "papermill": {
     "duration": 10.956506,
     "end_time": "2026-10-02T14:40:16.240413+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:05.283907+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "application/papermill.record/text/html": "<style>pre { line-height: 125%; }\ntd.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\nspan.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\ntd.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\nspan.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\n.output_html .hll { background-color: #ffffcc }\n.output_html { background: #f8f8f8; }\n.output_html .c { color: #3D7B7B; font-style: italic } /* Comment */\n.output_html .err { border: 1px solid #F00 } /* Error */\n.output_html .k { color: #008000; font-weight: bold } /* Keyword */\n.output_html .o { color: #666 } /* Operator */\n.output_html .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */\n.output_html .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */\n.output_html .cp { color: #9C6500 } /* Comment.Preproc */\n.output_html .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */\n.output_html .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */\n.output_html .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */\n.output_html .gd { color: #A00000 } /* Generic.Deleted */\n.output_html .ge { font-style: italic } /* Generic.Emph */\n.output_html .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */\n.output_html .gr { color: #E40000 } /* Generic.Error */\n.output_html .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n.output_html .gi { color: #008400 } /* Generic.Inserted */\n.output_html .go { color: #717171 } /* Generic.Output */\n.output_html .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n.output_html .gs { font-weight: bold } /* Generic.Strong */\n.output_html .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n.output_html .gt { color: #04D } /* Generic.Traceback */\n.output_html .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n.output_html .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n.output_html .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n.output_html .kp { color: #008000 } /* Keyword.Pseudo */\n.output_html .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n.output_html .kt { color: #B00040 } /* Keyword.Type */\n.output_html .m { color: #666 } /* Literal.Number */\n.output_html .s { color: #BA2121 } /* Literal.String */\n.output_html .na { color: #687822 } /* Name.Attribute */\n.output_html .nb { color: #008000 } /* Name.Builtin */\n.output_html .nc { color: #00F; font-weight: bold } /* Name.Class */\n.output_html .no { color: #800 } /* Name.Constant */\n.output_html .nd { color: #A2F } /* Name.Decorator */\n.output_html .ni { color: #717171; font-weight: bold } /* Name.Entity */\n.output_html .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */\n.output_html .nf { color: #00F } /* Name.Function */\n.output_html .nl { color: #767600 } /* Name.Label */\n.output_html .nn { color: #00F; font-weight: bold } /* Name.Namespace */\n.output_html .nt { color: #008000; font-weight: bold } /* Name.Tag */\n.output_html .nv { color: #19177C } /* Name.Variable */\n.output_html .ow { color: #A2F; font-weight: bold } /* Operator.Word */\n.output_html .w { color: #BBB } /* Text.Whitespace */\n.output_html .mb { color: #666 } /* Literal.Number.Bin */\n.output_html .mf { color: #666 } /* Literal.Number.Float */\n.output_html .mh { color: #666 } /* Literal.Number.Hex */\n.output_html .mi { color: #666 } /* Literal.Number.Integer */\n.output_html .mo { color: #666 } /* Literal.Number.Oct */\n.output_html .sa { color: #BA2121 } /* Literal.String.Affix */\n.output_html .sb { color: #BA2121 } /* Literal.String.Backtick */\n.output_html .sc { color: #BA2121 } /* Literal.String.Char */\n.output_html .dl { color: #BA2121 } /* Literal.String.Delimiter */\n.output_html .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n.output_html .s2 { color: #BA2121 } /* Literal.String.Double */\n.output_html .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */\n.output_html .sh { color: #BA2121 } /* Literal.String.Heredoc */\n.output_html .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */\n.output_html .sx { color: #008000 } /* Literal.String.Other */\n.output_html .sr { color: #A45A77 } /* Literal.String.Regex */\n.output_html .s1 { color: #BA2121 } /* Literal.String.Single */\n.output_html .ss { color: #19177C } /* Literal.String.Symbol */\n.output_html .bp { color: #008000 } /* Name.Builtin.Pseudo */\n.output_html .fm { color: #00F } /* Name.Function.Magic */\n.output_html .vc { color: #19177C } /* Name.Variable.Class */\n.output_html .vg { color: #19177C } /* Name.Variable.Global */\n.output_html .vi { color: #19177C } /* Name.Variable.Instance */\n.output_html .vm { color: #19177C } /* Name.Variable.Magic */\n.output_html .il { color: #666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Paraboloid</span><span class=\"p\">(</span><span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">ExplicitComponent</span><span class=\"p\">):</span>\n<span class=\"w\">    </span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Evaluates the equation f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3</span>\n\n<span class=\"sd\">    This version of Paraboloid optionally raises an analysis error when the</span>\n<span class=\"sd\">    design variables x and y are in an invalid region defined by the specified</span>\n<span class=\"sd\">    &quot;invalid_x&quot; and &quot;invalid_y&quot; ranges.</span>\n\n<span class=\"sd\">    The path of evaluated points to the optmized solution is recorded as</span>\n<span class=\"sd\">    well as the number of analysis errors raised.</span>\n\n<span class=\"sd\">    Parameters</span>\n<span class=\"sd\">    ----------</span>\n<span class=\"sd\">    invalid_x : tuple of float or None</span>\n<span class=\"sd\">        The range of values for x which will trigger an AnalysisError</span>\n<span class=\"sd\">    invalid_y : tuple of float or None</span>\n<span class=\"sd\">        The range of values for y which will trigger an AnalysisError</span>\n<span class=\"sd\">    func : str, &#39;compute&#39; or &#39;compute_partials&#39;</span>\n<span class=\"sd\">        The function that will raise the AnalysisError (compute or compute_partials).</span>\n\n<span class=\"sd\">    Attributes</span>\n<span class=\"sd\">    ----------</span>\n<span class=\"sd\">    invalid_x : tuple of float or None</span>\n<span class=\"sd\">        The range of values for x which will trigger an AnalysisError</span>\n<span class=\"sd\">    invalid_y : tuple of float or None</span>\n<span class=\"sd\">        The range of values for y which will trigger an AnalysisError</span>\n<span class=\"sd\">    func : str, &#39;compute&#39; or &#39;compute_partials&#39;</span>\n<span class=\"sd\">        The function that will raise the AnalysisError (compute or compute_partials).</span>\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">invalid_x</span><span class=\"o\">=</span><span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"n\">invalid_y</span><span class=\"o\">=</span><span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"n\">func</span><span class=\"o\">=</span><span class=\"s1\">&#39;compute&#39;</span><span class=\"p\">):</span>\n        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"fm\">__init__</span><span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_x</span> <span class=\"o\">=</span> <span class=\"n\">invalid_x</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_y</span> <span class=\"o\">=</span> <span class=\"n\">invalid_y</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">func</span> <span class=\"o\">=</span> <span class=\"n\">func</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_count</span> <span class=\"o\">=</span> <span class=\"o\">-</span><span class=\"mi\">1</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_history</span> <span class=\"o\">=</span> <span class=\"p\">[]</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_eval_errors</span> <span class=\"o\">=</span> <span class=\"p\">[]</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_count</span> <span class=\"o\">=</span> <span class=\"o\">-</span><span class=\"mi\">1</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_history</span> <span class=\"o\">=</span> <span class=\"p\">[]</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_grad_errors</span> <span class=\"o\">=</span> <span class=\"p\">[]</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">setup</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">add_input</span><span class=\"p\">(</span><span class=\"s1\">&#39;x&#39;</span><span class=\"p\">,</span> <span class=\"n\">val</span><span class=\"o\">=</span><span class=\"mf\">0.0</span><span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">add_input</span><span class=\"p\">(</span><span class=\"s1\">&#39;y&#39;</span><span class=\"p\">,</span> <span class=\"n\">val</span><span class=\"o\">=</span><span class=\"mf\">0.0</span><span class=\"p\">)</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">add_output</span><span class=\"p\">(</span><span class=\"s1\">&#39;f_xy&#39;</span><span class=\"p\">,</span> <span class=\"n\">val</span><span class=\"o\">=</span><span class=\"mf\">0.0</span><span class=\"p\">)</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">declare_partials</span><span class=\"p\">(</span><span class=\"s1\">&#39;*&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;*&#39;</span><span class=\"p\">)</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">compute</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">inputs</span><span class=\"p\">,</span> <span class=\"n\">outputs</span><span class=\"p\">):</span>\n<span class=\"w\">        </span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">        f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3</span>\n<span class=\"sd\">        &quot;&quot;&quot;</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_count</span> <span class=\"o\">+=</span> <span class=\"mi\">1</span>\n\n        <span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">inputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;x&#39;</span><span class=\"p\">]</span>\n        <span class=\"n\">y</span> <span class=\"o\">=</span> <span class=\"n\">inputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;y&#39;</span><span class=\"p\">]</span>\n\n        <span class=\"n\">f_xy</span> <span class=\"o\">=</span> <span class=\"n\">outputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;f_xy&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"n\">x</span><span class=\"o\">-</span><span class=\"mf\">3.0</span><span class=\"p\">)</span><span class=\"o\">**</span><span class=\"mi\">2</span> <span class=\"o\">+</span> <span class=\"n\">x</span><span class=\"o\">*</span><span class=\"n\">y</span> <span class=\"o\">+</span> <span class=\"p\">(</span><span class=\"n\">y</span><span class=\"o\">+</span><span class=\"mf\">4.0</span><span class=\"p\">)</span><span class=\"o\">**</span><span class=\"mi\">2</span> <span class=\"o\">-</span> <span class=\"mf\">3.0</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_history</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">((</span><span class=\"n\">x</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">(),</span> <span class=\"n\">y</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">(),</span> <span class=\"n\">f_xy</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()))</span>\n\n        <span class=\"k\">if</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_x</span> <span class=\"ow\">and</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">func</span> <span class=\"o\">==</span> <span class=\"s1\">&#39;compute&#39;</span><span class=\"p\">:</span>\n            <span class=\"n\">beg</span><span class=\"p\">,</span> <span class=\"n\">end</span> <span class=\"o\">=</span>  <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_x</span>\n            <span class=\"k\">if</span> <span class=\"n\">x</span> <span class=\"o\">&gt;=</span> <span class=\"n\">beg</span> <span class=\"ow\">and</span> <span class=\"n\">x</span> <span class=\"o\">&lt;=</span> <span class=\"n\">end</span><span class=\"p\">:</span>\n                <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_eval_errors</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_count</span><span class=\"p\">)</span>\n                <span class=\"k\">raise</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">AnalysisError</span><span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s1\">&#39;Invalid x: </span><span class=\"si\">{</span><span class=\"n\">beg</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">x</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()</span><span class=\"si\">:</span><span class=\"s1\">8.4f</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">end</span><span class=\"si\">}</span><span class=\"s1\">).&#39;</span><span class=\"p\">)</span>\n\n        <span class=\"k\">if</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_y</span> <span class=\"ow\">and</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">func</span> <span class=\"o\">==</span> <span class=\"s1\">&#39;compute&#39;</span><span class=\"p\">:</span>\n            <span class=\"n\">beg</span><span class=\"p\">,</span> <span class=\"n\">end</span> <span class=\"o\">=</span>  <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_y</span>\n            <span class=\"k\">if</span> <span class=\"n\">y</span> <span class=\"o\">&gt;=</span> <span class=\"n\">beg</span> <span class=\"ow\">and</span> <span class=\"n\">y</span> <span class=\"o\">&lt;=</span> <span class=\"n\">end</span><span class=\"p\">:</span>\n                <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_eval_errors</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">eval_count</span><span class=\"p\">)</span>\n                <span class=\"k\">raise</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">AnalysisError</span><span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s1\">&#39;Invalid y: </span><span class=\"si\">{</span><span class=\"n\">beg</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">y</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()</span><span class=\"si\">:</span><span class=\"s1\">8.4f</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">end</span><span class=\"si\">}</span><span class=\"s1\">).&#39;</span><span class=\"p\">)</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">compute_partials</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">inputs</span><span class=\"p\">,</span> <span class=\"n\">partials</span><span class=\"p\">):</span>\n<span class=\"w\">        </span><span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">        Partial derivatives.</span>\n<span class=\"sd\">        &quot;&quot;&quot;</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_count</span> <span class=\"o\">+=</span> <span class=\"mi\">1</span>\n\n        <span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">inputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;x&#39;</span><span class=\"p\">]</span>\n        <span class=\"n\">y</span> <span class=\"o\">=</span> <span class=\"n\">inputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;y&#39;</span><span class=\"p\">]</span>\n\n        <span class=\"n\">partials</span><span class=\"p\">[</span><span class=\"s1\">&#39;f_xy&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;x&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"mf\">2.0</span><span class=\"o\">*</span><span class=\"n\">x</span> <span class=\"o\">-</span> <span class=\"mf\">6.0</span> <span class=\"o\">+</span> <span class=\"n\">y</span>\n        <span class=\"n\">partials</span><span class=\"p\">[</span><span class=\"s1\">&#39;f_xy&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;y&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"mf\">2.0</span><span class=\"o\">*</span><span class=\"n\">y</span> <span class=\"o\">+</span> <span class=\"mf\">8.0</span> <span class=\"o\">+</span> <span class=\"n\">x</span>\n\n        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_history</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">((</span><span class=\"n\">x</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">(),</span> <span class=\"n\">y</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()))</span>\n\n        <span class=\"k\">if</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_x</span> <span class=\"ow\">and</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">func</span> <span class=\"o\">==</span> <span class=\"s1\">&#39;compute_partials&#39;</span><span class=\"p\">:</span>\n            <span class=\"n\">beg</span><span class=\"p\">,</span> <span class=\"n\">end</span> <span class=\"o\">=</span>  <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_x</span>\n            <span class=\"k\">if</span> <span class=\"n\">x</span> <span class=\"o\">&gt;</span> <span class=\"n\">beg</span> <span class=\"ow\">and</span> <span class=\"n\">x</span> <span class=\"o\">&lt;</span> <span class=\"n\">end</span><span class=\"p\">:</span>\n                <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_grad_errors</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_count</span><span class=\"p\">)</span>\n                <span class=\"k\">raise</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">AnalysisError</span><span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s1\">&#39;Invalid x: </span><span class=\"si\">{</span><span class=\"n\">beg</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">x</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()</span><span class=\"si\">:</span><span class=\"s1\">8.4f</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">end</span><span class=\"si\">}</span><span class=\"s1\">).&#39;</span><span class=\"p\">)</span>\n\n        <span class=\"k\">if</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_y</span> <span class=\"ow\">and</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">func</span> <span class=\"o\">==</span> <span class=\"s1\">&#39;compute_partials&#39;</span><span class=\"p\">:</span>\n            <span class=\"n\">beg</span><span class=\"p\">,</span> <span class=\"n\">end</span> <span class=\"o\">=</span>  <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">invalid_y</span>\n            <span class=\"k\">if</span> <span class=\"n\">y</span> <span class=\"o\">&gt;</span> <span class=\"n\">beg</span> <span class=\"ow\">and</span> <span class=\"n\">y</span> <span class=\"o\">&lt;</span> <span class=\"n\">end</span><span class=\"p\">:</span>\n                <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">raised_grad_errors</span><span class=\"o\">.</span><span class=\"n\">append</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">grad_count</span><span class=\"p\">)</span>\n                <span class=\"k\">raise</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">AnalysisError</span><span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s1\">&#39;Invalid y: </span><span class=\"si\">{</span><span class=\"n\">beg</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">y</span><span class=\"o\">.</span><span class=\"n\">item</span><span class=\"p\">()</span><span class=\"si\">:</span><span class=\"s1\">8.4f</span><span class=\"si\">}</span><span class=\"s1\"> &lt; </span><span class=\"si\">{</span><span class=\"n\">end</span><span class=\"si\">}</span><span class=\"s1\">).&#39;</span><span class=\"p\">)</span>\n</pre></div>\n",
      "application/papermill.record/text/latex": "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{k}{class}\\PY{+w}{ }\\PY{n+nc}{Paraboloid}\\PY{p}{(}\\PY{n}{om}\\PY{o}{.}\\PY{n}{ExplicitComponent}\\PY{p}{)}\\PY{p}{:}\n\\PY{+w}{    }\\PY{l+s+sd}{\\PYZdq{}\\PYZdq{}\\PYZdq{}}\n\\PY{l+s+sd}{    Evaluates the equation f(x,y) = (x\\PYZhy{}3)\\PYZca{}2 + xy + (y+4)\\PYZca{}2 \\PYZhy{} 3}\n\n\\PY{l+s+sd}{    This version of Paraboloid optionally raises an analysis error when the}\n\\PY{l+s+sd}{    design variables x and y are in an invalid region defined by the specified}\n\\PY{l+s+sd}{    \\PYZdq{}invalid\\PYZus{}x\\PYZdq{} and \\PYZdq{}invalid\\PYZus{}y\\PYZdq{} ranges.}\n\n\\PY{l+s+sd}{    The path of evaluated points to the optmized solution is recorded as}\n\\PY{l+s+sd}{    well as the number of analysis errors raised.}\n\n\\PY{l+s+sd}{    Parameters}\n\\PY{l+s+sd}{    \\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}}\n\\PY{l+s+sd}{    invalid\\PYZus{}x : tuple of float or None}\n\\PY{l+s+sd}{        The range of values for x which will trigger an AnalysisError}\n\\PY{l+s+sd}{    invalid\\PYZus{}y : tuple of float or None}\n\\PY{l+s+sd}{        The range of values for y which will trigger an AnalysisError}\n\\PY{l+s+sd}{    func : str, \\PYZsq{}compute\\PYZsq{} or \\PYZsq{}compute\\PYZus{}partials\\PYZsq{}}\n\\PY{l+s+sd}{        The function that will raise the AnalysisError (compute or compute\\PYZus{}partials).}\n\n\\PY{l+s+sd}{    Attributes}\n\\PY{l+s+sd}{    \\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}\\PYZhy{}}\n\\PY{l+s+sd}{    invalid\\PYZus{}x : tuple of float or None}\n\\PY{l+s+sd}{        The range of values for x which will trigger an AnalysisError}\n\\PY{l+s+sd}{    invalid\\PYZus{}y : tuple of float or None}\n\\PY{l+s+sd}{        The range of values for y which will trigger an AnalysisError}\n\\PY{l+s+sd}{    func : str, \\PYZsq{}compute\\PYZsq{} or \\PYZsq{}compute\\PYZus{}partials\\PYZsq{}}\n\\PY{l+s+sd}{        The function that will raise the AnalysisError (compute or compute\\PYZus{}partials).}\n\\PY{l+s+sd}{    \\PYZdq{}\\PYZdq{}\\PYZdq{}}\n\n    \\PY{k}{def}\\PY{+w}{ }\\PY{n+nf+fm}{\\PYZus{}\\PYZus{}init\\PYZus{}\\PYZus{}}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{p}{,} \\PY{n}{invalid\\PYZus{}x}\\PY{o}{=}\\PY{k+kc}{None}\\PY{p}{,} \\PY{n}{invalid\\PYZus{}y}\\PY{o}{=}\\PY{k+kc}{None}\\PY{p}{,} \\PY{n}{func}\\PY{o}{=}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{compute}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\\PY{p}{:}\n        \\PY{n+nb}{super}\\PY{p}{(}\\PY{p}{)}\\PY{o}{.}\\PY{n+nf+fm}{\\PYZus{}\\PYZus{}init\\PYZus{}\\PYZus{}}\\PY{p}{(}\\PY{p}{)}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}x} \\PY{o}{=} \\PY{n}{invalid\\PYZus{}x}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}y} \\PY{o}{=} \\PY{n}{invalid\\PYZus{}y}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{func} \\PY{o}{=} \\PY{n}{func}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}count} \\PY{o}{=} \\PY{o}{\\PYZhy{}}\\PY{l+m+mi}{1}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}history} \\PY{o}{=} \\PY{p}{[}\\PY{p}{]}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}eval\\PYZus{}errors} \\PY{o}{=} \\PY{p}{[}\\PY{p}{]}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}count} \\PY{o}{=} \\PY{o}{\\PYZhy{}}\\PY{l+m+mi}{1}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}history} \\PY{o}{=} \\PY{p}{[}\\PY{p}{]}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}grad\\PYZus{}errors} \\PY{o}{=} \\PY{p}{[}\\PY{p}{]}\n\n    \\PY{k}{def}\\PY{+w}{ }\\PY{n+nf}{setup}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{p}{)}\\PY{p}{:}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{add\\PYZus{}input}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{n}{val}\\PY{o}{=}\\PY{l+m+mf}{0.0}\\PY{p}{)}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{add\\PYZus{}input}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{n}{val}\\PY{o}{=}\\PY{l+m+mf}{0.0}\\PY{p}{)}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{add\\PYZus{}output}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{f\\PYZus{}xy}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{n}{val}\\PY{o}{=}\\PY{l+m+mf}{0.0}\\PY{p}{)}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{declare\\PYZus{}partials}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{*}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{*}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\n    \\PY{k}{def}\\PY{+w}{ }\\PY{n+nf}{compute}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{p}{,} \\PY{n}{inputs}\\PY{p}{,} \\PY{n}{outputs}\\PY{p}{)}\\PY{p}{:}\n\\PY{+w}{        }\\PY{l+s+sd}{\\PYZdq{}\\PYZdq{}\\PYZdq{}}\n\\PY{l+s+sd}{        f(x,y) = (x\\PYZhy{}3)\\PYZca{}2 + xy + (y+4)\\PYZca{}2 \\PYZhy{} 3}\n\\PY{l+s+sd}{        \\PYZdq{}\\PYZdq{}\\PYZdq{}}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}count} \\PY{o}{+}\\PY{o}{=} \\PY{l+m+mi}{1}\n\n        \\PY{n}{x} \\PY{o}{=} \\PY{n}{inputs}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]}\n        \\PY{n}{y} \\PY{o}{=} \\PY{n}{inputs}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]}\n\n        \\PY{n}{f\\PYZus{}xy} \\PY{o}{=} \\PY{n}{outputs}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{f\\PYZus{}xy}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]} \\PY{o}{=} \\PY{p}{(}\\PY{n}{x}\\PY{o}{\\PYZhy{}}\\PY{l+m+mf}{3.0}\\PY{p}{)}\\PY{o}{*}\\PY{o}{*}\\PY{l+m+mi}{2} \\PY{o}{+} \\PY{n}{x}\\PY{o}{*}\\PY{n}{y} \\PY{o}{+} \\PY{p}{(}\\PY{n}{y}\\PY{o}{+}\\PY{l+m+mf}{4.0}\\PY{p}{)}\\PY{o}{*}\\PY{o}{*}\\PY{l+m+mi}{2} \\PY{o}{\\PYZhy{}} \\PY{l+m+mf}{3.0}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}history}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{p}{(}\\PY{n}{x}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{y}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{f\\PYZus{}xy}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{p}{)}\\PY{p}{)}\n\n        \\PY{k}{if} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}x} \\PY{o+ow}{and} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{func} \\PY{o}{==} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{compute}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{:}\n            \\PY{n}{beg}\\PY{p}{,} \\PY{n}{end} \\PY{o}{=}  \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}x}\n            \\PY{k}{if} \\PY{n}{x} \\PY{o}{\\PYZgt{}}\\PY{o}{=} \\PY{n}{beg} \\PY{o+ow}{and} \\PY{n}{x} \\PY{o}{\\PYZlt{}}\\PY{o}{=} \\PY{n}{end}\\PY{p}{:}\n                \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}eval\\PYZus{}errors}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}count}\\PY{p}{)}\n                \\PY{k}{raise} \\PY{n}{om}\\PY{o}{.}\\PY{n}{AnalysisError}\\PY{p}{(}\\PY{l+s+sa}{f}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Invalid x: }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{beg}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{x}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{l+s+si}{:}\\PY{l+s+s1}{8.4f}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{end}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{).}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\n        \\PY{k}{if} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}y} \\PY{o+ow}{and} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{func} \\PY{o}{==} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{compute}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{:}\n            \\PY{n}{beg}\\PY{p}{,} \\PY{n}{end} \\PY{o}{=}  \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}y}\n            \\PY{k}{if} \\PY{n}{y} \\PY{o}{\\PYZgt{}}\\PY{o}{=} \\PY{n}{beg} \\PY{o+ow}{and} \\PY{n}{y} \\PY{o}{\\PYZlt{}}\\PY{o}{=} \\PY{n}{end}\\PY{p}{:}\n                \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}eval\\PYZus{}errors}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{eval\\PYZus{}count}\\PY{p}{)}\n                \\PY{k}{raise} \\PY{n}{om}\\PY{o}{.}\\PY{n}{AnalysisError}\\PY{p}{(}\\PY{l+s+sa}{f}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Invalid y: }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{beg}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{y}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{l+s+si}{:}\\PY{l+s+s1}{8.4f}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{end}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{).}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\n    \\PY{k}{def}\\PY{+w}{ }\\PY{n+nf}{compute\\PYZus{}partials}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{p}{,} \\PY{n}{inputs}\\PY{p}{,} \\PY{n}{partials}\\PY{p}{)}\\PY{p}{:}\n\\PY{+w}{        }\\PY{l+s+sd}{\\PYZdq{}\\PYZdq{}\\PYZdq{}}\n\\PY{l+s+sd}{        Partial derivatives.}\n\\PY{l+s+sd}{        \\PYZdq{}\\PYZdq{}\\PYZdq{}}\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}count} \\PY{o}{+}\\PY{o}{=} \\PY{l+m+mi}{1}\n\n        \\PY{n}{x} \\PY{o}{=} \\PY{n}{inputs}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]}\n        \\PY{n}{y} \\PY{o}{=} \\PY{n}{inputs}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]}\n\n        \\PY{n}{partials}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{f\\PYZus{}xy}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{x}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]} \\PY{o}{=} \\PY{l+m+mf}{2.0}\\PY{o}{*}\\PY{n}{x} \\PY{o}{\\PYZhy{}} \\PY{l+m+mf}{6.0} \\PY{o}{+} \\PY{n}{y}\n        \\PY{n}{partials}\\PY{p}{[}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{f\\PYZus{}xy}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{y}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{]} \\PY{o}{=} \\PY{l+m+mf}{2.0}\\PY{o}{*}\\PY{n}{y} \\PY{o}{+} \\PY{l+m+mf}{8.0} \\PY{o}{+} \\PY{n}{x}\n\n        \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}history}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{p}{(}\\PY{n}{x}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{y}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{p}{)}\\PY{p}{)}\n\n        \\PY{k}{if} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}x} \\PY{o+ow}{and} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{func} \\PY{o}{==} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{compute\\PYZus{}partials}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{:}\n            \\PY{n}{beg}\\PY{p}{,} \\PY{n}{end} \\PY{o}{=}  \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}x}\n            \\PY{k}{if} \\PY{n}{x} \\PY{o}{\\PYZgt{}} \\PY{n}{beg} \\PY{o+ow}{and} \\PY{n}{x} \\PY{o}{\\PYZlt{}} \\PY{n}{end}\\PY{p}{:}\n                \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}grad\\PYZus{}errors}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}count}\\PY{p}{)}\n                \\PY{k}{raise} \\PY{n}{om}\\PY{o}{.}\\PY{n}{AnalysisError}\\PY{p}{(}\\PY{l+s+sa}{f}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Invalid x: }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{beg}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{x}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{l+s+si}{:}\\PY{l+s+s1}{8.4f}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{end}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{).}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\n        \\PY{k}{if} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}y} \\PY{o+ow}{and} \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{func} \\PY{o}{==} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{compute\\PYZus{}partials}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{:}\n            \\PY{n}{beg}\\PY{p}{,} \\PY{n}{end} \\PY{o}{=}  \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{invalid\\PYZus{}y}\n            \\PY{k}{if} \\PY{n}{y} \\PY{o}{\\PYZgt{}} \\PY{n}{beg} \\PY{o+ow}{and} \\PY{n}{y} \\PY{o}{\\PYZlt{}} \\PY{n}{end}\\PY{p}{:}\n                \\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{raised\\PYZus{}grad\\PYZus{}errors}\\PY{o}{.}\\PY{n}{append}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{o}{.}\\PY{n}{grad\\PYZus{}count}\\PY{p}{)}\n                \\PY{k}{raise} \\PY{n}{om}\\PY{o}{.}\\PY{n}{AnalysisError}\\PY{p}{(}\\PY{l+s+sa}{f}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Invalid y: }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{beg}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{y}\\PY{o}{.}\\PY{n}{item}\\PY{p}{(}\\PY{p}{)}\\PY{l+s+si}{:}\\PY{l+s+s1}{8.4f}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{ \\PYZlt{} }\\PY{l+s+si}{\\PYZob{}}\\PY{n}{end}\\PY{l+s+si}{\\PYZcb{}}\\PY{l+s+s1}{).}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\end{Verbatim}\n",
      "application/papermill.record/text/plain": "class Paraboloid(om.ExplicitComponent):\n    \"\"\"\n    Evaluates the equation f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3\n\n    This version of Paraboloid optionally raises an analysis error when the\n    design variables x and y are in an invalid region defined by the specified\n    \"invalid_x\" and \"invalid_y\" ranges.\n\n    The path of evaluated points to the optmized solution is recorded as\n    well as the number of analysis errors raised.\n\n    Parameters\n    ----------\n    invalid_x : tuple of float or None\n        The range of values for x which will trigger an AnalysisError\n    invalid_y : tuple of float or None\n        The range of values for y which will trigger an AnalysisError\n    func : str, 'compute' or 'compute_partials'\n        The function that will raise the AnalysisError (compute or compute_partials).\n\n    Attributes\n    ----------\n    invalid_x : tuple of float or None\n        The range of values for x which will trigger an AnalysisError\n    invalid_y : tuple of float or None\n        The range of values for y which will trigger an AnalysisError\n    func : str, 'compute' or 'compute_partials'\n        The function that will raise the AnalysisError (compute or compute_partials).\n    \"\"\"\n\n    def __init__(self, invalid_x=None, invalid_y=None, func='compute'):\n        super().__init__()\n        self.invalid_x = invalid_x\n        self.invalid_y = invalid_y\n        self.func = func\n\n        self.eval_count = -1\n        self.eval_history = []\n        self.raised_eval_errors = []\n\n        self.grad_count = -1\n        self.grad_history = []\n        self.raised_grad_errors = []\n\n    def setup(self):\n        self.add_input('x', val=0.0)\n        self.add_input('y', val=0.0)\n\n        self.add_output('f_xy', val=0.0)\n\n        self.declare_partials('*', '*')\n\n    def compute(self, inputs, outputs):\n        \"\"\"\n        f(x,y) = (x-3)^2 + xy + (y+4)^2 - 3\n        \"\"\"\n        self.eval_count += 1\n\n        x = inputs['x']\n        y = inputs['y']\n\n        f_xy = outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0\n\n        self.eval_history.append((x.item(), y.item(), f_xy.item()))\n\n        if self.invalid_x and self.func == 'compute':\n            beg, end =  self.invalid_x\n            if x >= beg and x <= end:\n                self.raised_eval_errors.append(self.eval_count)\n                raise om.AnalysisError(f'Invalid x: {beg} < {x.item():8.4f} < {end}).')\n\n        if self.invalid_y and self.func == 'compute':\n            beg, end =  self.invalid_y\n            if y >= beg and y <= end:\n                self.raised_eval_errors.append(self.eval_count)\n                raise om.AnalysisError(f'Invalid y: {beg} < {y.item():8.4f} < {end}).')\n\n    def compute_partials(self, inputs, partials):\n        \"\"\"\n        Partial derivatives.\n        \"\"\"\n        self.grad_count += 1\n\n        x = inputs['x']\n        y = inputs['y']\n\n        partials['f_xy', 'x'] = 2.0*x - 6.0 + y\n        partials['f_xy', 'y'] = 2.0*y + 8.0 + x\n\n        self.grad_history.append((x.item(), y.item()))\n\n        if self.invalid_x and self.func == 'compute_partials':\n            beg, end =  self.invalid_x\n            if x > beg and x < end:\n                self.raised_grad_errors.append(self.grad_count)\n                raise om.AnalysisError(f'Invalid x: {beg} < {x.item():8.4f} < {end}).')\n\n        if self.invalid_y and self.func == 'compute_partials':\n            beg, end =  self.invalid_y\n            if y > beg and y < end:\n                self.raised_grad_errors.append(self.grad_count)\n                raise om.AnalysisError(f'Invalid y: {beg} < {y.item():8.4f} < {end}).')"
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "application/papermill.record/",
       "name": "code_paraboloid_invalid_region"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from openmdao.utils.notebook_utils import get_code\n",
    "from myst_nb import glue\n",
    "glue(\"code_paraboloid_invalid_region\", get_code(\"openmdao.test_suite.components.paraboloid_invalid_region.Paraboloid\"), display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e96908f4",
   "metadata": {
    "papermill": {
     "duration": 0.001388,
     "end_time": "2026-10-02T14:40:16.243389+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:16.242001+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    ":::{dropdown} `Paraboloid` class definition \n",
    "\n",
    "{glue:}`code_paraboloid_invalid_region`\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31f82df1",
   "metadata": {
    "papermill": {
     "duration": 0.001272,
     "end_time": "2026-10-02T14:40:16.246028+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:16.244756+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "First, we will define a function to create a Problem instance while allowing us to specify the optimizer and the invalid region:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e33338c4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:16.249406Z",
     "iopub.status.busy": "2026-10-02T14:40:16.249243Z",
     "iopub.status.idle": "2026-10-02T14:40:16.252679Z",
     "shell.execute_reply": "2026-10-02T14:40:16.252192Z"
    },
    "papermill": {
     "duration": 0.005764,
     "end_time": "2026-10-02T14:40:16.253111+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:16.247347+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "from openmdao.test_suite.components.paraboloid_invalid_region import Paraboloid\n",
    "\n",
    "\n",
    "def setup_problem(optimizer, invalid_x=None, invalid_y=None):\n",
    "    # Paraboloid model with optional AnalysisErrors\n",
    "    model = om.Group()\n",
    "\n",
    "    model.add_subsystem('p1', om.IndepVarComp('x', 50.0), promotes=['*'])\n",
    "    model.add_subsystem('p2', om.IndepVarComp('y', 50.0), promotes=['*'])\n",
    "\n",
    "    comp = model.add_subsystem('comp',\n",
    "                               Paraboloid(invalid_x, invalid_y),\n",
    "                               promotes=['*'])\n",
    "\n",
    "    model.add_subsystem('con', om.ExecComp('c = - x + y'), promotes=['*'])\n",
    "\n",
    "    model.add_design_var('x', lower=-50.0, upper=50.0)\n",
    "    model.add_design_var('y', lower=-50.0, upper=50.0)\n",
    "\n",
    "    model.add_objective('f_xy')\n",
    "    model.add_constraint('c', upper=-15.)\n",
    "\n",
    "    # pyOptSparseDriver with selected optimizer\n",
    "    driver = om.pyOptSparseDriver(optimizer=optimizer)\n",
    "    if optimizer == 'IPOPT':\n",
    "        driver.opt_settings['file_print_level'] = 5\n",
    "    driver.options['print_results'] = False\n",
    "    driver.options['output_dir'] = None  # will put the optimizer output file in the current directory\n",
    "\n",
    "    # setup problem & initialize values\n",
    "    prob = om.Problem(model, driver)\n",
    "    prob.setup()\n",
    "\n",
    "    prob.set_val('x', 50)\n",
    "    prob.set_val('y', 50)\n",
    "\n",
    "    return prob, comp"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c254098b",
   "metadata": {
    "papermill": {
     "duration": 0.001259,
     "end_time": "2026-10-02T14:40:16.255757+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:16.254498+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Example using IPOPT\n",
    "\n",
    "First we will run the Paraboloid optimization as normal, without raising any errors. In doing this, we can see the nominal path that the optimizer follows throught solution space to arrive at the optimum.  For this initial case, we will use the `IPOPT` optimizer:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "675bbd3f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:16.282954Z",
     "iopub.status.busy": "2026-10-02T14:40:16.282801Z",
     "iopub.status.idle": "2026-10-02T14:40:18.465779Z",
     "shell.execute_reply": "2026-10-02T14:40:18.465349Z"
    },
    "papermill": {
     "duration": 2.18739,
     "end_time": "2026-10-02T14:40:18.468288+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:16.280898+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952017.515626] [runnervm8df0l:5693 :0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x564217830ef0 failed to create UD QP TX wr:256 sge:6 inl:64 resp:0 RX wr:4096 sge:1 resp:0 failed: Operation not supported\n",
      "[1790952017.516004] [runnervm8df0l:5693 :0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[runnervm8df0l:05693] pml_ucx.c:313  Error: Failed to create UCP worker\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x:  49.50000  y:  49.50000  f_xy: 7471.75015\n",
      "x:   1.91747  y: -25.87525  f_xy:  427.08359\n",
      "x:  10.04882  y: -10.64684  f_xy:  -16.12184\n",
      "x:   9.14631  y:  -9.47131  f_xy:  -21.91518\n",
      "x:   7.28379  y:  -7.95036  f_xy:  -26.95255\n",
      "x:   7.18531  y:  -7.85195  f_xy:  -27.06436\n",
      "x:   7.16735  y:  -7.83402  f_xy:  -27.08265\n",
      "x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n",
      "x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n",
      "x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n"
     ]
    }
   ],
   "source": [
    "prob, comp = setup_problem('IPOPT')\n",
    "prob.run_driver()\n",
    "\n",
    "for (x, y, f_xy) in comp.eval_history:\n",
    "    print(f\"x: {x:9.5f}  y: {y:9.5f}  f_xy: {f_xy:10.5f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8c5abea7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.475022Z",
     "iopub.status.busy": "2026-10-02T14:40:18.474512Z",
     "iopub.status.idle": "2026-10-02T14:40:18.481400Z",
     "shell.execute_reply": "2026-10-02T14:40:18.480461Z"
    },
    "papermill": {
     "duration": 0.01103,
     "end_time": "2026-10-02T14:40:18.482002+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.470972+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(9.467642340305027e-08)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "assert_near_equal(prob['x'], 7.166667, 1e-6)\n",
    "assert_near_equal(prob['y'], -7.833334, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3312922",
   "metadata": {
    "papermill": {
     "duration": 0.002289,
     "end_time": "2026-10-02T14:40:18.495502+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.493213+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Now, we will define our invalid region as `x` between 7.2 and 10.2 and `y` between -50 and -10.  This region was chosen as it is crossed in the course of the nominal optimization from our chosen starting point at `x=50`, `y=50`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "085d9cf9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.501137Z",
     "iopub.status.busy": "2026-10-02T14:40:18.500934Z",
     "iopub.status.idle": "2026-10-02T14:40:18.503953Z",
     "shell.execute_reply": "2026-10-02T14:40:18.503439Z"
    },
    "papermill": {
     "duration": 0.009486,
     "end_time": "2026-10-02T14:40:18.507457+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.497971+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "invalid_x = (7.2, 10.2)\n",
    "invalid_y = (-50., -40.)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e50dace",
   "metadata": {
    "papermill": {
     "duration": 0.017995,
     "end_time": "2026-10-02T14:40:18.527824+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.509829+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "We will recreate the problem using this invalid region and see that the optimizer's path to the optimum now must reroute around the invalid values. It will take many more iterations to get to the solution, but IPOPT still gets there in the end:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e780e0a2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.534387Z",
     "iopub.status.busy": "2026-10-02T14:40:18.534166Z",
     "iopub.status.idle": "2026-10-02T14:40:18.746046Z",
     "shell.execute_reply": "2026-10-02T14:40:18.745594Z"
    },
    "papermill": {
     "duration": 0.216199,
     "end_time": "2026-10-02T14:40:18.746957+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.530758+00:00",
     "status": "completed"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 0  x:  49.50000  y:  49.50000  f_xy: 7471.75015\n",
      " 1  x:   1.91747  y: -25.87525  f_xy:  427.08359\n",
      " 2  x:  10.04882  y: -10.64684  f_xy:  -16.12184\n",
      " 3  x:   5.98314  y: -18.26105  f_xy:  100.01816\n",
      " 4  x:   9.26294  y:  -9.65590  f_xy:  -21.22839\n",
      " 5  x:   7.62304  y: -13.95847  f_xy:   11.13770\n",
      " 6  x:   6.80309  y: -16.10976  f_xy:   48.51363\n",
      " 7  x:   8.56687  y:  -8.93122  f_xy:  -24.20564\n",
      " 8  x:   7.68498  y: -12.52049  f_xy:   -4.67191\n",
      " 9  x:   7.24404  y: -14.31513  f_xy:   17.71439\n",
      "10  x:   7.02356  y: -15.21244  f_xy:   32.06239\n",
      "11  x:   8.01980  y:  -8.42815  f_xy:  -25.78517\n",
      "12  x:   7.52168  y: -11.82030  f_xy:  -10.30586\n",
      "13  x:   7.27262  y: -13.51637  f_xy:    7.51714\n",
      "14  x:   7.14809  y: -14.36441  f_xy:   18.94949\n",
      "15  x:   7.63794  y:  -8.12375  f_xy:  -26.53291\n",
      "16  x:   7.39302  y: -11.24408  f_xy:  -14.35239\n",
      "17  x:   7.27056  y: -12.80424  f_xy:   -0.34162\n",
      "18  x:   7.20932  y: -13.58433  f_xy:    8.64389\n",
      "19  x:   7.17871  y: -13.97437  f_xy:   13.63168\n",
      "20  x:   7.40133  y:  -7.95811  f_xy:  -26.86226\n",
      "21  x:   7.29002  y: -10.96624  f_xy:  -16.01136\n",
      "22  x:   7.23436  y: -12.47030  f_xy:   -3.53886\n",
      "23  x:   7.20654  y: -13.22233  f_xy:    4.45916\n",
      "24  x:   7.19262  y: -13.59835  f_xy:    8.89860\n",
      "25  x:   7.26649  y:  -7.87450  f_xy:  -27.00529\n",
      "26  x:   7.22956  y: -10.73642  f_xy:  -17.35104\n",
      "27  x:   7.21109  y: -12.16739  f_xy:   -6.30064\n",
      "28  x:   7.20186  y: -12.88287  f_xy:    0.78038\n",
      "29  x:   7.19724  y: -13.24061  f_xy:    4.70984\n",
      "30  x:   7.19562  y:  -7.85876  f_xy:  -27.05540\n",
      "31  x:   7.17091  y:  -7.82964  f_xy:  -27.08301\n",
      "32  x:   7.16638  y:  -7.83363  f_xy:  -27.08333\n",
      "33  x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n",
      "34  x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n",
      "35  x:   7.16667  y:  -7.83333  f_xy:  -27.08333\n"
     ]
    }
   ],
   "source": [
    "prob, comp = setup_problem('IPOPT', invalid_x, invalid_y)\n",
    "prob.run_driver()\n",
    "\n",
    "for i, (x, y, f_xy) in enumerate(comp.eval_history):\n",
    "    print(f\"{i:2d}  x: {x:9.5f}  y: {y:9.5f}  f_xy: {f_xy:10.5f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "62a473fa",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.753389Z",
     "iopub.status.busy": "2026-10-02T14:40:18.753172Z",
     "iopub.status.idle": "2026-10-02T14:40:18.757491Z",
     "shell.execute_reply": "2026-10-02T14:40:18.757010Z"
    },
    "papermill": {
     "duration": 0.008016,
     "end_time": "2026-10-02T14:40:18.757911+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.749895+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(9.467957549130128e-08)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "assert_near_equal(prob['x'], 7.166667, 1e-6)\n",
    "assert_near_equal(prob['y'], -7.833334, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34fb1279",
   "metadata": {
    "papermill": {
     "duration": 0.001965,
     "end_time": "2026-10-02T14:40:18.764781+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.762816+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "We can see how many times our Component raised an AnalysisError and at which iteration they occurred:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3f745d15",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.774919Z",
     "iopub.status.busy": "2026-10-02T14:40:18.774598Z",
     "iopub.status.idle": "2026-10-02T14:40:18.777525Z",
     "shell.execute_reply": "2026-10-02T14:40:18.777047Z"
    },
    "papermill": {
     "duration": 0.009189,
     "end_time": "2026-10-02T14:40:18.778010+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.768821+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of errors: 21\n",
      "Iterations:[2, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28]\n"
     ]
    }
   ],
   "source": [
    "print(f\"Number of errors: {len(comp.raised_eval_errors)}\")\n",
    "print(f\"Iterations:{comp.raised_eval_errors}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fc58e90",
   "metadata": {
    "papermill": {
     "duration": 0.001925,
     "end_time": "2026-10-02T14:40:18.784743+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.782818+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Looking at the IPOPT output file (`IPOPT.out`) will reveal what happened when the optimizer encountered these bad points. Here we just show a relevant subsection of the file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7c38f0a3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.805870Z",
     "iopub.status.busy": "2026-10-02T14:40:18.805645Z",
     "iopub.status.idle": "2026-10-02T14:40:18.809124Z",
     "shell.execute_reply": "2026-10-02T14:40:18.808726Z"
    },
    "papermill": {
     "duration": 0.009802,
     "end_time": "2026-10-02T14:40:18.809859+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.800057+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls\n",
      "   0  7.4717501e+03 1.50e+01 1.52e+02   0.0 0.00e+00    -  0.00e+00 0.00e+00   0\n",
      "   1  4.2708359e+02 0.00e+00 3.76e+01   1.3 7.54e+01    -  8.53e-03 1.00e+00f  1\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   2  1.0001816e+02 0.00e+00 1.84e+01   1.1 1.52e+01    -  9.05e-01 5.00e-01f  2\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   3  4.8513633e+01 0.00e+00 1.41e+01  -0.2 8.61e+00    -  9.89e-01 2.50e-01f  3\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   4  3.2062390e+01 0.00e+00 1.24e+01  -0.9 7.18e+00    -  1.00e+00 1.25e-01f  4\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   5  1.8949488e+01 0.00e+00 1.09e+01  -2.0 6.78e+00    -  1.00e+00 1.25e-01f  4\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   6  1.3631680e+01 0.00e+00 1.02e+01  -2.2 6.24e+00    -  1.00e+00 6.25e-02f  5\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   7  8.8986042e+00 0.00e+00 9.58e+00  -2.3 6.02e+00    -  1.00e+00 6.25e-02f  5\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "   8  4.7098388e+00 0.00e+00 8.98e+00  -2.3 5.72e+00    -  1.00e+00 6.25e-02f  5\n",
      "   9 -2.7055396e+01 0.00e+00 3.56e-02  -2.4 5.41e+00    -  1.00e+00 9.96e-01f  1\n",
      "iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls\n",
      "  10 -2.7083014e+01 0.00e+00 1.63e-02  -4.2 5.58e-02    -  1.00e+00 9.65e-01f  1\n",
      "  11 -2.7083330e+01 0.00e+00 9.09e-04  -6.1 4.68e-03    -  1.00e+00 9.67e-01f  1\n",
      "  12 -2.7083333e+01 0.00e+00 3.13e-08  -8.0 2.95e-04    -  1.00e+00 1.00e+00f  1\n",
      "  13 -2.7083333e+01 0.00e+00 1.50e-11 -11.0 2.10e-08    -  1.00e+00 1.00e+00f  1\n",
      "\n",
      "Number of Iterations....: 13\n",
      "\n",
      "                                   \n"
     ]
    }
   ],
   "source": [
    "with open(prob.get_outputs_dir() / \"IPOPT.out\", encoding=\"utf-8\") as f:\n",
    "    IPOPT_history = f.read()\n",
    "beg = IPOPT_history.find(\"iter    objective\")\n",
    "end = IPOPT_history.find(\"(scaled)\", beg)\n",
    "print(IPOPT_history[beg:end])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0294c805",
   "metadata": {
    "papermill": {
     "duration": 0.00405,
     "end_time": "2026-10-02T14:40:18.817855+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.813805+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Specifically, we can see the following message when IPOPT changes its search in response to the bad point:\n",
    "\n",
    "    Warning: Cutting back alpha due to evaluation error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b8026f37",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:40:18.825824Z",
     "iopub.status.busy": "2026-10-02T14:40:18.825597Z",
     "iopub.status.idle": "2026-10-02T14:40:18.828891Z",
     "shell.execute_reply": "2026-10-02T14:40:18.828496Z"
    },
    "papermill": {
     "duration": 0.007037,
     "end_time": "2026-10-02T14:40:18.829957+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.822920+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "Warning: Cutting back alpha due to evaluation error\n",
      "\n",
      "Number of times IPOPT encountered an evaluation error: 21\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "\n",
    "for line in IPOPT_history.split('\\n'):\n",
    "    if 'Cutting back alpha' in line:\n",
    "        print(line)\n",
    "        count = count + 1\n",
    "\n",
    "print(\"\\nNumber of times IPOPT encountered an evaluation error:\", count)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d634240",
   "metadata": {
    "papermill": {
     "duration": 0.071248,
     "end_time": "2026-10-02T14:40:18.905323+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.834075+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Example using SNOPT\n",
    "\n",
    "We can exercise the same model using `SNOPT` as our optimizer, with similar results. First we will run the nominal case, and then again with the invalid region:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7aea274f",
   "metadata": {
    "papermill": {
     "duration": 0.004075,
     "end_time": "2026-10-02T14:40:18.913922+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.909847+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "In this case we can see that we raised a single AnalysisError.  We can again find evidence of SNOPT encountering this evaluation error in the `SNOPT_print.out` file, but still finding the solution. For SNOPT, we are looking for the `D` code at the end of an iteration. Here again we just show a relevant subsection of the file:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e3f5a80",
   "metadata": {
    "papermill": {
     "duration": 0.003699,
     "end_time": "2026-10-02T14:40:18.927909+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:40:18.924210+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "```{Note}\n",
    "Not all optimizers will respond as nicely to an AnalysisError as the two demonstrated here (`IPOPT` and `SNOPT`).  Some optimizers may fail to navigate around the bad region and find a solution at all.  Other may find an incorrect solution.  It is important to understand the capabilities of your chosen optimizer when working with a model that may raise an AnalysisError.\n",
    "```\n"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.14"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 17.998695,
   "end_time": "2026-10-02T14:40:19.948861+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/advanced_user_guide/analysis_errors/analysis_error.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/advanced_user_guide/analysis_errors/analysis_error.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:40:01.950166+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}