{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "99ec1c06",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:43:02.562499Z",
     "iopub.status.busy": "2026-10-02T14:43:02.562247Z",
     "iopub.status.idle": "2026-10-02T14:43:02.567072Z",
     "shell.execute_reply": "2026-10-02T14:43:02.566441Z"
    },
    "papermill": {
     "duration": 0.007229,
     "end_time": "2026-10-02T14:43:02.567564+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:43:02.560335+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": "b9eeb600",
   "metadata": {
    "papermill": {
     "duration": 0.000806,
     "end_time": "2026-10-02T14:43:02.569267+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:43:02.568461+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# ResponseSurface\n",
    "\n",
    "Surrogate Model based on second order response surface equations.\n",
    "\n",
    "Here is a simple example where the *ResponseSurface* surrogate is used to approximate the output of a sinusoidal component."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "04fcf54a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:43:02.571472Z",
     "iopub.status.busy": "2026-10-02T14:43:02.571338Z",
     "iopub.status.idle": "2026-10-02T14:43:05.006518Z",
     "shell.execute_reply": "2026-10-02T14:43:05.005723Z"
    },
    "papermill": {
     "duration": 2.437119,
     "end_time": "2026-10-02T14:43:05.007183+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:43:02.570064+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952184.991726] [runnervm8df0l:7494 :0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x5610f08d3800 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",
      "[1790952184.992000] [runnervm8df0l:7494 :0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n",
      "[0.43075734]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[runnervm8df0l:07494] pml_ucx.c:313  Error: Failed to create UCP worker\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "sin_mm = om.MetaModelUnStructuredComp()\n",
    "sin_mm.add_input('x', 2.1)\n",
    "sin_mm.add_output('f_x', 0., surrogate=om.ResponseSurface())\n",
    "\n",
    "prob.model.add_subsystem('sin_mm', sin_mm)\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "# train the surrogate and check predicted value\n",
    "sin_mm.options['train_x'] = np.linspace(0, 3.14, 20)\n",
    "sin_mm.options['train_f_x'] = .5*np.sin(sin_mm.options['train_x'])\n",
    "\n",
    "prob.set_val('sin_mm.x', 2.1)\n",
    "\n",
    "prob.run_model()\n",
    "\n",
    "print(prob.get_val('sin_mm.f_x'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9242db14",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:43:05.010786Z",
     "iopub.status.busy": "2026-10-02T14:43:05.010407Z",
     "iopub.status.idle": "2026-10-02T14:43:05.017842Z",
     "shell.execute_reply": "2026-10-02T14:43:05.016390Z"
    },
    "papermill": {
     "duration": 0.00991,
     "end_time": "2026-10-02T14:43:05.018424+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:43:05.008514+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.0019632419022928777)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "assert_near_equal(prob.get_val('sin_mm.f_x'), .5*np.sin(prob.get_val('sin_mm.x')), 2e-3)"
   ]
  }
 ],
 "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": 3.63804,
   "end_time": "2026-10-02T14:43:05.536325+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/features/building_blocks/surrogates/responsesurface.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/features/building_blocks/surrogates/responsesurface.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:43:01.898285+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}