{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input",
     "active-ipynb",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from openmdao.utils.notebook_utils import notebook_mode\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# View Connections of a Model\n",
    "\n",
    "## View Connections from Command Line\n",
    "\n",
    "The `openmdao view_connections` command generates a table of connection information for all input and\n",
    "output variables in the model.  For more in-depth documentation, see [openmdao view_connections](om-command-view-connections).\n",
    "\n",
    "## View Connections from Script\n",
    "\n",
    "You can also generate a display of model connections from within a script by calling the function `view_connections`.\n",
    "\n",
    "```{eval-rst}\n",
    "    .. autofunction:: openmdao.visualization.connection_viewer.viewconns.view_connections\n",
    "       :noindex:\n",
    "```\n",
    "\n",
    "Here is an example of how this function can be used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "from openmdao.utils.notebook_utils import get_code\n",
    "from myst_nb import glue\n",
    "glue(\"code_src73\", get_code(\"openmdao.test_suite.components.sellar.SellarNoDerivatives\"), display=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ":::{Admonition} `SellarNoDerivatives` class definition \n",
    ":class: dropdown\n",
    "\n",
    "{glue:}`code_src73`\n",
    ":::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "import openmdao.api as om\n",
    "from openmdao.test_suite.components.sellar import SellarNoDerivatives\n",
    "\n",
    "prob = om.Problem()\n",
    "prob.model = SellarNoDerivatives()\n",
    "\n",
    "prob.setup()\n",
    "prob.final_setup()\n",
    "\n",
    "om.view_connections(prob, outfile= \"sellar_connections.html\", show_browser=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example, an HTML file named `sellar_connections.html` is created. This file can then be opened using using your browser. The page will look like this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "from openmdao.test_suite.components.sellar import SellarNoDerivatives\n",
    "\n",
    "prob = om.Problem()\n",
    "prob.model = SellarNoDerivatives()\n",
    "\n",
    "prob.setup()\n",
    "prob.final_setup()\n",
    "\n",
    "om.view_connections(prob, outfile= \"sellar_connections.html\", show_browser=False)"
   ]
  }
 ],
 "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.8.1"
  },
  "orphan": true
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
