{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "44aaf7a7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:23.293913Z",
     "iopub.status.busy": "2026-10-02T14:50:23.293667Z",
     "iopub.status.idle": "2026-10-02T14:50:23.297858Z",
     "shell.execute_reply": "2026-10-02T14:50:23.297228Z"
    },
    "hide_input": true,
    "papermill": {
     "duration": 0.007481,
     "end_time": "2026-10-02T14:50:23.298351+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:23.290870+00:00",
     "status": "completed"
    },
    "tags": [
     "active-ipynb",
     "remove-input",
     "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": "9a545301",
   "metadata": {
    "papermill": {
     "duration": 0.001279,
     "end_time": "2026-10-02T14:50:23.301288+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:23.300009+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Conversion Guide for the Auto-IVC (IndepVarComp) Feature\n",
    "As of the OpenMDAO 3.2 release, it is no longer necessary to add an IndepVarComp to your model to handle the assignment of unconnected inputs as design variables."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28d641e8",
   "metadata": {
    "papermill": {
     "duration": 0.001192,
     "end_time": "2026-10-02T14:50:23.303878+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:23.302686+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Declaring Design Variables\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "This is what we used to do\n",
    "```\n",
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.x', 'paraboloid.x')\n",
    "prob.model.connect('indeps.y', 'paraboloid.y')\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('indeps.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('indeps.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver()\n",
    "```\n",
    "````\n",
    "````{tab-item} With Auto IVC\n",
    "This is how we handle IVCs now\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob['x'] = 3.0\n",
    "prob['y'] = -4.0\n",
    "\n",
    "prob.run_driver()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e7808729",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:23.307519Z",
     "iopub.status.busy": "2026-10-02T14:50:23.307356Z",
     "iopub.status.idle": "2026-10-02T14:50:25.642241Z",
     "shell.execute_reply": "2026-10-02T14:50:25.641559Z"
    },
    "papermill": {
     "duration": 2.337692,
     "end_time": "2026-10-02T14:50:25.642801+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:23.305109+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952625.600734] [runnervm8df0l:11984:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x55e0d4777470 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",
      "[1790952625.601026] [runnervm8df0l:11984: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: 5\n",
      "            Function evaluations: 6\n",
      "            Gradient evaluations: 5\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[runnervm8df0l:11984] pml_ucx.c:313  Error: Failed to create UCP worker\n"
     ]
    }
   ],
   "source": [
    "# Old way\n",
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.x', 'paraboloid.x')\n",
    "prob.model.connect('indeps.y', 'paraboloid.y')\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('indeps.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('indeps.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3070b662",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.646860Z",
     "iopub.status.busy": "2026-10-02T14:50:25.646589Z",
     "iopub.status.idle": "2026-10-02T14:50:25.656916Z",
     "shell.execute_reply": "2026-10-02T14:50:25.656328Z"
    },
    "papermill": {
     "duration": 0.012949,
     "end_time": "2026-10-02T14:50:25.657389+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.644440+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimization terminated successfully    (Exit mode 0)\n",
      "            Current function value: -27.33333333333333\n",
      "            Iterations: 5\n",
      "            Function evaluations: 6\n",
      "            Gradient evaluations: 5\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    }
   ],
   "source": [
    "# New way\n",
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob['x'] = 3.0\n",
    "prob['y'] = -4.0\n",
    "\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed25707f",
   "metadata": {
    "papermill": {
     "duration": 0.038589,
     "end_time": "2026-10-02T14:50:25.697488+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.658899+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Declaring a Multi-Component Input as a Design Variable\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('parab', Paraboloid())\n",
    "\n",
    "# define the component whose output will be constrained\n",
    "prob.model.add_subsystem('const', om.ExecComp('g = x + y'))\n",
    "\n",
    "prob.model.connect('indeps.x', ['parab.x', 'const.x'])\n",
    "prob.model.connect('indeps.y', ['parab.y', 'const.y'])\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'COBYLA'\n",
    "\n",
    "prob.model.add_design_var('indeps.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('indeps.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('parab.f_xy')\n",
    "\n",
    "# to add the constraint to the model\n",
    "prob.model.add_constraint('const.g', lower=0, upper=10.)\n",
    "# prob.model.add_constraint('const.g', equals=0.)\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver()\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "prob.model.add_subsystem('parab', Paraboloid(),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# define the component whose output will be constrained\n",
    "prob.model.add_subsystem('const', om.ExecComp('g = x + y'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# Design variables 'x' and 'y' span components, so we need to provide a common initial\n",
    "# value for them.\n",
    "prob.model.set_input_defaults('x', 3.0)\n",
    "prob.model.set_input_defaults('y', -4.0)\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'COBYLA'\n",
    "\n",
    "prob.model.add_design_var('x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('y', lower=-50, upper=50)\n",
    "prob.model.add_objective('parab.f_xy')\n",
    "\n",
    "# to add the constraint to the model\n",
    "prob.model.add_constraint('const.g', lower=0, upper=10.)\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1daebccc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.701469Z",
     "iopub.status.busy": "2026-10-02T14:50:25.701309Z",
     "iopub.status.idle": "2026-10-02T14:50:25.774804Z",
     "shell.execute_reply": "2026-10-02T14:50:25.774194Z"
    },
    "papermill": {
     "duration": 0.076235,
     "end_time": "2026-10-02T14:50:25.775311+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.699076+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Return from COBYLA because the trust region radius reaches its lower bound.\n",
      "Number of function values = 44   Least value of F = -26.99999999999995   Constraint violation = 0.0\n",
      "The corresponding X is: [ 7.00000022 -7.00000022]\n",
      "The constraint value is:\n",
      "[-57.00000022 -42.99999978 -42.99999978 -57.00000022   0.\n",
      " -10.        ]\n",
      "\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    }
   ],
   "source": [
    "import openmdao.api as om\n",
    "from openmdao.test_suite.components.paraboloid import Paraboloid\n",
    "\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('parab', Paraboloid())\n",
    "\n",
    "# define the component whose output will be constrained\n",
    "prob.model.add_subsystem('const', om.ExecComp('g = x + y'))\n",
    "\n",
    "prob.model.connect('indeps.x', ['parab.x', 'const.x'])\n",
    "prob.model.connect('indeps.y', ['parab.y', 'const.y'])\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'COBYLA'\n",
    "\n",
    "prob.model.add_design_var('indeps.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('indeps.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('parab.f_xy')\n",
    "\n",
    "# to add the constraint to the model\n",
    "prob.model.add_constraint('const.g', lower=0, upper=10.)\n",
    "# prob.model.add_constraint('const.g', equals=0.)\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27a4f7c2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.779419Z",
     "iopub.status.busy": "2026-10-02T14:50:25.779259Z",
     "iopub.status.idle": "2026-10-02T14:50:25.838847Z",
     "shell.execute_reply": "2026-10-02T14:50:25.838206Z"
    },
    "papermill": {
     "duration": 0.06232,
     "end_time": "2026-10-02T14:50:25.839478+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.777158+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Return from COBYLA because the trust region radius reaches its lower bound.\n",
      "Number of function values = 44   Least value of F = -26.99999999999995   Constraint violation = 0.0\n",
      "The corresponding X is: [ 7.00000022 -7.00000022]\n",
      "The constraint value is:\n",
      "[-57.00000022 -42.99999978 -42.99999978 -57.00000022   0.\n",
      " -10.        ]\n",
      "\n",
      "Optimization Complete\n",
      "-----------------------------------\n"
     ]
    }
   ],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "prob.model.add_subsystem('parab', Paraboloid(),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# define the component whose output will be constrained\n",
    "prob.model.add_subsystem('const', om.ExecComp('g = x + y'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "# Design variables 'x' and 'y' span components, so we need to provide a common initial\n",
    "# value for them.\n",
    "prob.model.set_input_defaults('x', 3.0)\n",
    "prob.model.set_input_defaults('y', -4.0)\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'COBYLA'\n",
    "\n",
    "prob.model.add_design_var('x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('y', lower=-50, upper=50)\n",
    "prob.model.add_objective('parab.f_xy')\n",
    "\n",
    "# to add the constraint to the model\n",
    "prob.model.add_constraint('const.g', lower=0, upper=10.)\n",
    "\n",
    "prob.setup()\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7850b6db",
   "metadata": {
    "papermill": {
     "duration": 0.001419,
     "end_time": "2026-10-02T14:50:25.842527+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.841108+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Declaring a New Name for a Promoted Input\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('width', 3.0)\n",
    "indeps.add_output('length', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                       om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.width', 'paraboloid.x')\n",
    "prob.model.connect('indeps.length', 'paraboloid.y')\n",
    "\n",
    "prob.setup()\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=[('x', 'width'), ('y', 'length')])\n",
    "\n",
    "# Could also set these after setup.\n",
    "prob.model.set_input_defaults('width', 3.0)\n",
    "prob.model.set_input_defaults('length', -4.0)\n",
    "\n",
    "prob.setup()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b78ed32d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.930040Z",
     "iopub.status.busy": "2026-10-02T14:50:25.929853Z",
     "iopub.status.idle": "2026-10-02T14:50:25.935037Z",
     "shell.execute_reply": "2026-10-02T14:50:25.934152Z"
    },
    "papermill": {
     "duration": 0.009176,
     "end_time": "2026-10-02T14:50:25.935472+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.926296+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('width', 3.0)\n",
    "indeps.add_output('length', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                       om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.width', 'paraboloid.x')\n",
    "prob.model.connect('indeps.length', 'paraboloid.y')\n",
    "\n",
    "prob.setup();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d620621b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.940852Z",
     "iopub.status.busy": "2026-10-02T14:50:25.940665Z",
     "iopub.status.idle": "2026-10-02T14:50:25.944897Z",
     "shell.execute_reply": "2026-10-02T14:50:25.944306Z"
    },
    "papermill": {
     "duration": 0.00821,
     "end_time": "2026-10-02T14:50:25.945294+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.937084+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=[('x', 'width'), ('y', 'length')])\n",
    "\n",
    "# Could also set these after setup.\n",
    "prob.model.set_input_defaults('width', 3.0)\n",
    "prob.model.set_input_defaults('length', -4.0)\n",
    "\n",
    "prob.setup();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab6a60f2",
   "metadata": {
    "papermill": {
     "duration": 0.001467,
     "end_time": "2026-10-02T14:50:25.948332+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.946865+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Declare an Input Defined with Source Indices as a Design Variable\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "class MyComp1(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(3))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*2.0\n",
    "\n",
    "class MyComp2(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(2))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*4.0\n",
    "\n",
    "p = om.Problem()\n",
    "\n",
    "p.model.add_subsystem('indep', om.IndepVarComp('x', np.ones(5)),\n",
    "                      promotes_outputs=['x'])\n",
    "p.model.add_subsystem('C1', MyComp1())\n",
    "p.model.add_subsystem('C2', MyComp2())\n",
    "\n",
    "# this input will connect to entries 0, 1, and 2 of its source\n",
    "p.model.promotes('C1', inputs=['x'], src_indices=[0, 1, 2])\n",
    "\n",
    "# this input will connect to entries 3 and 4 of its source\n",
    "p.model.promotes('C2', inputs=['x'], src_indices=[3, 4])\n",
    "\n",
    "p.model.add_design_var('x')\n",
    "p.setup()\n",
    "p.run_model()\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "class MyComp1(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(3))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*2.0\n",
    "\n",
    "class MyComp2(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(2))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*4.0\n",
    "\n",
    "p = om.Problem()\n",
    "\n",
    "# IndepVarComp is required to define the full size of the source vector.\n",
    "p.model.add_subsystem('indep', om.IndepVarComp('x', np.ones(5)),\n",
    "                      promotes_outputs=['x'])\n",
    "p.model.add_subsystem('C1', MyComp1())\n",
    "p.model.add_subsystem('C2', MyComp2())\n",
    "\n",
    "# this input will connect to entries 0, 1, and 2 of its source\n",
    "p.model.promotes('C1', inputs=['x'], src_indices=[0, 1, 2])\n",
    "\n",
    "# this input will connect to entries 3 and 4 of its source\n",
    "p.model.promotes('C2', inputs=['x'], src_indices=[3, 4])\n",
    "\n",
    "p.model.add_design_var('x')\n",
    "p.setup()\n",
    "p.run_model()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "aefc151c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:25.989661Z",
     "iopub.status.busy": "2026-10-02T14:50:25.989516Z",
     "iopub.status.idle": "2026-10-02T14:50:26.086248Z",
     "shell.execute_reply": "2026-10-02T14:50:26.085804Z"
    },
    "papermill": {
     "duration": 0.099805,
     "end_time": "2026-10-02T14:50:26.087087+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:25.987282+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import openmdao.api as om\n",
    "\n",
    "\n",
    "class MyComp1(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(3))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*2.0\n",
    "\n",
    "class MyComp2(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(2))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*4.0\n",
    "\n",
    "p = om.Problem()\n",
    "\n",
    "p.model.add_subsystem('indep', om.IndepVarComp('x', np.ones(5)),\n",
    "                      promotes_outputs=['x'])\n",
    "p.model.add_subsystem('C1', MyComp1())\n",
    "p.model.add_subsystem('C2', MyComp2())\n",
    "\n",
    "# this input will connect to entries 0, 1, and 2 of its source\n",
    "p.model.promotes('C1', inputs=['x'], src_indices=[0, 1, 2])\n",
    "\n",
    "# this input will connect to entries 3 and 4 of its source\n",
    "p.model.promotes('C2', inputs=['x'], src_indices=[3, 4])\n",
    "\n",
    "p.model.add_design_var('x')\n",
    "p.setup()\n",
    "p.run_model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b08266fd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:26.091410Z",
     "iopub.status.busy": "2026-10-02T14:50:26.091240Z",
     "iopub.status.idle": "2026-10-02T14:50:26.097406Z",
     "shell.execute_reply": "2026-10-02T14:50:26.096889Z"
    },
    "papermill": {
     "duration": 0.008961,
     "end_time": "2026-10-02T14:50:26.097886+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.088925+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "\n",
    "class MyComp1(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(3))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*2.0\n",
    "\n",
    "class MyComp2(om.ExplicitComponent):\n",
    "    def setup(self):\n",
    "        self.add_input('x', np.ones(2))\n",
    "        self.add_output('y', 1.0)\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['y'] = np.sum(inputs['x'])*4.0\n",
    "\n",
    "p = om.Problem()\n",
    "\n",
    "# IndepVarComp is required to define the full size of the source vector.\n",
    "p.model.add_subsystem('indep', om.IndepVarComp('x', np.ones(5)),\n",
    "                      promotes_outputs=['x'])\n",
    "p.model.add_subsystem('C1', MyComp1())\n",
    "p.model.add_subsystem('C2', MyComp2())\n",
    "\n",
    "# this input will connect to entries 0, 1, and 2 of its source\n",
    "p.model.promotes('C1', inputs=['x'], src_indices=[0, 1, 2])\n",
    "\n",
    "# this input will connect to entries 3 and 4 of its source\n",
    "p.model.promotes('C2', inputs=['x'], src_indices=[3, 4])\n",
    "\n",
    "p.model.add_design_var('x')\n",
    "p.setup()\n",
    "p.run_model()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ed75930",
   "metadata": {
    "papermill": {
     "duration": 0.001483,
     "end_time": "2026-10-02T14:50:26.115295+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.113812+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Setting Default Units for an Input\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "ivc = om.IndepVarComp()\n",
    "ivc.add_output('x2', 100.0, units='degC')\n",
    "prob.model.add_subsystem('T1', ivc,\n",
    "                       promotes_outputs=['x2'])\n",
    "\n",
    "# Input units in degF\n",
    "prob.model.add_subsystem('tgtF', TgtCompF(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degC\n",
    "prob.model.add_subsystem('tgtC', TgtCompC(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in deg\n",
    "prob.model.add_subsystem('tgtK', TgtCompK(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "prob.setup()\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "# Input units in degF\n",
    "prob.model.add_subsystem('tgtF', TgtCompF(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degC\n",
    "prob.model.add_subsystem('tgtC', TgtCompC(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degK\n",
    "prob.model.add_subsystem('tgtK', TgtCompK(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "prob.model.set_input_defaults('x2', 100.0, units='degC')\n",
    "\n",
    "prob.setup()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6416623e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:26.118948Z",
     "iopub.status.busy": "2026-10-02T14:50:26.118800Z",
     "iopub.status.idle": "2026-10-02T14:50:26.124210Z",
     "shell.execute_reply": "2026-10-02T14:50:26.123483Z"
    },
    "papermill": {
     "duration": 0.007876,
     "end_time": "2026-10-02T14:50:26.124661+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.116785+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "from openmdao.test_suite.components.unit_conv import TgtCompC, TgtCompF, TgtCompK\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "ivc = om.IndepVarComp()\n",
    "ivc.add_output('x2', 100.0, units='degC')\n",
    "prob.model.add_subsystem('T1', ivc,\n",
    "                       promotes_outputs=['x2'])\n",
    "\n",
    "# Input units in degF\n",
    "prob.model.add_subsystem('tgtF', TgtCompF(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degC\n",
    "prob.model.add_subsystem('tgtC', TgtCompC(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in deg\n",
    "prob.model.add_subsystem('tgtK', TgtCompK(),\n",
    "                       promotes_inputs=['x2'])\n",
    "\n",
    "prob.setup();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5d6402c6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:26.128348Z",
     "iopub.status.busy": "2026-10-02T14:50:26.128214Z",
     "iopub.status.idle": "2026-10-02T14:50:26.132525Z",
     "shell.execute_reply": "2026-10-02T14:50:26.131858Z"
    },
    "papermill": {
     "duration": 0.006736,
     "end_time": "2026-10-02T14:50:26.132981+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.126245+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "# Input units in degF\n",
    "prob.model.add_subsystem('tgtF', TgtCompF(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degC\n",
    "prob.model.add_subsystem('tgtC', TgtCompC(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "# Input units in degK\n",
    "prob.model.add_subsystem('tgtK', TgtCompK(),\n",
    "                         promotes_inputs=['x2'])\n",
    "\n",
    "prob.model.set_input_defaults('x2', 100.0, units='degC')\n",
    "\n",
    "prob.setup();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0380d391",
   "metadata": {
    "papermill": {
     "duration": 0.001633,
     "end_time": "2026-10-02T14:50:26.136134+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.134501+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Creating a Distributed Component with Unconnected Inputs\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "size = 4\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem(\"C1\", DistribNoncontiguousComp(arr_size=size),\n",
    "                       promotes=['invec', 'outvec'])\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "rank = prob.model.comm.rank\n",
    "if rank == 0:\n",
    "    prob.set_val('invec', np.array([1.0, 3.0]))\n",
    "else:\n",
    "    prob.set_val('invec', np.array([5.0, 7.0]))\n",
    "\n",
    "prob.run_model()\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "size = 4\n",
    "dist_size = 2\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "# An IndepVarComp is required on all unconnected distributed inputs.\n",
    "ivc = om.IndepVarComp()\n",
    "ivc.add_output('invec', np.ones(dist_size), distributed=True)\n",
    "prob.model.add_subsystem('P', ivc,\n",
    "                         promotes_outputs=['invec'])\n",
    "\n",
    "prob.model.add_subsystem(\"C1\", DistribNoncontiguousComp(arr_size=size),\n",
    "                         promotes=['invec', 'outvec'])\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "prob.set_val('P.invec', np.array([1.0, 3.0, 5.0, 7.0]))\n",
    "\n",
    "prob.run_model()\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0c70aa92",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:26.139772Z",
     "iopub.status.busy": "2026-10-02T14:50:26.139633Z",
     "iopub.status.idle": "2026-10-02T14:50:26.143157Z",
     "shell.execute_reply": "2026-10-02T14:50:26.142590Z"
    },
    "papermill": {
     "duration": 0.005936,
     "end_time": "2026-10-02T14:50:26.143554+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.137618+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing mpi_script_0.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile mpi_script_0.py\n",
    "import numpy as np\n",
    "import openmdao.api as om\n",
    "from openmdao.utils.array_utils import take_nth\n",
    "\n",
    "\n",
    "class DistribNoncontiguousComp(om.ExplicitComponent):\n",
    "    '''Uses 4 procs and takes non-contiguous input var slices and has output\n",
    "    var slices as well\n",
    "    '''\n",
    "\n",
    "    def initialize(self):\n",
    "        self.options.declare('arr_size', types=int, default=11,\n",
    "                             desc=\"Size of input and output vectors.\")\n",
    "\n",
    "    def compute(self, inputs, outputs):\n",
    "        outputs['outvec'] = inputs['invec']*2.0\n",
    "\n",
    "    def setup(self):\n",
    "        arr_size = self.options['arr_size']\n",
    "\n",
    "        self.add_input('invec', np.ones(arr_size, float), distributed=True)\n",
    "        self.add_output('outvec', np.ones(arr_size, float), distributed=True)\n",
    "\n",
    "\n",
    "size = 4\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "comm = prob.comm\n",
    "rank = comm.rank\n",
    "idxs = list(take_nth(rank, comm.size, range(size)))\n",
    "\n",
    "ivc = om.IndepVarComp()\n",
    "ivc.add_output('invec', np.ones(len(idxs)), distributed=True)\n",
    "\n",
    "prob.model.add_subsystem('P', ivc, promotes_outputs=['invec'])\n",
    "prob.model.add_subsystem('C1', DistribNoncontiguousComp(arr_size=len(idxs)),\n",
    "                         promotes_outputs=['outvec'])\n",
    "\n",
    "prob.model.promotes('C1', inputs=['invec'], src_indices=idxs)\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "val_array = np.array([1.0, 3.0, 5.0, 7.0])\n",
    "prob.set_val('invec', val_array[idxs])\n",
    "\n",
    "prob.run_model()\n",
    "\n",
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "assert_near_equal(prob.get_val('C1.outvec', get_remote=True), np.array([2.0, 6.0, 10.0, 14.0]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3b34afd8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:26.172295Z",
     "iopub.status.busy": "2026-10-02T14:50:26.172145Z",
     "iopub.status.idle": "2026-10-02T14:50:30.143641Z",
     "shell.execute_reply": "2026-10-02T14:50:30.143058Z"
    },
    "papermill": {
     "duration": 3.97466,
     "end_time": "2026-10-02T14:50:30.144519+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:26.169859+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"admonition note\"><p class=\"admonition-title\">Note</p><p>This feature requires MPI, and may not be able to be run on Colab or Binder.</p></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<p>The following script is executed using <code>mpiexec -n 4 mpi_script_0.py</code>:</p><style>pre { line-height: 125%; }\n",
       "td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\n",
       "span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\n",
       "td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\n",
       "span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\n",
       ".highlight .hll { background-color: #ffffcc }\n",
       ".highlight { background: #f8f8f8; }\n",
       ".highlight .c { color: #3D7B7B; font-style: italic } /* Comment */\n",
       ".highlight .err { border: 1px solid #F00 } /* Error */\n",
       ".highlight .k { color: #008000; font-weight: bold } /* Keyword */\n",
       ".highlight .o { color: #666 } /* Operator */\n",
       ".highlight .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */\n",
       ".highlight .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */\n",
       ".highlight .cp { color: #9C6500 } /* Comment.Preproc */\n",
       ".highlight .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */\n",
       ".highlight .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */\n",
       ".highlight .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */\n",
       ".highlight .gd { color: #A00000 } /* Generic.Deleted */\n",
       ".highlight .ge { font-style: italic } /* Generic.Emph */\n",
       ".highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */\n",
       ".highlight .gr { color: #E40000 } /* Generic.Error */\n",
       ".highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
       ".highlight .gi { color: #008400 } /* Generic.Inserted */\n",
       ".highlight .go { color: #717171 } /* Generic.Output */\n",
       ".highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
       ".highlight .gs { font-weight: bold } /* Generic.Strong */\n",
       ".highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
       ".highlight .gt { color: #04D } /* Generic.Traceback */\n",
       ".highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
       ".highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
       ".highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
       ".highlight .kp { color: #008000 } /* Keyword.Pseudo */\n",
       ".highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
       ".highlight .kt { color: #B00040 } /* Keyword.Type */\n",
       ".highlight .m { color: #666 } /* Literal.Number */\n",
       ".highlight .s { color: #BA2121 } /* Literal.String */\n",
       ".highlight .na { color: #687822 } /* Name.Attribute */\n",
       ".highlight .nb { color: #008000 } /* Name.Builtin */\n",
       ".highlight .nc { color: #00F; font-weight: bold } /* Name.Class */\n",
       ".highlight .no { color: #800 } /* Name.Constant */\n",
       ".highlight .nd { color: #A2F } /* Name.Decorator */\n",
       ".highlight .ni { color: #717171; font-weight: bold } /* Name.Entity */\n",
       ".highlight .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */\n",
       ".highlight .nf { color: #00F } /* Name.Function */\n",
       ".highlight .nl { color: #767600 } /* Name.Label */\n",
       ".highlight .nn { color: #00F; font-weight: bold } /* Name.Namespace */\n",
       ".highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
       ".highlight .nv { color: #19177C } /* Name.Variable */\n",
       ".highlight .ow { color: #A2F; font-weight: bold } /* Operator.Word */\n",
       ".highlight .w { color: #BBB } /* Text.Whitespace */\n",
       ".highlight .mb { color: #666 } /* Literal.Number.Bin */\n",
       ".highlight .mf { color: #666 } /* Literal.Number.Float */\n",
       ".highlight .mh { color: #666 } /* Literal.Number.Hex */\n",
       ".highlight .mi { color: #666 } /* Literal.Number.Integer */\n",
       ".highlight .mo { color: #666 } /* Literal.Number.Oct */\n",
       ".highlight .sa { color: #BA2121 } /* Literal.String.Affix */\n",
       ".highlight .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
       ".highlight .sc { color: #BA2121 } /* Literal.String.Char */\n",
       ".highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
       ".highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
       ".highlight .s2 { color: #BA2121 } /* Literal.String.Double */\n",
       ".highlight .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */\n",
       ".highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
       ".highlight .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */\n",
       ".highlight .sx { color: #008000 } /* Literal.String.Other */\n",
       ".highlight .sr { color: #A45A77 } /* Literal.String.Regex */\n",
       ".highlight .s1 { color: #BA2121 } /* Literal.String.Single */\n",
       ".highlight .ss { color: #19177C } /* Literal.String.Symbol */\n",
       ".highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
       ".highlight .fm { color: #00F } /* Name.Function.Magic */\n",
       ".highlight .vc { color: #19177C } /* Name.Variable.Class */\n",
       ".highlight .vg { color: #19177C } /* Name.Variable.Global */\n",
       ".highlight .vi { color: #19177C } /* Name.Variable.Instance */\n",
       ".highlight .vm { color: #19177C } /* Name.Variable.Magic */\n",
       ".highlight .il { color: #666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">numpy</span><span class=\"w\"> </span><span class=\"k\">as</span><span class=\"w\"> </span><span class=\"nn\">np</span>\n",
       "<span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">openmdao.api</span><span class=\"w\"> </span><span class=\"k\">as</span><span class=\"w\"> </span><span class=\"nn\">om</span>\n",
       "<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">openmdao.utils.array_utils</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">take_nth</span>\n",
       "\n",
       "\n",
       "<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">DistribNoncontiguousComp</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\">&#39;&#39;&#39;Uses 4 procs and takes non-contiguous input var slices and has output</span>\n",
       "<span class=\"sd\">    var slices as well</span>\n",
       "<span class=\"sd\">    &#39;&#39;&#39;</span>\n",
       "\n",
       "    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">initialize</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\">options</span><span class=\"o\">.</span><span class=\"n\">declare</span><span class=\"p\">(</span><span class=\"s1\">&#39;arr_size&#39;</span><span class=\"p\">,</span> <span class=\"n\">types</span><span class=\"o\">=</span><span class=\"nb\">int</span><span class=\"p\">,</span> <span class=\"n\">default</span><span class=\"o\">=</span><span class=\"mi\">11</span><span class=\"p\">,</span>\n",
       "                             <span class=\"n\">desc</span><span class=\"o\">=</span><span class=\"s2\">&quot;Size of input and output vectors.&quot;</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=\"n\">outputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;outvec&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"n\">inputs</span><span class=\"p\">[</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">]</span><span class=\"o\">*</span><span class=\"mf\">2.0</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=\"n\">arr_size</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">options</span><span class=\"p\">[</span><span class=\"s1\">&#39;arr_size&#39;</span><span class=\"p\">]</span>\n",
       "\n",
       "        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">add_input</span><span class=\"p\">(</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">,</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">ones</span><span class=\"p\">(</span><span class=\"n\">arr_size</span><span class=\"p\">,</span> <span class=\"nb\">float</span><span class=\"p\">),</span> <span class=\"n\">distributed</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n",
       "        <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">add_output</span><span class=\"p\">(</span><span class=\"s1\">&#39;outvec&#39;</span><span class=\"p\">,</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">ones</span><span class=\"p\">(</span><span class=\"n\">arr_size</span><span class=\"p\">,</span> <span class=\"nb\">float</span><span class=\"p\">),</span> <span class=\"n\">distributed</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n",
       "\n",
       "\n",
       "<span class=\"n\">size</span> <span class=\"o\">=</span> <span class=\"mi\">4</span>\n",
       "\n",
       "<span class=\"n\">prob</span> <span class=\"o\">=</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">Problem</span><span class=\"p\">()</span>\n",
       "\n",
       "<span class=\"n\">comm</span> <span class=\"o\">=</span> <span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">comm</span>\n",
       "<span class=\"n\">rank</span> <span class=\"o\">=</span> <span class=\"n\">comm</span><span class=\"o\">.</span><span class=\"n\">rank</span>\n",
       "<span class=\"n\">idxs</span> <span class=\"o\">=</span> <span class=\"nb\">list</span><span class=\"p\">(</span><span class=\"n\">take_nth</span><span class=\"p\">(</span><span class=\"n\">rank</span><span class=\"p\">,</span> <span class=\"n\">comm</span><span class=\"o\">.</span><span class=\"n\">size</span><span class=\"p\">,</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"n\">size</span><span class=\"p\">)))</span>\n",
       "\n",
       "<span class=\"n\">ivc</span> <span class=\"o\">=</span> <span class=\"n\">om</span><span class=\"o\">.</span><span class=\"n\">IndepVarComp</span><span class=\"p\">()</span>\n",
       "<span class=\"n\">ivc</span><span class=\"o\">.</span><span class=\"n\">add_output</span><span class=\"p\">(</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">,</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">ones</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">idxs</span><span class=\"p\">)),</span> <span class=\"n\">distributed</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n",
       "\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">model</span><span class=\"o\">.</span><span class=\"n\">add_subsystem</span><span class=\"p\">(</span><span class=\"s1\">&#39;P&#39;</span><span class=\"p\">,</span> <span class=\"n\">ivc</span><span class=\"p\">,</span> <span class=\"n\">promotes_outputs</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">])</span>\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">model</span><span class=\"o\">.</span><span class=\"n\">add_subsystem</span><span class=\"p\">(</span><span class=\"s1\">&#39;C1&#39;</span><span class=\"p\">,</span> <span class=\"n\">DistribNoncontiguousComp</span><span class=\"p\">(</span><span class=\"n\">arr_size</span><span class=\"o\">=</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">idxs</span><span class=\"p\">)),</span>\n",
       "                         <span class=\"n\">promotes_outputs</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s1\">&#39;outvec&#39;</span><span class=\"p\">])</span>\n",
       "\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">model</span><span class=\"o\">.</span><span class=\"n\">promotes</span><span class=\"p\">(</span><span class=\"s1\">&#39;C1&#39;</span><span class=\"p\">,</span> <span class=\"n\">inputs</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">],</span> <span class=\"n\">src_indices</span><span class=\"o\">=</span><span class=\"n\">idxs</span><span class=\"p\">)</span>\n",
       "\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">setup</span><span class=\"p\">()</span>\n",
       "\n",
       "<span class=\"n\">val_array</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">array</span><span class=\"p\">([</span><span class=\"mf\">1.0</span><span class=\"p\">,</span> <span class=\"mf\">3.0</span><span class=\"p\">,</span> <span class=\"mf\">5.0</span><span class=\"p\">,</span> <span class=\"mf\">7.0</span><span class=\"p\">])</span>\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">set_val</span><span class=\"p\">(</span><span class=\"s1\">&#39;invec&#39;</span><span class=\"p\">,</span> <span class=\"n\">val_array</span><span class=\"p\">[</span><span class=\"n\">idxs</span><span class=\"p\">])</span>\n",
       "\n",
       "<span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">run_model</span><span class=\"p\">()</span>\n",
       "\n",
       "<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">openmdao.utils.assert_utils</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">assert_near_equal</span>\n",
       "<span class=\"n\">assert_near_equal</span><span class=\"p\">(</span><span class=\"n\">prob</span><span class=\"o\">.</span><span class=\"n\">get_val</span><span class=\"p\">(</span><span class=\"s1\">&#39;C1.outvec&#39;</span><span class=\"p\">,</span> <span class=\"n\">get_remote</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">),</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">array</span><span class=\"p\">([</span><span class=\"mf\">2.0</span><span class=\"p\">,</span> <span class=\"mf\">6.0</span><span class=\"p\">,</span> <span class=\"mf\">10.0</span><span class=\"p\">,</span> <span class=\"mf\">14.0</span><span class=\"p\">]))</span>\n",
       "</pre></div>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952627.919142] [runnervm8df0l:12009:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x55c9b27c19c0 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",
      "[1790952627.922741] [runnervm8df0l:12011:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x558520e70880 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",
      "[1790952627.923523] [runnervm8df0l:12009:0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n",
      "[1790952627.924461] [runnervm8df0l:12010:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x55c00befe480 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",
      "[1790952627.924769] [runnervm8df0l:12011:0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n",
      "[1790952627.925678] [runnervm8df0l:12008:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x55cda0e0c120 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",
      "[1790952627.927280] [runnervm8df0l:12010:0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n",
      "[1790952627.927666] [runnervm8df0l:12008:0]      ucp_worker.c:1412 UCX  ERROR uct_iface_open(ud_verbs/mana_0:1) failed: Input/output error\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from openmdao.utils.notebook_utils import mpi_exec\n",
    "mpi_exec(4, 'mpi_script_0.py')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e83a86b",
   "metadata": {
    "papermill": {
     "duration": 0.001711,
     "end_time": "2026-10-02T14:50:30.148084+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:30.146373+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Setting and Getting Inputs\n",
    "\n",
    "\n",
    "`````{tab-set}\n",
    "````{tab-item} Pre Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.x', 'paraboloid.x')\n",
    "prob.model.connect('indeps.y', 'paraboloid.y')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "x = prob.get_val('indeps.x')\n",
    "prob.set_val('indeps.y', 15.0)\n",
    "```\n",
    "````\n",
    "\n",
    "````{tab-item} With Auto IVC\n",
    "```\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "x = prob.get_val('x')\n",
    "prob.set_val('y', 15.0)\n",
    "```\n",
    "````\n",
    "`````\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "94b1ee9b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:30.489134Z",
     "iopub.status.busy": "2026-10-02T14:50:30.488945Z",
     "iopub.status.idle": "2026-10-02T14:50:30.494452Z",
     "shell.execute_reply": "2026-10-02T14:50:30.493371Z"
    },
    "papermill": {
     "duration": 0.345593,
     "end_time": "2026-10-02T14:50:30.495559+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:30.149966+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "indeps = prob.model.add_subsystem('indeps', om.IndepVarComp())\n",
    "indeps.add_output('x', 3.0)\n",
    "indeps.add_output('y', -4.0)\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "prob.model.connect('indeps.x', 'paraboloid.x')\n",
    "prob.model.connect('indeps.y', 'paraboloid.y')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "x = prob.get_val('indeps.x')\n",
    "prob.set_val('indeps.y', 15.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1f00177d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:50:30.500086Z",
     "iopub.status.busy": "2026-10-02T14:50:30.499942Z",
     "iopub.status.idle": "2026-10-02T14:50:30.503519Z",
     "shell.execute_reply": "2026-10-02T14:50:30.502995Z"
    },
    "papermill": {
     "duration": 0.00639,
     "end_time": "2026-10-02T14:50:30.503940+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:50:30.497550+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid',\n",
    "                         om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'),\n",
    "                         promotes_inputs=['x', 'y'])\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "x = prob.get_val('x')\n",
    "prob.set_val('y', 15.0)"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "dev311",
   "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"
  },
  "mpi": true,
  "papermill": {
   "default_parameters": {},
   "duration": 8.39705,
   "end_time": "2026-10-02T14:50:31.020201+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/other_useful_docs/auto_ivc_api_translation.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/other_useful_docs/auto_ivc_api_translation.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:50:22.623151+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}