{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cd9ef718",
   "metadata": {
    "papermill": {
     "duration": 0.00137,
     "end_time": "2026-10-02T14:46:42.423639+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:42.422269+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Getting Started\n",
    "\n",
    "Installation Instructions:\n",
    "\n",
    "From your python environment, just type the following at the operating system command prompt:\n",
    "\n",
    "``` bash\n",
    "pip install 'openmdao[all]'\n",
    "```\n",
    "\n",
    "```{note}\n",
    "\n",
    "The [all] suffix to the install command ensures that you get all the optional dependencies\n",
    "(e.g. for testing and visualization).  You can omit this for a minimal installation.\n",
    "\n",
    "The quotation marks are required to prevent some command shells (e.g. zsh) from trying to interpret\n",
    "the square brackets.\n",
    "```\n",
    "\n",
    "## Using Pixi Environments\n",
    "\n",
    "For most users, this will be the simplest way to set up an environment that has been proven to work with OpenMDAO.\n",
    "See the documentation on [OpenMDAO pixi environments](pixi_environment.ipynb) for information on how to use it.\n",
    "\n",
    "## Using in Jupyter notebooks on Google Colab\n",
    "\n",
    "Alternatively, in a Jupyter notebook environment such as [Google Colab](https://colab.research.google.com),\n",
    "you can install OpenMDAO by running the above as a shell command (precede it with !).\n",
    "\n",
    "The examples in this documentation will do this for you using the following block. This simply installs OpenMDAO if it is not already available. This is not typically necessary if you're running OpenMDAO on your local computer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6d9c6fd5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:46:42.427495Z",
     "iopub.status.busy": "2026-10-02T14:46:42.427252Z",
     "iopub.status.idle": "2026-10-02T14:46:43.736242Z",
     "shell.execute_reply": "2026-10-02T14:46:43.735793Z"
    },
    "hide_input": true,
    "papermill": {
     "duration": 1.312114,
     "end_time": "2026-10-02T14:46:43.737247+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:42.425133+00:00",
     "status": "completed"
    },
    "tags": [
     "active-ipynb",
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    import openmdao.api as om\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]\n",
    "    import openmdao.api as om\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae941f27",
   "metadata": {
    "papermill": {
     "duration": 0.00078,
     "end_time": "2026-10-02T14:46:43.739141+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:43.738361+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Parallel Processing with MPI\n",
    "\n",
    "OpenMDAO enables parallel processing via [MPI](https://www.mcs.anl.gov/research/projects/mpi/) and [PETSc](https://petsc.org). This requires a few pre-requisites that can be installed with your package manager of choice: `mpi4py` and `petsc4py`.\n",
    "    \n",
    "For Windows users, installing `PETSc` can be more difficult as [described on the PETSc web site](https://petsc.org/main/install/windows/).  Probably the quickest way to get up and running with MPI on Windows is to use\n",
    "[Windows Subsystem for Linux (WSL2)](https://learn.microsoft.com/en-us/windows/wsl/). WSL integration with [Visual Studio Code](https://code.visualstudio.com/) provides a nearly seamless development environment on Windows."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1f7df90",
   "metadata": {
    "papermill": {
     "duration": 0.000825,
     "end_time": "2026-10-02T14:46:43.740779+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:43.739954+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Sample Optimization File\n",
    "\n",
    "With OpenMDAO installed, let's try out a simple example, to get you started running your first optimization.\n",
    "Copy the following code into a file named paraboloid_min.py:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "360af236",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:46:43.893233Z",
     "iopub.status.busy": "2026-10-02T14:46:43.892635Z",
     "iopub.status.idle": "2026-10-02T14:46:45.211677Z",
     "shell.execute_reply": "2026-10-02T14:46:45.210885Z"
    },
    "papermill": {
     "duration": 1.470861,
     "end_time": "2026-10-02T14:46:45.212423+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:43.741562+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1790952405.167889] [runnervm8df0l:10710:0]        ib_iface.c:1269 UCX  ERROR mana_0: iface 0x5623f7451de0 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",
      "[1790952405.168123] [runnervm8df0l:10710: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:10710] pml_ucx.c:313  Error: Failed to create UCP worker\n"
     ]
    }
   ],
   "source": [
    "import openmdao.api as om\n",
    "\n",
    "# build the model\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid', om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('paraboloid.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('paraboloid.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "# Set initial values.\n",
    "prob.set_val('paraboloid.x', 3.0)\n",
    "prob.set_val('paraboloid.y', -4.0)\n",
    "\n",
    "# run the optimization\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da0f185a",
   "metadata": {
    "papermill": {
     "duration": 0.00168,
     "end_time": "2026-10-02T14:46:45.215705+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:45.214025+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Then, to run the file, simply type:\n",
    "\n",
    "``` bash\n",
    ">> python paraboloid_min.py\n",
    "```\n",
    "\n",
    "If all works as planned, results should appear as such:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "30582afd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:46:45.219822Z",
     "iopub.status.busy": "2026-10-02T14:46:45.219550Z",
     "iopub.status.idle": "2026-10-02T14:46:45.229984Z",
     "shell.execute_reply": "2026-10-02T14:46:45.229164Z"
    },
    "papermill": {
     "duration": 0.01304,
     "end_time": "2026-10-02T14:46:45.230502+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:45.217462+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-input"
    ]
   },
   "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": [
    "import openmdao.api as om\n",
    "\n",
    "# build the model\n",
    "prob = om.Problem()\n",
    "\n",
    "prob.model.add_subsystem('paraboloid', om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))\n",
    "\n",
    "# setup the optimization\n",
    "prob.driver = om.ScipyOptimizeDriver()\n",
    "prob.driver.options['optimizer'] = 'SLSQP'\n",
    "\n",
    "prob.model.add_design_var('paraboloid.x', lower=-50, upper=50)\n",
    "prob.model.add_design_var('paraboloid.y', lower=-50, upper=50)\n",
    "prob.model.add_objective('paraboloid.f')\n",
    "\n",
    "prob.setup()\n",
    "\n",
    "# Set initial values.\n",
    "prob.set_val('paraboloid.x', 3.0)\n",
    "prob.set_val('paraboloid.y', -4.0)\n",
    "\n",
    "# run the optimization\n",
    "prob.run_driver();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1d4ca39b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-02T14:46:45.233493Z",
     "iopub.status.busy": "2026-10-02T14:46:45.233291Z",
     "iopub.status.idle": "2026-10-02T14:46:45.239605Z",
     "shell.execute_reply": "2026-10-02T14:46:45.238948Z"
    },
    "hide_input": true,
    "papermill": {
     "duration": 0.008591,
     "end_time": "2026-10-02T14:46:45.240162+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:45.231571+00:00",
     "status": "completed"
    },
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.545456612206542e-07)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This block of code tests that the documented code functions as\n",
    "# expected and is hidden by default.\n",
    "\n",
    "from openmdao.utils.assert_utils import assert_near_equal\n",
    "\n",
    "# minimum value\n",
    "assert_near_equal(prob.get_val('paraboloid.f'), -27.33333, 1e-6)\n",
    "\n",
    "# location of the minimum\n",
    "assert_near_equal(prob.get_val('paraboloid.x'), 6.6667, 1e-4)\n",
    "assert_near_equal(prob.get_val('paraboloid.y'), -7.33333, 1e-4)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a2ab44e",
   "metadata": {
    "papermill": {
     "duration": 0.021358,
     "end_time": "2026-10-02T14:46:45.263112+00:00",
     "exception": false,
     "start_time": "2026-10-02T14:46:45.241754+00:00",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "```{toctree}\n",
    ":hidden:\n",
    "\n",
    "pixi_environment\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "dev",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.14"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 4.034667,
   "end_time": "2026-10-02T14:46:45.779717+00:00",
   "environment_variables": {},
   "exception": null,
   "input_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/openmdao_book/getting_started/getting_started.ipynb",
   "output_path": "/home/runner/work/OpenMDAO/OpenMDAO/openmdao/docs/_executed_book/getting_started/getting_started.ipynb",
   "parameters": {},
   "start_time": "2026-10-02T14:46:41.745050+00:00",
   "version": "2.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}