{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1a768fd8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:05.026345Z",
     "iopub.status.busy": "2026-10-02T14:42:05.026173Z",
     "iopub.status.idle": "2026-10-02T14:42:05.030168Z",
     "shell.execute_reply": "2026-10-02T14:42:05.029818Z"
    },
    "papermill": {
     "duration": 0.00765,
     "end_time": "2026-10-02T14:42:05.031083+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:05.023433+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": "3800f4a9",
   "metadata": {
    "papermill": {
     "duration": 0.001511,
     "end_time": "2026-10-02T14:42:05.041001+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:05.039490+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# ScipyOptimizeDriver\n",
    "\n",
    "ScipyOptimizeDriver wraps the optimizers in *scipy.optimize.minimize*. In this example, we use the SLSQP optimizer to find the minimum of the Paraboloid problem."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4465b5eb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:05.045100Z",
     "iopub.status.busy": "2026-10-02T14:42:05.044945Z",
     "iopub.status.idle": "2026-10-02T14:42:07.679125Z",
     "shell.execute_reply": "2026-10-02T14:42:07.678175Z"
    },
    "papermill": {
     "duration": 2.636937,
     "end_time": "2026-10-02T14:42:07.679797+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:05.042860+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<span class=\"sd\">    &quot;&quot;&quot;</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=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">setup_partials</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\">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\n<span class=\"sd\">        Optimal solution (minimum): x = 6.6667; y = -7.3333</span>\n<span class=\"sd\">        &quot;&quot;&quot;</span>\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\">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=\"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\">        Jacobian for our paraboloid.</span>\n<span class=\"sd\">        &quot;&quot;&quot;</span>\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</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\\PY{l+s+sd}{    \\PYZdq{}\\PYZdq{}\\PYZdq{}}\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{k}{def}\\PY{+w}{ }\\PY{n+nf}{setup\\PYZus{}partials}\\PY{p}{(}\\PY{n+nb+bp}{self}\\PY{p}{)}\\PY{p}{:}\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\n\\PY{l+s+sd}{        Optimal solution (minimum): x = 6.6667; y = \\PYZhy{}7.3333}\n\\PY{l+s+sd}{        \\PYZdq{}\\PYZdq{}\\PYZdq{}}\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}{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{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}{        Jacobian for our paraboloid.}\n\\PY{l+s+sd}{        \\PYZdq{}\\PYZdq{}\\PYZdq{}}\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\\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\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    def setup_partials(self):\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        Optimal solution (minimum): x = 6.6667; y = -7.3333\n        \"\"\"\n        x = inputs['x']\n        y = inputs['y']\n\n        outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0\n\n    def compute_partials(self, inputs, partials):\n        \"\"\"\n        Jacobian for our paraboloid.\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"
     },
     "metadata": {
      "scrapbook": {
       "mime_prefix": "application/papermill.record/",
       "name": "code_src019"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from openmdao.utils.notebook_utils import get_code\n",
    "from myst_nb import glue\n",
    "glue(\"code_src019\", get_code(\"openmdao.test_suite.components.paraboloid.Paraboloid\"), display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfe5e8bb",
   "metadata": {
    "papermill": {
     "duration": 0.002166,
     "end_time": "2026-10-02T14:42:07.684408+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:07.682242+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    ":::{dropdown} `Paraboloid` class definition \n",
    "\n",
    "{glue:}`code_src019`\n",
    ":::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e99f06bc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:07.689566Z",
     "iopub.status.busy": "2026-10-02T14:42:07.689401Z",
     "iopub.status.idle": "2026-10-02T14:42:08.970016Z",
     "shell.execute_reply": "2026-10-02T14:42:08.969395Z"
    },
    "papermill": {
     "duration": 1.283943,
     "end_time": "2026-10-02T14:42:08.970446+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:07.686503+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952128.922825] [runnervm8df0l:6967 :0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x555a76495df0 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",
      "[1790952128.923072] [runnervm8df0l:6967 :0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimization terminated successfully    (Exit mode 0)\n",
      "            Current function value: -27.33333333333333\n",
      "            Iterations: 3\n",
      "            Function evaluations: 4\n",
      "            Gradient evaluations: 3\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[runnervm8df0l:06967] pml_ucx.c:313  Error: Failed to create UCP worker\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Problem: problem\n",
       "Driver:  ScipyOptimizeDriver\n",
       "  success     : True\n",
       "  iterations  : 5\n",
       "  runtime     : 3.2382E-02 s\n",
       "  model_evals : 5\n",
       "  model_time  : 4.0902E-04 s\n",
       "  deriv_evals : 3\n",
       "  deriv_time  : 2.8207E-02 s\n",
       "  exit_status : SUCCESS"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "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",
    "model.add_subsystem('comp', Paraboloid(), promotes=['*'])\n",
    "\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "prob.driver.options['tol'] = 1e-9\n",
    "prob.driver.options['disp'] = True\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",
    "model.add_objective('f_xy')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('x', 50.0)\n",
    "prob.set_val('y', 50.0)\n",
    "\n",
    "prob.run_driver()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2dede65b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:08.974795Z",
     "iopub.status.busy": "2026-10-02T14:42:08.974496Z",
     "iopub.status.idle": "2026-10-02T14:42:08.977835Z",
     "shell.execute_reply": "2026-10-02T14:42:08.977008Z"
    },
    "papermill": {
     "duration": 0.006109,
     "end_time": "2026-10-02T14:42:08.978302+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:08.972193+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.66666667]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('x'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "873e6248",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:08.984276Z",
     "iopub.status.busy": "2026-10-02T14:42:08.984114Z",
     "iopub.status.idle": "2026-10-02T14:42:08.988008Z",
     "shell.execute_reply": "2026-10-02T14:42:08.987453Z"
    },
    "papermill": {
     "duration": 0.008793,
     "end_time": "2026-10-02T14:42:08.988783+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:08.979990+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-7.33333333]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bdd53dec",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:08.994632Z",
     "iopub.status.busy": "2026-10-02T14:42:08.994228Z",
     "iopub.status.idle": "2026-10-02T14:42:08.998829Z",
     "shell.execute_reply": "2026-10-02T14:42:08.997942Z"
    },
    "papermill": {
     "duration": 0.008455,
     "end_time": "2026-10-02T14:42:08.999372+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:08.990917+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.5454546999778205e-09)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "assert_near_equal(prob.get_val('x'), 6.66666667, 1e-6)\n",
    "assert_near_equal(prob.get_val('y'), -7.3333333, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06f35dd5",
   "metadata": {
    "papermill": {
     "duration": 0.001794,
     "end_time": "2026-10-02T14:42:09.003114+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.001320+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## ScipyOptimizeDriver Options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7a4e6500",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.008218Z",
     "iopub.status.busy": "2026-10-02T14:42:09.008057Z",
     "iopub.status.idle": "2026-10-02T14:42:09.011298Z",
     "shell.execute_reply": "2026-10-02T14:42:09.010765Z"
    },
    "papermill": {
     "duration": 0.006684,
     "end_time": "2026-10-02T14:42:09.011865+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.005181+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<!DOCTYPE html>\n",
       "<html lang=\"en\">\n",
       "<head>\n",
       "    <style>\n",
       "        h2 {\n",
       "            text-align: center;\n",
       "        }\n",
       "    </style>\n",
       "</head>\n",
       "<body>\n",
       "    <h2></h2>\n",
       "        <table style=\"border: 1px solid #999; border-collapse: collapse;\">\n",
       "        <tr><th style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; background-color: #E9E9E9; text-align: left;\">Option</th><th style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; background-color: #E9E9E9; text-align: left;\">Default</th><th style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; background-color: #E9E9E9; text-align: left;\">Acceptable Values</th><th style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; background-color: #E9E9E9; text-align: left;\">Acceptable Types</th><th style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; background-color: #E9E9E9; text-align: left;\">Description</th></tr>\n",
       "       <tr style=\"background-color: ghostwhite;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">debug_print</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;desvars&#x27;, &#x27;nl_cons&#x27;, &#x27;ln_cons&#x27;, &#x27;objs&#x27;, &#x27;totals&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;list&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">List of what type of Driver variables to print at each iteration.</td></tr>\n",
       "       <tr style=\"background-color: #F3F3F3;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">disp</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">True</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;int&#x27;, &#x27;bool&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Value of &quot;disp&quot; argument provided to scipy.optimize.minimize which controls the verbosity of the optimization.</td></tr>\n",
       "       <tr style=\"background-color: ghostwhite;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">invalid_desvar_behavior</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">warn</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;warn&#x27;, &#x27;raise&#x27;, &#x27;ignore&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Behavior of driver if the initial value of a design variable exceeds its bounds. The default value may beset using the `OPENMDAO_INVALID_DESVAR_BEHAVIOR` environment variable to one of the valid options.</td></tr>\n",
       "       <tr style=\"background-color: #F3F3F3;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">maxiter</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">200</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Maximum number of iterations.</td></tr>\n",
       "       <tr style=\"background-color: ghostwhite;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">optimizer</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">SLSQP</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;Newton-CG&#x27;, &#x27;dual_annealing&#x27;, &#x27;L-BFGS-B&#x27;, &#x27;CG&#x27;, &#x27;BFGS&#x27;, &#x27;shgo&#x27;, &#x27;trust-constr&#x27;, &#x27;basinhopping&#x27;, &#x27;differential_evolution&#x27;, &#x27;Powell&#x27;, &#x27;COBYQA&#x27;, &#x27;Nelder-Mead&#x27;, &#x27;COBYLA&#x27;, &#x27;SLSQP&#x27;, &#x27;TNC&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Name of optimizer to use</td></tr>\n",
       "       <tr style=\"background-color: #F3F3F3;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">singular_jac_behavior</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">warn</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">[&#x27;error&#x27;, &#x27;warn&#x27;, &#x27;ignore&#x27;]</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Defines behavior of a zero row/col check after first call tocompute_totals:error - raise an error.warn - raise a warning.ignore - don&#x27;t perform check.</td></tr>\n",
       "       <tr style=\"background-color: ghostwhite;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">singular_jac_tol</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">1e-16</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Tolerance for zero row/column check.</td></tr>\n",
       "       <tr style=\"background-color: #F3F3F3;\"><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">tol</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">1e-06</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">N/A</td><td style=\"border: 1px solid #999; border-collapse: collapse; padding: 5px; text-align: left;\">Tolerance for termination. For detailed control, use solver-specific options.</td></tr>\n",
       "    </table>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "om.show_options_table(\"openmdao.drivers.scipy_optimizer.ScipyOptimizeDriver\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eebe2836",
   "metadata": {
    "papermill": {
     "duration": 0.001866,
     "end_time": "2026-10-02T14:42:09.015429+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.013563+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## ScipyOptimizeDriver Constructor\n",
    "\n",
    "The call signature for the *ScipyOptimizeDriver* constructor is:\n",
    "\n",
    "```{eval-rst}\n",
    "    .. automethod:: openmdao.drivers.scipy_optimizer.ScipyOptimizeDriver.__init__\n",
    "        :noindex:\n",
    "```\n",
    "\n",
    "## ScipyOptimizeDriver Option Examples\n",
    "\n",
    "**optimizer**\n",
    "\n",
    "    The “optimizer” option lets you choose which optimizer to use. ScipyOptimizeDriver supports all of the optimizers in scipy.optimize except for ‘dogleg’ and ‘trust-ncg’. Generally, the optimizers that you are most likely to use are “COBYLA” and “SLSQP”, as these are the only ones that support constraints. Only SLSQP supports equality constraints. SLSQP also uses gradients provided by OpenMDAO, while COBYLA is gradient-free. Also, SLSQP supports both equality and inequality constraints, but COBYLA only supports inequality constraints.\n",
    "\n",
    "    Here we pass the optimizer option as a keyword argument."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a9cbd36d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.020221Z",
     "iopub.status.busy": "2026-10-02T14:42:09.020088Z",
     "iopub.status.idle": "2026-10-02T14:42:09.124995Z",
     "shell.execute_reply": "2026-10-02T14:42:09.124429Z"
    },
    "papermill": {
     "duration": 0.108279,
     "end_time": "2026-10-02T14:42:09.125678+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.017399+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Return from COBYLA because the trust region radius reaches its lower bound.\n",
      "Number of function values = 76   Least value of F = -27.333333333332494   Constraint violation = 0.0\n",
      "The corresponding X is: [ 6.66666772 -7.33333381]\n",
      "The constraint value is:\n",
      "[-56.66666772 -42.66666619 -43.33333228 -57.33333381]\n",
      "\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Problem: problem2\n",
       "Driver:  ScipyOptimizeDriver\n",
       "  success     : True\n",
       "  iterations  : 77\n",
       "  runtime     : 9.8107E-02 s\n",
       "  model_evals : 77\n",
       "  model_time  : 5.3630E-03 s\n",
       "  deriv_evals : 0\n",
       "  deriv_time  : 0.0000E+00 s\n",
       "  exit_status : SUCCESS"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "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",
    "model.add_subsystem('comp', Paraboloid(), promotes=['*'])\n",
    "\n",
    "prob.driver = om.ScipyOptimizeDriver(optimizer='COBYLA')\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",
    "model.add_objective('f_xy')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('x', 50.0)\n",
    "prob.set_val('y', 50.0)\n",
    "\n",
    "prob.run_driver()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "99411d55",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.131775Z",
     "iopub.status.busy": "2026-10-02T14:42:09.131561Z",
     "iopub.status.idle": "2026-10-02T14:42:09.135250Z",
     "shell.execute_reply": "2026-10-02T14:42:09.134378Z"
    },
    "papermill": {
     "duration": 0.007489,
     "end_time": "2026-10-02T14:42:09.135873+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.128384+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.66666826]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('x'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e0abbfc1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.163723Z",
     "iopub.status.busy": "2026-10-02T14:42:09.163521Z",
     "iopub.status.idle": "2026-10-02T14:42:09.167004Z",
     "shell.execute_reply": "2026-10-02T14:42:09.165782Z"
    },
    "papermill": {
     "duration": 0.007444,
     "end_time": "2026-10-02T14:42:09.167680+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.160236+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-7.33333297]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bf838a0d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.172866Z",
     "iopub.status.busy": "2026-10-02T14:42:09.172718Z",
     "iopub.status.idle": "2026-10-02T14:42:09.176439Z",
     "shell.execute_reply": "2026-10-02T14:42:09.175826Z"
    },
    "papermill": {
     "duration": 0.007216,
     "end_time": "2026-10-02T14:42:09.176904+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.169688+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.497040832902862e-08)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assert_near_equal(prob.get_val('x'), 6.66666667, 1e-6)\n",
    "assert_near_equal(prob.get_val('y'), -7.3333333, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ddbc78b",
   "metadata": {
    "papermill": {
     "duration": 0.002184,
     "end_time": "2026-10-02T14:42:09.181094+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.178910+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**maxiter**\n",
    "\n",
    "    The “maxiter” option is used to specify the maximum number of major iterations before termination. It is generally a valid option across all of the available options."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d78d466a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.186113Z",
     "iopub.status.busy": "2026-10-02T14:42:09.185940Z",
     "iopub.status.idle": "2026-10-02T14:42:09.196651Z",
     "shell.execute_reply": "2026-10-02T14:42:09.195981Z"
    },
    "papermill": {
     "duration": 0.013893,
     "end_time": "2026-10-02T14:42:09.197106+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.183213+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimization terminated successfully    (Exit mode 0)\n",
      "            Current function value: -27.33333333333333\n",
      "            Iterations: 3\n",
      "            Function evaluations: 4\n",
      "            Gradient evaluations: 3\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Problem: problem3\n",
       "Driver:  ScipyOptimizeDriver\n",
       "  success     : True\n",
       "  iterations  : 5\n",
       "  runtime     : 3.3083E-03 s\n",
       "  model_evals : 5\n",
       "  model_time  : 3.3350E-04 s\n",
       "  deriv_evals : 3\n",
       "  deriv_time  : 9.7861E-04 s\n",
       "  exit_status : SUCCESS"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "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",
    "model.add_subsystem('comp', Paraboloid(), promotes=['*'])\n",
    "\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['maxiter'] = 20\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",
    "model.add_objective('f_xy')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('x', 50.0)\n",
    "prob.set_val('y', 50.0)\n",
    "\n",
    "prob.run_driver()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6760534a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.202049Z",
     "iopub.status.busy": "2026-10-02T14:42:09.201895Z",
     "iopub.status.idle": "2026-10-02T14:42:09.204622Z",
     "shell.execute_reply": "2026-10-02T14:42:09.204060Z"
    },
    "papermill": {
     "duration": 0.005981,
     "end_time": "2026-10-02T14:42:09.205077+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.199096+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.66666667]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('x'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "372afb33",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.253546Z",
     "iopub.status.busy": "2026-10-02T14:42:09.253386Z",
     "iopub.status.idle": "2026-10-02T14:42:09.256194Z",
     "shell.execute_reply": "2026-10-02T14:42:09.255385Z"
    },
    "papermill": {
     "duration": 0.006775,
     "end_time": "2026-10-02T14:42:09.256622+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.249847+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-7.33333333]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "91e808fc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.272581Z",
     "iopub.status.busy": "2026-10-02T14:42:09.272406Z",
     "iopub.status.idle": "2026-10-02T14:42:09.275821Z",
     "shell.execute_reply": "2026-10-02T14:42:09.275178Z"
    },
    "papermill": {
     "duration": 0.017751,
     "end_time": "2026-10-02T14:42:09.276512+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.258761+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.5454546999778205e-09)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assert_near_equal(prob.get_val('x'), 6.66666667, 1e-6)\n",
    "assert_near_equal(prob.get_val('y'), -7.3333333, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16c3a0a8",
   "metadata": {
    "papermill": {
     "duration": 0.098066,
     "end_time": "2026-10-02T14:42:09.376491+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.278425+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**tol**\n",
    "\n",
    "    The “tol” option allows you to specify the tolerance for termination."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f92f626a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.386444Z",
     "iopub.status.busy": "2026-10-02T14:42:09.386284Z",
     "iopub.status.idle": "2026-10-02T14:42:09.398146Z",
     "shell.execute_reply": "2026-10-02T14:42:09.397274Z"
    },
    "papermill": {
     "duration": 0.020236,
     "end_time": "2026-10-02T14:42:09.398772+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.378536+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimization terminated successfully    (Exit mode 0)\n",
      "            Current function value: -27.33333333333333\n",
      "            Iterations: 3\n",
      "            Function evaluations: 4\n",
      "            Gradient evaluations: 3\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Problem: problem4\n",
       "Driver:  ScipyOptimizeDriver\n",
       "  success     : True\n",
       "  iterations  : 5\n",
       "  runtime     : 4.5153E-03 s\n",
       "  model_evals : 5\n",
       "  model_time  : 3.5368E-04 s\n",
       "  deriv_evals : 3\n",
       "  deriv_time  : 1.0216E-03 s\n",
       "  exit_status : SUCCESS"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "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",
    "model.add_subsystem('comp', Paraboloid(), promotes=['*'])\n",
    "\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['tol'] = 1.0e-9\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",
    "model.add_objective('f_xy')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('x', 50.0)\n",
    "prob.set_val('y', 50.0)\n",
    "\n",
    "prob.run_driver()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4be05434",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.462414Z",
     "iopub.status.busy": "2026-10-02T14:42:09.462246Z",
     "iopub.status.idle": "2026-10-02T14:42:09.465225Z",
     "shell.execute_reply": "2026-10-02T14:42:09.464431Z"
    },
    "papermill": {
     "duration": 0.06437,
     "end_time": "2026-10-02T14:42:09.465943+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.401573+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.66666667]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('x'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "74abb004",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.472724Z",
     "iopub.status.busy": "2026-10-02T14:42:09.472549Z",
     "iopub.status.idle": "2026-10-02T14:42:09.475334Z",
     "shell.execute_reply": "2026-10-02T14:42:09.474855Z"
    },
    "papermill": {
     "duration": 0.006794,
     "end_time": "2026-10-02T14:42:09.475924+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.469130+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-7.33333333]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d9701822",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.527173Z",
     "iopub.status.busy": "2026-10-02T14:42:09.526973Z",
     "iopub.status.idle": "2026-10-02T14:42:09.530386Z",
     "shell.execute_reply": "2026-10-02T14:42:09.529786Z"
    },
    "papermill": {
     "duration": 0.052147,
     "end_time": "2026-10-02T14:42:09.530955+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.478808+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.5454546999778205e-09)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assert_near_equal(prob.get_val('x'), 6.66666667, 1e-6)\n",
    "assert_near_equal(prob.get_val('y'), -7.3333333, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee5a5ef7",
   "metadata": {
    "papermill": {
     "duration": 0.002724,
     "end_time": "2026-10-02T14:42:09.536584+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.533860+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## ScipyOptimizeDriver Driver Specific Options\n",
    "\n",
    "Optimizers in *scipy.optimize.minimize* have optimizer specific options. To let the user specify values for these options, OpenMDAO provides an option in the form of a dictionary named *opt_settings*. See the *scipy.optimize.minimize* documentation for more information about the driver specific options that are available.\n",
    "\n",
    "As an example, here is code using some *opt_settings* for the shgo optimizer:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ec17e3b9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.543262Z",
     "iopub.status.busy": "2026-10-02T14:42:09.543077Z",
     "iopub.status.idle": "2026-10-02T14:42:09.579365Z",
     "shell.execute_reply": "2026-10-02T14:42:09.578808Z"
    },
    "papermill": {
     "duration": 0.040527,
     "end_time": "2026-10-02T14:42:09.579813+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.539286+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/runner/work/OpenMDAO/OpenMDAO/.pixi/envs/dev/lib/python3.13/site-packages/openmdao/core/total_jac.py:1925: DerivativesWarning:The following constraints or objectives cannot be impacted by the design variables of the problem at the current design point:\n",
      "  f, inds=[0]\n",
      "\n",
      "/home/runner/work/OpenMDAO/OpenMDAO/.pixi/envs/dev/lib/python3.13/site-packages/openmdao/core/total_jac.py:1953: DerivativesWarning:The following design variables have no impact on the constraints or objective at the current design point:\n",
      "  x, inds=[0, 1, 2]\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Problem: problem5\n",
       "Driver:  ScipyOptimizeDriver\n",
       "  success     : True\n",
       "  iterations  : 50\n",
       "  runtime     : 2.6623E-02 s\n",
       "  model_evals : 50\n",
       "  model_time  : 3.3714E-03 s\n",
       "  deriv_evals : 15\n",
       "  deriv_time  : 4.5907E-03 s\n",
       "  exit_status : SUCCESS"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Source of example: https://stefan-endres.github.io/shgo/\n",
    "\n",
    "import numpy as np\n",
    "import openmdao.api as om\n",
    "\n",
    "size = 3  # size of the design variable\n",
    "\n",
    "def rastrigin(x):\n",
    "    a = 10  # constant\n",
    "    return np.sum(np.square(x) - a * np.cos(2 * np.pi * x)) + a * np.size(x)\n",
    "\n",
    "class Rastrigin(om.ExplicitComponent):\n",
    "\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(size))\n",
    "        self.add_output('f', 0.0)\n",
    "        \n",
    "        self.declare_partials(of='f', wrt='x', method='cs')\n",
    "\n",
    "    def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):\n",
    "        x = inputs['x']\n",
    "        outputs['f'] = rastrigin(x)\n",
    "\n",
    "prob = om.Problem()\n",
    "model = prob.model\n",
    "\n",
    "model.add_subsystem('rastrigin', Rastrigin(), promotes=['*'])\n",
    "\n",
    "prob.driver = driver = om.ScipyOptimizeDriver()\n",
    "driver.options['optimizer'] = 'shgo'\n",
    "driver.options['disp'] = False\n",
    "driver.opt_settings['maxtime'] = 10  # seconds\n",
    "driver.opt_settings['iters'] = 3\n",
    "driver.opt_settings['maxiter'] = None\n",
    "\n",
    "model.add_design_var('x', lower=-5.12*np.ones(size), upper=5.12*np.ones(size))\n",
    "model.add_objective('f')\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('x', 2*np.ones(size))\n",
    "prob.run_driver()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "32cd13f6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.585349Z",
     "iopub.status.busy": "2026-10-02T14:42:09.585195Z",
     "iopub.status.idle": "2026-10-02T14:42:09.587976Z",
     "shell.execute_reply": "2026-10-02T14:42:09.587442Z"
    },
    "papermill": {
     "duration": 0.006413,
     "end_time": "2026-10-02T14:42:09.588504+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.582091+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0. 0.]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('x'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8c7c6fbc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.593502Z",
     "iopub.status.busy": "2026-10-02T14:42:09.593369Z",
     "iopub.status.idle": "2026-10-02T14:42:09.596361Z",
     "shell.execute_reply": "2026-10-02T14:42:09.595805Z"
    },
    "papermill": {
     "duration": 0.006388,
     "end_time": "2026-10-02T14:42:09.596985+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.590597+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.]\n"
     ]
    }
   ],
   "source": [
    "print(prob.get_val('f'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "418215be",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:42:09.602762Z",
     "iopub.status.busy": "2026-10-02T14:42:09.602596Z",
     "iopub.status.idle": "2026-10-02T14:42:09.605998Z",
     "shell.execute_reply": "2026-10-02T14:42:09.605030Z"
    },
    "papermill": {
     "duration": 0.007097,
     "end_time": "2026-10-02T14:42:09.606497+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.599400+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.0)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assert_near_equal(prob.get_val('x'), np.zeros(size), 1e-6)\n",
    "assert_near_equal(prob.get_val('f'), 0.0, 1e-6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31496522",
   "metadata": {
    "papermill": {
     "duration": 0.030906,
     "end_time": "2026-10-02T14:42:09.639868+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:42:09.608962+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Notice that when using the shgo optimizer, setting the *opt_settings[‘maxiter’]* to None overrides *ScipyOptimizeDriver*’s *options[‘maxiter’]* value. It is not possible to set *options[‘maxiter’]* to anything other than an integer so the *opt_settings[‘maxiter’]* option provides a way to set the maxiter value for the shgo optimizer to None."
   ]
  }
 ],
 "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.13.14"
  },
  "orphan": true,
  "papermill": {
   "default_parameters": {},
   "duration": 6.264803,
   "end_time": "2026-10-02T14:42:10.458871+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/features/building_blocks/drivers/scipy_optimize_driver.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/features/building_blocks/drivers/scipy_optimize_driver.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:42:04.194068+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}