Command Line Tools

OpenMDAO has a number of debugging/viewing command line tools that are available via the openmdao command. There are two types of commands available, those that perform some sort of viewing or configuration checking on the Problem after its setup is complete, and those that are used to collect information about the entire run of the Problem, things like profilers and tracers.


The openmdao sub-commands, as well as any other console scripts associated with OpenMDAO, will only be available if you have installed OpenMDAO using pip. See Getting Started

All available openmdao sub-commands can be shown using the following command:

openmdao -h
usage: openmdao [-h]  ...

OpenMDAO Command Line Tools

optional arguments:
  -h, --help        show this help message and exit

    call_tree       Display the call tree for the specified class method and
                    all 'self' class methods it calls.
    check           Perform a number of configuration checks on the problem.
    cite            Print citations referenced by problem
    dump_idxs       Show distributed index information.
    iprof           Profiling of calls to particular object instances.
    iprof_totals    Total timings of calls to particular object instances.
    mem             Memory profiler.
    mempost         Post-processor for memory profile output.
    n2              Display an interactive N2 diagram of the problem.
                    Compute coloring(s) for specified partial jacobians.
    scaffold        Generate a simple scaffold for a component.
    summary         Print a short top-level summary of the problem.
    total_coloring  Compute a coloring for the total jacobian.
    total_sparsity  Compute the sparsity pattern of the total jacobian.
    trace           Dump trace output.
    tree            Print the system tree.
    view_coloring   Colored jacobian viewer.
                    Connection viewer showing values and source/target units.
    view_mm         Meta Model Viewer.
    view_model      Display an interactive N2 diagram of the problem.
                    (Deprecated, please use n2 instead.)
    xdsm            XDSM viewer.

Use -h after any sub-command for sub-command help.

All sub-commands are shown under ‘positional arguments’. To get further info on any sub-command, for example, for tree, follow the command with a -h. For example:

openmdao tree -h
usage: openmdao tree [-h] [-o OUTFILE] [-c] [-d DEPTH] [-a ATTRS] [-v VECVARS]
                     [-r RANK]

positional arguments:
  file                  Python file containing the model.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTFILE            Output file name. By default, output goes to stdout.
  -c, --colors          Display colors if the terminal supports it. Requires
                        'colorama' python package. Use 'pip install colorama'
                        to install it.
  -d DEPTH, --depth DEPTH
                        Max depth of tree to display.
  -a ATTRS, --attr ATTRS
                        Add an attribute to search for in tree systems.
                        Add a variable to search for in vectors of tree
  -r RANK, --rank RANK  Display the tree on this rank (if MPI is active).


Several of the example commands below make use of a file This file is located in the openmdao/test_suite/scripts directory.

Post-setup Commands

The following commands all register a function that will run at the end of a Problem’s final_setup function. After the registered function completes, the program will exit, rather than continuing to the end of the user’s run script. This makes it convenient to view or check the configuration of a model in any run script without having to wait around for the entire script to run.

openmdao check

The openmdao check command will perform a number of checks on a model and display errors, warnings, or informational messages describing what it finds. Some of the available checks are unconnected_inputs, which lists any input variables that are not connected, and out_of_order, which displays any systems that are being executed out-of-order. You can supply individual checks on the command line using -c args. For example:

openmdao check -c cycles

Otherwise, a set of default checks will be done. To see lists of the available and default checks, run the following command:

openmdao check -h
usage: openmdao check [-h] [-o OUTFILE] [-c CHECKS] file

positional arguments:
  file        Python file containing the model.

optional arguments:
  -h, --help  show this help message and exit
  -o OUTFILE  output file.
  -c CHECKS   Only perform specific check(s). Default checks are:
              ['comp_has_no_outputs', 'dup_inputs', 'missing_recorders',
              'out_of_order', 'solvers', 'system']. Other available checks
              are: ['cycles', 'promotions', 'unconnected_inputs'].

openmdao n2

The openmdao n2 command will generate an \(N^2\) diagram of the model that is viewable in a browser, for example:

openmdao n2

will generate an \(N^2\) diagram like the one below.

openmdao view_connections

The openmdao view_connections command generates a table of connection information for all input and output variables in the model. Its primary purpose is to help debug a model by making the following things easier:

  • Identifying unconnected inputs

  • Highlighting unit conversions or missing units

  • Identifying missing or unwanted implicit connections

The table can be sorted by any column by clicking on the column header, and a column can be filtered by typing text into the ‘filter column’ field found at the top of each column. Also, any column can be shown or hidden using the toggle buttons at the bottom of the table. When input and output units differ, they are highlighted in red. In the promoted input and output columns, variables that are promoted at some level in the model are shown in blue, while variables that are never promoted are shown in black.

Below is an example of a connection viewer for a pycycle propulsor model obtained using the command:

openmdao view_connections
An example of a connection viewer

An example of a connection viewer.

By default the promoted names columns of both inputs and outputs are shown, but in the example above, the absolute input names are shown and the promoted input names are hidden.

Unconnected inputs can easily be identified by typing ‘[NO CONNECTION]’ or ‘[‘, into the filter field of either the absolute or promoted output column. Unconnected outputs can be shown similarly by typing ‘[NO CONNECTION]’ or ‘[‘ into the filter field of either the absolute or promoted input column.

When showing promoted output and promoted input columns, if the promoted output name equals the promoted input name, that means the connection is an implicit connection. Otherwise the connection is explicit, meaning somewhere in the model there is an explicit call to connect that producted the connection.

In OpenMDAO, multiple inputs can be promoted to the same name, and by sorting the promoted inputs column, all such inputs will be grouped together. This can make it much easier to spot either missing or unwanted implicit connections.

openmdao tree

The openmdao tree command prints an indented list of all systems in the model tree. Each system’s type and name are shown, along with size of their inputs and outputs, and their linear and nonlinear solvers if they differ from the defaults, which are LinearRunOnce and NonlinearRunOnce respectively. If the -c option is used, the tree will print in color if the terminal supports it and the colorama package is installed. If colors are used, implicit and explicit components will be displayed using different colors.

The tree command also allows specific attributes and/or vector variables to be printed out along with their corresponding system in the tree.

Here’s an example of the tree output for a simple circuit model:

openmdao tree
Driver: Driver
    Group  (11 / 7)
        IndepVarComp ground (0 / 1)
        IndepVarComp source (0 / 1)
        Circuit circuit (11 / 5)  LN: DirectSolver  NL: NewtonSolver Jac: CSCJacobian
            Node n1 (3 / 1)  APPROX: ['fd'] (3 of 3)
            Node n2 (2 / 1)  APPROX: ['fd'] (2 of 2)
            Resistor R1 (2 / 1)  APPROX: ['fd'] (2 of 3)
            Resistor R2 (2 / 1)  APPROX: ['fd'] (2 of 3)
            Diode D1 (2 / 1)  APPROX: ['fd'] (2 of 3)

openmdao summary

The openmdao summary command prints a high level summary of the model. For example:

openmdao summary
============== Problem Summary ============
Groups:               2
Components:           7
Max tree depth:       2

Design variables:            2   Total size:        2

Nonlinear Constraints:       0   Total size:        0
    equality:                0                      0
    inequality:              0                      0

Linear Constraints:          0   Total size:        0
    equality:                0                      0
    inequality:              0                      0

Objectives:                  1   Total size:        1

Input variables:            11   Total size:       11
Output variables:            7   Total size:        7

Total connections: 11   Total transfer data size: 11

Driver type: Driver
Linear Solvers: [LinearRunOnce, DirectSolver]
Nonlinear Solvers: [NonlinearRunOnce, NewtonSolver]

openmdao cite

The openmdao cite command prints citations for any classes in the model that have them. It supports optional -c arguments to allow you to limit displayed citations to only those belonging to a particular class or group of classes. By default, all citations for any class used in the problem will be displayed. For example:

openmdao cite
Class: <class 'openmdao.core.problem.Problem'>
        Author={Justin S. Gray and John T. Hwang and Joaquim R. R. A.
                Martins and Kenneth T. Moore and Bret A. Naylor},
        Title="{OpenMDAO: An Open-Source Framework for Multidisciplinary
                Design, Analysis, and Optimization}",
        Journal="{Structural and Multidisciplinary Optimization}",
        note= {In Press}

Profiling and Tracing Commands

The following commands perform profiling or tracing on a run script, filtering their target functions based on pre-defined groups of functions that can be displayed using the -h command line option. For example, here’s the usage output for the openmdao trace command, which includes the function groups available at the time of this writing:

usage: openmdao trace [-h] [-g METHODS] [-v] file

positional arguments:
  file                  Python file to be traced.

optional arguments:
  -h, --help            show this help message and exit
  -g METHODS, --group METHODS
                        Determines which group of methods will be traced.
                        Default is "openmdao". Options are: ['dataflow',
                        'linear', 'mpi', 'openmdao', 'openmdao_all', 'setup']
  -v, --verbose         Show function locals and return values.

openmdao iprof

The openmdao iprof command will display an icicle plot showing the time elapsed in all of the target methods corresponding to each object instance that they were called on. For more details, see Instance-based Profiling.

openmdao iprof_totals

The openmdao iprof_totals command performs the same profiling as openmdao iprof, but it outputs a simple, text-based summary of the total time spent in each method. The Instance-based Profiling section contains more details.

openmdao trace

The openmdao trace command prints a call trace for a specified set of functions. Optionally it can display values of function locals and return values. For more detail, see Instance-based Call Tracing.

Memory Profiling

openmdao mem

The openmdao mem command profiles the memory usage of python functions. For more detail, see Memory Profiling.

openmdao mempost

The openmdao mempost postprocesses the raw memory dump file generated by openmdao mem. For more detail, see Memory Profiling.

Other Commands

openmdao call_tree

The openmdao call_tree command takes the full module path of a class method and displays the call tree for that method. It’s purpose is to show which class ‘owns’ the specified method call and any other ‘self.*’ methods that it calls. Note that it shows all of the methods called, regardless of the result of conditionals within any function, so the displayed tree does not necessarily represent a trace of the function as it executes. The functions are ordered top to bottom as they are encountered in the source code, and a given subfunction is only displayed once within a given function, even if it is actually called in multiple places within the function. Here’s an example:

openmdao call_tree openmdao.api.LinearBlockGS.solve

openmdao scaffold

The openmdao scaffold command generates simple scaffolding, or ‘skeleton’ code for an explicit or implicit component. In addition, it will generate the scaffolding for a simple test file of that component. The available options are as follows:

openmdao scaffold -h
usage: openmdao scaffold [-h] -c CLASS_NAME [-e] [-i] [file]

positional arguments:
  file                  output file.

optional arguments:
  -h, --help            show this help message and exit
                        Name of the component class. If an output file is not
                        provided, this name will be used to generate the
                        output file name.
  -e, --explicit        Generate an ExplicitComponent.
  -i, --implicit        Generate an ImplicitComponent.

This command is only an initial attempt to provide this sort of functionality and any user feedback describing how to improve it is welcome.

Using Commands under MPI

In general, usage of openmdao subcommands under MPI is the same as usual, except the command will be preceded by mpirun -n <num_procs>. For example:

mpirun -n 2 openmdao summary
============== Problem Summary ============
Groups:               4
Components:          10
Max tree depth:       3

Design variables:            1   Total size:        5

Nonlinear Constraints:       1   Total size:        1
    equality:                1                      1
    inequality:              0                      0

Linear Constraints:          0   Total size:        0
    equality:                0                      0
    inequality:              0                      0

Objectives:                  1   Total size:        1

Input variables:            10   Total size:     1961
Output variables:           10   Total size:     1117

Total connections: 10   Total transfer data size: 1961

Driver type: ScipyOptimizeDriver
Linear Solvers: [LinearRunOnce x 4]
Nonlinear Solvers: [NonlinearRunOnce x 4]