Installation Instructions

Conda

Conda packages are available on conda-forge and can be installed via

conda install -c conda-forge pyoptsparse

This would install pyOptSparse with the built-in optimizers, as well as IPOPT. If you wish to use optimizers not packaged by conda, e.g. SNOPT, then you must build the package from source.

Building from source

Requirements

pyOptSparse has the following dependencies:

  • Python 3.7 or 3.8, though other Python 3 versions will likely work

  • C and Fortran compilers. We recommend gcc and gfortran which can be installed via the package manager for your operating system.

Please make sure these are installed and available for use. In order to use NSGA2, SWIG (v1.3+) is also required, which can be installed via the package manager. If those optimizers are not needed, then you do not need to install SWIG. Simply comment out the corresponding lines in pyoptsparse/pyoptsparse/setup.py so that they are not compiled. The corresponding lines in pyoptsparse/pyoptsparse/__init__.py must be commented out as well.

Python dependencies are automatically handled by pip, so they do not need to be installed separately. The only exception is numpy, which is required as part of the build process and therefore must be present before installing.

Note

  • In Linux, the python header files (python-dev) are also required.

  • We do not support operating systems other than Linux. For macOS users, the conda package may work out of the box if you do not need any non-default optimizers. For Windows users, a conda package is on the way, if it’s not already in the repos. This comes with the same disclaimer as the macOS conda package. Alternatively, follow the conda build instructions below as this will work on any platform.

Installation

The easiest and recommended way to install pyOptSparse is with pip. First clone the repository into a location which is not on the $PYTHONPATH, for example $HOME/packages/. Then in the root pyoptsparse folder type

pip install .

For those not using virtual environments, a user install may be needed

pip install . --user

If you plan to modify pyOptSparse, installing with the developer option, i.e. with -e, will save you from re-installing each time you modify the Python code.

Note

Some optimizers are proprietary, and their sources are not distributed with pyOptSparse. To use them, please follow the instructions on specific optimizer pages.

Specifying compilers

To specify a non-default compiler (e.g. something other than /usr/bin/gcc), meson recognizes certain special environment variables. For example, to specify the Intel compilers, simply run

FC=$(which ifort) CC=$(which icc) pip install .

Installing OptView

OptView and OptView-Dash have separate dependencies that must be installed. To install pyOptSparse including those dependencies, run

pip install .[optview]

Testing

pyOptSparse provides a set of unit and regression tests to verify the installation. To run these tests, first install testflo which is a testing framework developed by the OpenMDAO team:

pip install testflo

Then, in the project root directory, type:

testflo . -v

to run all tests.

Update or Uninstall

To update pyOptSparse, first delete the meson_build directory, then update the package using git. For stability, users are encouraged to stick to tagged releases. Install the package normally via pip.

To uninstall the package, type

pip uninstall pyoptsparse

Conda Build Instructions

The following instructions explain how to build and install pyOptSparse in a conda environment. This has the advantage that conda can be used to install all the necessary dependencies in an isolated and reproducible environment. Considering how finicky Windows can be with ABI compatibility among various compilers, this is the recommended approach. The guide will work on any platform, however.

The only build requirement for the build is a working conda installation as all compilers and dependencies are pulled from the conda-forge repos, with the exception of a Windows build, which requires Visual Studio 2017 C++ Build Tools.

First, we need to create the conda environment. An environment.yml file is provided in the pyoptsparse repo:

conda create -y -n pyos-build
conda activate pyos-build
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict

conda env update -f .github/environment.yml

Next, we need to tell the compiler where to find IPOPT:

export IPOPT_DIR="$CONDA_PREFIX"

Finally, build the wheel and install it using pip:

# build wheel
python -m build -n -x .

# install wheel
pip install --no-deps --no-index --find-links dist pyoptsparse