Getting Started#

Installation Instructions:

From your python environment (we recommend Anaconda), just type:

pip install 'openmdao[all]'

Note

The [all] suffix to the install command ensures that you get all the optional dependencies (e.g. for testing and visualization). You can omit this for a minimal installation.

The quotation marks are required to prevent some command shells (e.g. zsh) from trying to interpret the square brackets.

Alternatively, in a Jupyter notebook environment such as Google Colab, you can install OpenMDAO by running the above as a shell command (precede it with !).

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.

Parallel Processing with MPI#

OpenMDAO enables parallel processing via MPI and PETSc. The easiest way to install support for these is to use conda:

conda create -n OpenMDAO python=3
conda activate OpenMDAO
conda install -c conda-forge mpi4py petsc4py
pip install openmdao[all]

For Windows users, installing PETSc can be more difficult as described on the PETSc web site. Probably the quickest way to get up and running with MPI on Windows is to use Windows Subsystem for Linux (WSL2). WSL integration with Visual Studio Code provides a nearly seamless development environment on Windows.

Sample Optimization File#

With OpenMDAO installed, let’s try out a simple example, to get you started running your first optimization. Copy the following code into a file named paraboloid_min.py:

import openmdao.api as om

# 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();
Hide code cell output
Optimization terminated successfully    (Exit mode 0)
            Current function value: -27.33333333333333
            Iterations: 5
            Function evaluations: 6
            Gradient evaluations: 5
Optimization Complete
-----------------------------------

Then, to run the file, simply type:

>> python paraboloid_min.py

If all works as planned, results should appear as such:

Hide code cell source
import openmdao.api as om

# 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();
Optimization terminated successfully    (Exit mode 0)
            Current function value: -27.33333333333333
            Iterations: 5
            Function evaluations: 6
            Gradient evaluations: 5
Optimization Complete
-----------------------------------