Skip to content

Commit e3b9417

Browse files
ewu63kanekosh
andauthored
Switch to cyipopt (#425)
* very preliminary attempt with cyipoptcore * clean up meson.build * remove old ipopt bindings * fix unsized array * make cyipopt optional * update build system * set PKG_CONFIG_PATH * format * get rid of IPOPT_DIR * PKG_CONFIG_PATH * update docs * return array of nans under analysis failure * added tests to check eval failure * only test SNOPT and IPOPT in func eval failure test * clean up meson.build again * typo --------- Co-authored-by: kanekosh <[email protected]>
1 parent 7952e1c commit e3b9417

15 files changed

+145
-1735
lines changed

.github/build_real.sh

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ fi
1111
mv ~/.config/pip/constraints.txt ~/.config/pip/constraints.txt.bkup
1212
touch ~/.config/pip/constraints.txt
1313

14+
# set $PKG_CONFIG_PATH so pkg-config can find ipopt
15+
# only necessary if IPOPT is installed outside of conda
16+
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$IPOPT_DIR/lib/pkgconfig
17+
1418
pip install .[optview,testing] -v
1519

1620
# move pip constraints file back

.github/environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ dependencies:
22
# build
33
- python >=3.9
44
- numpy >=2.0
5-
- ipopt
65
- swig
76
- meson >=1.3.2
87
- compilers
@@ -17,6 +16,7 @@ dependencies:
1716
- mdolab-baseclasses >=1.3.1
1817
- scipy >=1.7
1918
- sqlitedict >=1.6
19+
- cyipopt
2020
# testing
2121
- parameterized
2222
- testflo

.github/windows.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
displayName: Install mamba and update environment
2828
2929
- script: |
30-
set IPOPT_DIR=%CONDA_PREFIX%\Library
3130
set CC=cl
3231
set FC=flang
3332
set CC_LD=link

.github/workflows/windows-build.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
numpy_version: ["1.21.6", "1.25.2"]
18+
numpy_version: ["1.21.6", "1.25.2", "2.1.3"]
1919
steps:
2020
- uses: actions/checkout@v4
2121
- uses: conda-incubator/setup-miniconda@v3
@@ -39,8 +39,6 @@ jobs:
3939
:: set fortran compiler, flang 5 activation doesn't seem to do it
4040
set FC=flang.exe
4141
42-
set MESON_ARGS=-Dipopt_dir=%CONDA_PREFIX%\Library\
43-
4442
python -m build -n -x .
4543
4644
pip install --no-deps --no-index --find-links dist pyoptsparse

doc/install.rst

-13
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,6 @@ An ``environment.yml`` file is provided in the ``pyoptsparse`` repo:
184184
conda config --env --set channel_priority strict
185185

186186
conda env update -f .github\environment.yml
187-
conda install libpgmath
188-
189-
Next, we need to tell the compiler where to find IPOPT:
190-
191-
.. tabs::
192-
193-
.. code-tab:: bash Linux/OSX
194-
195-
export IPOPT_DIR="$CONDA_PREFIX"
196-
197-
.. code-tab:: powershell Windows
198-
199-
set IPOPT_DIR=%CONDA_PREFIX%\Library
200187

201188
Finally, build the wheel and install it using pip:
202189

doc/optimizers/IPOPT.rst

+5-62
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,14 @@ IPOPT
44
=====
55
IPOPT (Interior Point OPTimizer) is an open source interior point optimizer, designed for large-scale nonlinear optimization.
66
The source code can be found `here <https://www.coin-or.org/download/source/Ipopt/>`_.
7-
The latest version we support is 3.13.2.
7+
The latest version we support is 3.14.17.
88

99
Installation
1010
------------
11-
IPOPT must be installed separately, then linked to pyOptSparse when building.
12-
For the full installation instructions, please see `their documentation <https://coin-or.github.io/Ipopt/INSTALL.html>`_.
13-
OpenMDAO also has a very helpful `script <https://github.com/OpenMDAO/build_pyoptsparse/>`_ which can be used to install IPOPT with other linear solvers.
14-
Here we explain a basic setup using MUMPS as the linear solver, together with METIS adapted from the OpenMDAO script.
15-
16-
#. Download the tarball and extract it to ``$IPOPT_DIR`` which could be set to for example ``$HOME/packages/Ipopt``.
17-
18-
#. Install METIS, which can be used to improve the performance of the MUMPS linear solver.
19-
20-
.. code-block:: bash
21-
22-
# build METIS
23-
cd $IPOPT_DIR
24-
git clone https://github.com/coin-or-tools/ThirdParty-Metis.git
25-
cd ThirdParty-Metis
26-
./get.Metis
27-
./configure --prefix=$IPOPT_DIR
28-
make
29-
make install
30-
31-
#. Install MUMPS
32-
33-
.. code-block:: bash
34-
35-
# build MUMPS
36-
cd $IPOPT_DIR
37-
git clone https://github.com/coin-or-tools/ThirdParty-Mumps.git
38-
cd ThirdParty-Mumps
39-
./get.Mumps
40-
./configure --with-metis --with-metis-lflags="-L${IPOPT_DIR}/lib -lcoinmetis" \
41-
--with-metis-cflags="-I${IPOPT_DIR}/include -I${IPOPT_DIR}/include/coin-or -I${IPOPT_DIR}/include/coin-or/metis" \
42-
--prefix=$IPOPT_DIR CFLAGS="-I${IPOPT_DIR}/include -I${IPOPT_DIR}/include/coin-or -I${IPOPT_DIR}/include/coin-or/metis" \
43-
FCFLAGS="-I${IPOPT_DIR}/include -I${IPOPT_DIR}/include/coin-or -I${IPOPT_DIR}/include/coin-or/metis"
44-
make
45-
make install
46-
47-
#. Build IPOPT
48-
49-
.. code-block:: bash
50-
51-
# build IPOPT
52-
cd $IPOPT_DIR
53-
mkdir build
54-
cd build
55-
../configure --prefix=${IPOPT_DIR} --disable-java --with-mumps --with-mumps-lflags="-L${IPOPT_DIR}/lib -lcoinmumps" \
56-
--with-mumps-cflags="-I${IPOPT_DIR}/include/coin-or/mumps"
57-
make
58-
make install
59-
60-
#. You must add the IPOPT library path to the ``LD_LIBRARY_PATH`` variable for things to work right.
61-
This could be done for example by adding the following to your ``.bashrc``:
62-
63-
.. code-block:: bash
64-
65-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$IPOPT_DIR/lib
66-
67-
Furthermore, the environment variable ``$IPOPT_DIR`` must be set correctly in order to link to pyOptSparse.
68-
Alternatively, you can manually define the variables ``$IPOPT_LIB`` and ``$IPOPT_INC`` for the lib and include paths separately.
69-
70-
71-
#. Now clean build pyOptSparse. Verify that IPOPT works by running the relevant tests.
11+
IPOPT and its Python interface `cyipopt <https://github.com/mechmotum/cyipopt>` must be installed separately.
12+
Follow the instructions `here <https://cyipopt.readthedocs.io/en/stable/install.html>`_.
13+
OpenMDAO also has a very helpful `script <https://github.com/OpenMDAO/build_pyoptsparse/>`_ which can be used to install IPOPT with other linear solvers,
14+
but it does not install ``cyipopt`` for you.
7215

7316
Options
7417
-------

meson_options.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
option('ipopt_dir', type: 'string', value: '',
2-
description: 'Top-level dir for ipopt')
3-
41
option('incdir_numpy', type: 'string', value: '',
52
description: 'Include directory for numpy. If left empty Meson will try to find it on its own.')
63

pyoptsparse/meson.build

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ inc_f2py = include_directories(incdir_f2py)
6666
#)
6767

6868
subdir('pySNOPT')
69-
subdir('pyIPOPT')
7069
subdir('pySLSQP')
7170
subdir('pyCONMIN')
7271
subdir('pyNLPQLP')

pyoptsparse/pyIPOPT/meson.build

+5-55
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,10 @@
1-
fs = import('fs')
2-
3-
if get_option('ipopt_dir') != '' or fs.is_dir('Ipopt')
4-
5-
ipopt_dir = ''
6-
7-
if get_option('ipopt_dir') != ''
8-
ipopt_dir = get_option('ipopt_dir')
9-
elif fs.is_dir('Ipopt')
10-
ipopt_dir = fs.is_dir('Ipopt')
11-
endif
12-
13-
ipopt_lib = []
14-
ipopt_idir = ''
15-
16-
# Ipopt installs differently on some systems (i.e. Fedora)
17-
if fs.is_dir(ipopt_dir / 'lib')
18-
ipopt_lib = [ipopt_dir / 'lib']
19-
elif fs.is_dir(ipopt_dir / 'lib64')
20-
ipopt_lib = [ipopt_dir / 'lib64']
21-
endif
22-
23-
24-
if fs.is_dir(ipopt_dir / 'include' / 'coin-or')
25-
ipopt_idir = ipopt_dir / 'include' / 'coin-or'
26-
elif fs.is_dir(ipopt_dir / 'include' / 'coin')
27-
ipopt_idir = ipopt_dir / 'include' / 'coin'
28-
endif
29-
30-
ipopt_dep = cc.find_library('ipopt-3', required: false, dirs: ipopt_lib) # only relevant on windows
31-
if not ipopt_dep.found()
32-
ipopt_dep = cc.find_library('ipopt', required: true, dirs: ipopt_lib)
33-
endif
34-
35-
if fs.is_dir(ipopt_idir)
36-
ipopt_inc = include_directories(ipopt_idir)
37-
else
38-
error('IPOPT include directory not found: ', ipopt_dir)
39-
endif
40-
41-
py3_target.extension_module('pyipoptcore',
42-
'src/callback.c',
43-
'src/pyipoptcoremodule.c',
44-
include_directories: [inc_np, 'src', ipopt_inc],
45-
dependencies : [py3_dep, ipopt_dep],
46-
subdir: 'pyoptsparse/pyIPOPT',
47-
link_language: 'c',
48-
install : false)
49-
endif
50-
51-
#python_sources = [
1+
# python_sources = [
522
# '__init__.py',
533
# 'pyIPOPT.py',
54-
#]
55-
#
56-
#py3_target.install_sources(
4+
# ]
5+
6+
# py3_target.install_sources(
577
# python_sources,
588
# pure: false,
599
# subdir: 'pyoptsparse/pyIPOPT'
60-
#)
10+
# )

0 commit comments

Comments
 (0)