<jupyter_start><jupyter_text>OpenMDAO Docs Style GuideThis document outlines OpenMDAO-v3 documentation conventions regardingboth content and formatting. General Docstring ConventionsGeneral docstring rules:- All docstrings should begin and end with triple double quotes (""").- Modules, classes, methods, and functions must have docstrings  whether the object is public or private.Two types of docstrings:1. One-line docstrings:```     """Do something."""```   - Phrase or sentence ended by a period.   - No empty space between the text and the triple double quotes.2. Multi-line docstrings:```     """Summary line.     Paragraph 1.     """```   - Summary line ended by a period.   - No empty space between the summary line and     the opening triple double quotes.   - Paragraphs separated by blank lines.   - Can contain a list of attributes/args/returns, explained below.   - No empty line at the end, before closing triple double quotes.Detailed docstring rules:1. Modules:   - Either one-line or multi-line.   - No blank line after the docstring.   - List the classes and functions inside (this can be automated).2. Classes:   - Either one-line or multi-line.   - List the attributes, if any (then must be multi-line).   - Blank line after the docstring.```     """Summary line.     Paragraph 1.     Attributes     ----------     attribute_name : Type         description ending with a period.     """```3. Methods or functions:   - Either one-line or multi-line.   - List the arguments (except for self) and the returned variables, if any.   - The summary line/one-line docstring should be an imperative sentence,     not a descriptive phrase:     - Incorrect: `"""Does something."""`     - Correct: `"""Do something."""`   - No blank line after the docstring.```     """Do something.     Paragraph 1.     Parameters     ----------     argument_name : Type         description ending with a period.     Returns     -------     Type         description ending with a period.     """```   - Sphinx does not correctly handle decorated methods. To ensure a method's     call signature appears correctly in the docs, put the call signature of the method     into the first line of the docstring. [See Sphinx and Decorated Methods](sphinx_decorators.ipynb) for more information.) For example:```     """     method_name(self, arg1, arg2)     Do something.     Paragraph 1.     Parameters     ----------     argument_name : Type         description ending with a period.     Returns     -------     Type         description ending with a period.     """``` Notebook Guidelines1. Each notebook should include this block at the top to import OpenMDAO if not already available.  This is necessary on the cloude-based notebook environments like colab.```try:    import openmdao.api as omexcept ImportError:    !python -m pip install openmdao[notebooks]    import openmdao.api as om```This cell should be tagged with the following metadata.  The "remove-input" and "remove-output" tags prevent it from showing up in the documentation, and the "hide_input" portion collapses the input cell. To add tags in Jupyter Notebook, navigate to `View` -> `Cell Toolbar` -> `Tags`.```{  "hide_input": true,  "tags": [    "remove-input",    "remove-output"  ],  "trusted": true}```2\. Executed code in notebooks should be tested using the same assertions used in unittests.For instance, in the paraboloid case we have:``` This code block is hidden by default. It exists to verify that the above code works correctly.from openmdao.utils.assert_utils import assert_near_equal minimum valueassert_near_equal(prob.get_val('paraboloid.f'), -27.33333, 1e-6); location of the minimumassert_near_equal(prob.get_val('paraboloid.x'), 6.6667, 1e-4);assert_near_equal(prob.get_val('paraboloid.y'), -7.33333, 1e-4);```It's not necessary to show this in the documentation, so remove it using the samehiding metadata above.3. We will use a Github Action to check all output cells from the notebooks when committing them.  This will prevent git from picking up on meaningless diffs in the output cells and their metadata.4. Since 'n2.html' files and other build artifacts need to be manually copied over to the output `_build` directory to make the docs, each example notebook should be kept in its own directory. Notebook Guidelines for MPI Features1. Each notebook should include this block at the top to import OpenMDAO if not already available.  This includes some directives that are required to interact with an mpi server that will be launched.```%pylab inlinefrom ipyparallel import Client, errorcluster=Client(profile="mpi")view=cluster[:]view.block=Truetry:    import openmdao.api as omexcept ImportError:    !python -m pip install openmdao[notebooks]    import openmdao.api as om```This cell should be tagged with the following metadata.  The "remove-input" and "remove-output" tags prevent it from showing up in the documentation, and the "hide_input" portion collapses the input cell. To add tags in Jupyter Notebook, navigate to `View` -> `Cell Toolbar` -> `Tags`.```{  "hide_input": true,  "tags": [    "remove-input",    "remove-output"  ],  "trusted": true}```2. Any cell that needs to run in MPI should start with the following line.```%%px```3. The following steps are required in order to test and run the mpi examples. These are in addition to the normal requirements for setting up OpenMDAO under MPI.The following only need to be done once:```pip install ipyparalleljupyter serverextension enable --py ipyparallelipython profile create --parallel --profile=mpi```You will also need to edit the file ~/.ipython/profile_mpi/ipcluster_config.py and add the following line to the end:```c.IPClusterEngines.engine_launcher_class = 'MPIEngineSetLauncher'```Finally, you will need to launch an MPI server that the notebooks can use. If you cycle power on your computer, or you kill this process, then you will need to launch it again.```ipcluster start -n 2 --profile=mpi &``` Embedding Autodocumentation Snippets into DocumentationSometimes in a feature doc, you want to reproduce a particular method or class or module right there within the text. The syntax to do this is provided by the sphinx.ext.autodoc module, in three commands, automodule, autoclass, and automethod. The syntax of these, inside of a markdown file or Jupyter cell is detailed in the following example code:<jupyter_code>**AUTOMODULE EXAMPLE:**
```{eval-rst}
    .. automodule:: openmdao.core.group
        :noindex:
```

**AUTOCLASS EXAMPLE:**
```{eval-rst}
    .. autoclass:: openmdao.core.group.Group
        :noindex:
```

**AUTOMETHOD EXAMPLE:**
```{eval-rst}
  .. automethod:: openmdao.core.group.Group.add_subsystem
      :noindex:
```<jupyter_output><empty_output><jupyter_text>The :noindex: argument is needed to prevent unwanted replication interactions with the OpenMDAO source documentation. The above syntax will pull docstring info and produce the following output: Adding a Link to a Document in a `.ipynb` FileSometimes in a document, you don't want or need to embed/display the entiredocument of a class to make your point. At these times, you want to just providethe user with an easy way to link to the autodoc for quick reference.We'll do this with a `[]()` link.  The basic syntax looks like this:```    You might find this [file](openmdao_book/path/to/file.ipynb) helpful.```This could be a link to a file or a link to a website like our [home page](https://openmdao.org) Custom Functions for Embedding Items into OpenMDAO Documentation `display_source``om.display_source` is a custom function from OpenMDAO that takes one argument, which is a class, test, or method's full, dotted path (e.g. "openmdao.core.tests.test_expl_comp.RectangleComp").The syntax for invoking the function within a `.md` or `ipynb` file looks like this:<jupyter_code>import openmdao.api as om
om.display_source("openmdao.core.tests.test_expl_comp.RectangleComp")<jupyter_output><empty_output><jupyter_text>```{Note}When using this function in a doc, don't forget to apply `remove-input` tag to the cell for cleanliness```Embedding in this fashion has the benefit of allowing you to drop entire code blocks into a feature doc that may, for example, illustrate a usage example. Another great benefit of this method is that now your embedded example changes along with the code, so the docs maintain themselves.By default, docstrings will be included. There is an option to the directive to strip the docstrings:<jupyter_code>om.display_source("openmdao.core.tests.test_expl_comp.RectangleComp", hide_doc_string=True)<jupyter_output><empty_output><jupyter_text>Embedding More Than Just CodeSometimes developers will want to embed code, code output, or even plots into a document. Because our docs use Jupyter Notebooks, developers are now able to embed code examples directly into the documents just like this notebook and even write tests for the examples. Below is an example of the flexibility this allows:<jupyter_code># build the model
prob = om.Problem()

prob.model.add_subsystem('paraboloid', om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))

# setup the optimization
prob.driver = om.ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'

prob.model.add_design_var('paraboloid.x', lower=-50, upper=50)
prob.model.add_design_var('paraboloid.y', lower=-50, upper=50)
prob.model.add_objective('paraboloid.f')

prob.setup()

# Set initial values.
prob.set_val('paraboloid.x', 3.0)
prob.set_val('paraboloid.y', -4.0)

# run the optimization
prob.run_driver();
from openmdao.utils.assert_utils import assert_near_equal
assert_near_equal(prob.get_val('paraboloid.x'), 6.66666666, tolerance=1.0E-5)
assert_near_equal(prob.get_val('paraboloid.y'), -7.33333333, tolerance=1.0E-5)
assert_near_equal(prob.get_val('paraboloid.f'), -27.33333333, tolerance=1.0E-5)<jupyter_output><empty_output><jupyter_text>When adding tests, use `remove-output` and `remove-input` to keep the docs clean while still allowing tests to be run when building the docs.If you want to hide the output use the `remove-output` tag and/or `remove-input` to hide the code when the doc gets built. To add tags in Jupyter Notebook, navigate to `View` -> `Cell Toolbar` -> `Tags`. The output includes any output that the script produces, including plots. Below is an example of `remove-output`:<jupyter_code># build the model
prob = om.Problem()

prob.model.add_subsystem('paraboloid', om.ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3'))

# setup the optimization
prob.driver = om.ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'

prob.model.add_design_var('paraboloid.x', lower=-50, upper=50)
prob.model.add_design_var('paraboloid.y', lower=-50, upper=50)
prob.model.add_objective('paraboloid.f')

prob.setup()

# Set initial values.
prob.set_val('paraboloid.x', 3.0)
prob.set_val('paraboloid.y', -4.0)

# run the optimization
prob.run_driver();<jupyter_output><empty_output><jupyter_text>The tests will automatically detect if you have an assert in a cell but forgot to tag it with `remove-output` and `remove-input`.  If you need to include an assert in a visible cell block, you can tag that block with `allow-assert` so that the test will skip it. `show_options_table``om.show_options_table()` is function that lets a developer display a set of options directly into a feature doc by including the module dot path name. The syntax for invoking the directive looks like this:<jupyter_code>om.show_options_table("openmdao.solvers.linear.linear_block_jac.LinearBlockJac")<jupyter_output><empty_output><jupyter_text>Shell CommandsIf a developer wants to run a shell command, all they need to do is start the line with `!`. For example:<jupyter_code>!openmdao tree ../circuit.py<jupyter_output><empty_output><jupyter_text>CitationsTo insert a citation, use `om.cite()`. The single argument is the module dot path or the name of a function that returns an instance of the desired class when called with no arguments.<jupyter_code>om.cite("openmdao.drivers.scipy_optimizer.ScipyOptimizeDriver")<jupyter_output><empty_output><jupyter_text>N2To embed an `N2` diagram simply call `om.n2()` inside of a Jupyter code cell and the output will be automatically formatted and displayed when given a case file or `om.Problem()`. In the example below, we will display the n2 from the paraboloid example from above.<jupyter_code>om.n2(prob)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09403225806451612, 'fraction_numerical': 0.009758064516129032, 'mean_word_length': 4.548545861297539, 'pattern_counts': {'":': 6, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '118815', 'license': 'Apache-2.0', 'n_tokens_mistral': 3647, 'n_tokens_neox': 3479, 'n_words': 1457, 'path': 'openmdao/docs/openmdao_book/other_useful_docs/developer_docs/doc_style_guide.ipynb', 'repo_name': 'tong0711/OpenMDAO', 'size': '12400'}