mechmotum / cyipopt

Cython interface for the interior point optimzer IPOPT
Eclipse Public License 2.0
227 stars 54 forks source link

Changes for the upcoming NumPy 2.0 #253

Closed moorepants closed 1 week ago

moorepants commented 3 months ago

NumPy 2.0 will break ABI compatibility.

https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-abi-handling

https://numpy.org/devdocs/numpy_2_0_migration_guide.html

Looks like we should start with an upper bound numpy < 2.0 because our binaries that we build against NumPy 1 will not work with NumPy 2.0.

moorepants commented 3 months ago

cyipopt builds successfully against NumPy 2.0 release candidate here: https://github.com/conda-forge/cyipopt-feedstock/pull/57 so maybe we don't need to do anything. That is the only binary we currently release.

moorepants commented 1 week ago

The conda forge package for cyipopt 1.4.1 was built against NumPy 2 and works with both NumPy 1 and 2.

moorepants@nandi:cyipopt(master)$ conda create -n cyipopt-num2 "numpy>2" cyipopt
Channels:
 - conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/moorepants/miniconda/envs/cyipopt-num2

  added / updated specs:
    - cyipopt
    - numpy[version='>2']

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _libgcc_mutex-0.1          |      conda_forge           3 KB  conda-forge
    _openmp_mutex-4.5          |            2_gnu          23 KB  conda-forge
    libblas-3.9.0              |23_linux64_openblas          15 KB  conda-forge
    libcblas-3.9.0             |23_linux64_openblas          14 KB  conda-forge
    libgcc-ng-14.1.0           |       h69a702a_1          51 KB  conda-forge
    libgfortran-14.1.0         |       h69a702a_1          51 KB  conda-forge
    libgfortran-ng-14.1.0      |       h69a702a_1          51 KB  conda-forge
    liblapack-3.9.0            |23_linux64_openblas          14 KB  conda-forge
    libstdcxx-ng-14.1.0        |       h4852527_1          51 KB  conda-forge
    numpy-2.1.0                |  py312h1103770_0         8.0 MB  conda-forge
    python-3.12.5              |h2ad013b_0_cpython        30.2 MB  conda-forge
    python_abi-3.12            |          5_cp312           6 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        38.4 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge 
  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-2_gnu 
  ampl-mp            conda-forge/linux-64::ampl-mp-3.1.0-h2cc385e_1006 
  bzip2              conda-forge/linux-64::bzip2-1.0.8-h4bc722e_7 
  ca-certificates    conda-forge/linux-64::ca-certificates-2024.7.4-hbcca054_0 
  cyipopt            conda-forge/linux-64::cyipopt-1.4.1-py312hfd7c8c3_3 
  icu                conda-forge/linux-64::icu-75.1-he02047a_0 
  ipopt              conda-forge/linux-64::ipopt-3.14.16-h3696c94_4 
  ld_impl_linux-64   conda-forge/linux-64::ld_impl_linux-64-2.40-hf3520f5_7 
  libblas            conda-forge/linux-64::libblas-3.9.0-23_linux64_openblas 
  libcblas           conda-forge/linux-64::libcblas-3.9.0-23_linux64_openblas 
  libedit            conda-forge/linux-64::libedit-3.1.20191231-he28a2e2_2 
  libexpat           conda-forge/linux-64::libexpat-2.6.2-h59595ed_0 
  libffi             conda-forge/linux-64::libffi-3.4.2-h7f98852_5 
  libgcc             conda-forge/linux-64::libgcc-14.1.0-h77fa898_1 
  libgcc-ng          conda-forge/linux-64::libgcc-ng-14.1.0-h69a702a_1 
  libgfortran        conda-forge/linux-64::libgfortran-14.1.0-h69a702a_1 
  libgfortran-ng     conda-forge/linux-64::libgfortran-ng-14.1.0-h69a702a_1 
  libgfortran5       conda-forge/linux-64::libgfortran5-14.1.0-hc5f4f2c_1 
  libgomp            conda-forge/linux-64::libgomp-14.1.0-h77fa898_1 
  libhwloc           conda-forge/linux-64::libhwloc-2.11.1-default_hecaa2ac_1000 
  libiconv           conda-forge/linux-64::libiconv-1.17-hd590300_2 
  liblapack          conda-forge/linux-64::liblapack-3.9.0-23_linux64_openblas 
  libnsl             conda-forge/linux-64::libnsl-2.0.1-hd590300_0 
  libopenblas        conda-forge/linux-64::libopenblas-0.3.27-pthreads_hac2b453_1 
  libscotch          conda-forge/linux-64::libscotch-7.0.4-h2fe6a88_5 
  libspral           conda-forge/linux-64::libspral-2024.05.08-h831f25b_3 
  libsqlite          conda-forge/linux-64::libsqlite-3.46.0-hde9e2c9_0 
  libstdcxx          conda-forge/linux-64::libstdcxx-14.1.0-hc0a3c3a_1 
  libstdcxx-ng       conda-forge/linux-64::libstdcxx-ng-14.1.0-h4852527_1 
  libuuid            conda-forge/linux-64::libuuid-2.38.1-h0b41bf4_0 
  libxcrypt          conda-forge/linux-64::libxcrypt-4.4.36-hd590300_1 
  libxml2            conda-forge/linux-64::libxml2-2.12.7-he7c6b58_4 
  libzlib            conda-forge/linux-64::libzlib-1.3.1-h4ab18f5_1 
  metis              conda-forge/linux-64::metis-5.1.0-h59595ed_1007 
  mumps-include      conda-forge/linux-64::mumps-include-5.7.2-ha770c72_0 
  mumps-seq          conda-forge/linux-64::mumps-seq-5.7.2-h6e8dedb_0 
  ncurses            conda-forge/linux-64::ncurses-6.5-he02047a_1 
  numpy              conda-forge/linux-64::numpy-2.1.0-py312h1103770_0 
  openssl            conda-forge/linux-64::openssl-3.3.1-hb9d3cd8_3 
  pip                conda-forge/noarch::pip-24.2-pyhd8ed1ab_0 
  python             conda-forge/linux-64::python-3.12.5-h2ad013b_0_cpython 
  python_abi         conda-forge/linux-64::python_abi-3.12-5_cp312 
  readline           conda-forge/linux-64::readline-8.2-h8228510_1 
  setuptools         conda-forge/noarch::setuptools-72.2.0-pyhd8ed1ab_0 
  tk                 conda-forge/linux-64::tk-8.6.13-noxft_h4845f30_101 
  tzdata             conda-forge/noarch::tzdata-2024a-h8827d51_1 
  unixodbc           conda-forge/linux-64::unixodbc-2.3.12-h661eb56_0 
  wheel              conda-forge/noarch::wheel-0.44.0-pyhd8ed1ab_0 
  xz                 conda-forge/linux-64::xz-5.2.6-h166bdaf_0 
  zlib               conda-forge/linux-64::zlib-1.3.1-h4ab18f5_1 

Downloading and Extracting Packages:

Preparing transaction: done                                                                                                                                                                   
Verifying transaction: done                                                                                                                                                                   
Executing transaction: done                                                                                                                                                                   
#                                                                                                                                                                                             
# To activate this environment, use                                                                                                                                                           
#                                                                                                                                                                                             
#     $ conda activate cyipopt-num2                                                                                                                                                           
#                                                                                                                                                                                             
# To deactivate an active environment, use                                                                                                                                                    
#                                                                                                                                                                                             
#     $ conda deactivate                                                                                                                                                                      

moorepants@nandi:cyipopt(master)$ act cyipopt-num2 
(cyipopt-num2) moorepants@nandi:cyipopt(master)$ cd examples/
(cyipopt-num2) moorepants@nandi:examples(master)$ python hs071.py 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

This is Ipopt version 3.14.16, running with linear solver MUMPS 5.7.2.

Number of nonzeros in equality constraint Jacobian...:        4
Number of nonzeros in inequality constraint Jacobian.:        4
Number of nonzeros in Lagrangian Hessian.............:       10

Total number of variables............................:        4
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        4
                     variables with only upper bounds:        0
Total number of equality constraints.................:        1
Total number of inequality constraints...............:        1
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

Objective value at iteration #0 is - 16.1097
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.6109693e+01 1.12e+01 1.02e+00   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
Objective value at iteration #1 is - 17.3461
   1  1.7346108e+01 7.50e-01 2.37e+01  -0.3 7.22e-01    -  3.51e-01 1.00e+00f  1
Objective value at iteration #2 is - 17.9222
   2  1.7922201e+01 7.70e-03 5.29e+00  -0.2 6.00e-02   2.0 9.96e-01 1.00e+00h  1
Objective value at iteration #3 is - 17.1673
   3  1.7167308e+01 6.72e-02 1.66e+00  -0.8 1.37e+00    -  9.95e-01 6.98e-01f  1
Objective value at iteration #4 is - 16.9893
   4  1.6989299e+01 1.02e-01 1.47e-01  -1.2 2.30e-01    -  9.92e-01 1.00e+00f  1
Objective value at iteration #5 is - 16.9944
   5  1.6994402e+01 3.39e-02 1.19e-02  -2.3 8.69e-02    -  9.84e-01 1.00e+00h  1
Objective value at iteration #6 is - 17.014
   6  1.7013957e+01 2.20e-04 3.14e-04  -3.8 1.15e-02    -  9.99e-01 1.00e+00h  1
Objective value at iteration #7 is - 17.014
   7  1.7014017e+01 6.30e-07 1.31e-06  -9.7 3.43e-04    -  9.99e-01 9.99e-01h  1
Objective value at iteration #8 is - 17.014
   8  1.7014017e+01 5.68e-13 8.43e-13 -11.0 5.69e-07    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 8

                                   (scaled)                 (unscaled)
Objective...............:   3.4028034280427242e+01    1.7014017140213621e+01
Dual infeasibility......:   8.4300285623552048e-13    4.2150142811776024e-13
Constraint violation....:   5.6843418860808015e-13    5.6843418860808015e-13
Variable bound violation:   9.9952566223748818e-09    9.9952566223748818e-09
Complementarity.........:   1.1688338036422999e-11    5.8441690182114995e-12
Overall NLP error.......:   1.1688338036422999e-11    5.8441690182114995e-12

Number of objective function evaluations             = 9
Number of objective gradient evaluations             = 9
Number of equality constraint evaluations            = 9
Number of inequality constraint evaluations          = 9
Number of equality constraint Jacobian evaluations   = 9
Number of inequality constraint Jacobian evaluations = 9
Number of Lagrangian Hessian evaluations             = 8
Total seconds in IPOPT                               = 0.010

EXIT: Optimal Solution Found.
Solution of the primal variables: x=array([0.99999999, 4.74299964, 3.82114998, 1.37940829])

Solution of the dual variables: lambda=array([-0.55229366,  0.16146856])

Objective=17.01401714021362

(cyipopt-num2) moorepants@nandi:examples(master)$ conda list cyipopt
# packages in environment at /home/moorepants/miniconda/envs/cyipopt-num2:
#
# Name                    Version                   Build  Channel
cyipopt                   1.4.1           py312hfd7c8c3_3    conda-forge
(cyipopt-num2) moorepants@nandi:examples(master)$ conda list numpy
# packages in environment at /home/moorepants/miniconda/envs/cyipopt-num2:
#
# Name                    Version                   Build  Channel
numpy                     2.1.0           py312h1103770_0    conda-forge
(cyipopt-num2) moorepants@nandi:examples(master)$ deact
moorepants@nandi:examples(master)$ condarm cyipopt-num2 

Remove all packages in environment /home/moorepants/miniconda/envs/cyipopt-num2:

moorepants@nandi:examples(master)$ conda create -n cyipopt-num1 "numpy<2" cyipopt
Channels:
 - conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/moorepants/miniconda/envs/cyipopt-num1

  added / updated specs:
    - cyipopt
    - numpy[version='<2']

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    numpy-1.26.4               |  py312heda63a1_0         7.1 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         7.1 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge 
  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-2_gnu 
  ampl-mp            conda-forge/linux-64::ampl-mp-3.1.0-h2cc385e_1006 
  bzip2              conda-forge/linux-64::bzip2-1.0.8-h4bc722e_7 
  ca-certificates    conda-forge/linux-64::ca-certificates-2024.7.4-hbcca054_0 
  cyipopt            conda-forge/linux-64::cyipopt-1.4.1-py312hfd7c8c3_3 
  icu                conda-forge/linux-64::icu-75.1-he02047a_0 
  ipopt              conda-forge/linux-64::ipopt-3.14.16-h3696c94_4 
  ld_impl_linux-64   conda-forge/linux-64::ld_impl_linux-64-2.40-hf3520f5_7 
  libblas            conda-forge/linux-64::libblas-3.9.0-23_linux64_openblas 
  libcblas           conda-forge/linux-64::libcblas-3.9.0-23_linux64_openblas 
  libedit            conda-forge/linux-64::libedit-3.1.20191231-he28a2e2_2 
  libexpat           conda-forge/linux-64::libexpat-2.6.2-h59595ed_0 
  libffi             conda-forge/linux-64::libffi-3.4.2-h7f98852_5 
  libgcc             conda-forge/linux-64::libgcc-14.1.0-h77fa898_1 
  libgcc-ng          conda-forge/linux-64::libgcc-ng-14.1.0-h69a702a_1 
  libgfortran        conda-forge/linux-64::libgfortran-14.1.0-h69a702a_1 
  libgfortran-ng     conda-forge/linux-64::libgfortran-ng-14.1.0-h69a702a_1 
  libgfortran5       conda-forge/linux-64::libgfortran5-14.1.0-hc5f4f2c_1 
  libgomp            conda-forge/linux-64::libgomp-14.1.0-h77fa898_1 
  libhwloc           conda-forge/linux-64::libhwloc-2.11.1-default_hecaa2ac_1000 
  libiconv           conda-forge/linux-64::libiconv-1.17-hd590300_2 
  liblapack          conda-forge/linux-64::liblapack-3.9.0-23_linux64_openblas 
  libnsl             conda-forge/linux-64::libnsl-2.0.1-hd590300_0 
  libopenblas        conda-forge/linux-64::libopenblas-0.3.27-pthreads_hac2b453_1 
  libscotch          conda-forge/linux-64::libscotch-7.0.4-h2fe6a88_5 
  libspral           conda-forge/linux-64::libspral-2024.05.08-h831f25b_3 
  libsqlite          conda-forge/linux-64::libsqlite-3.46.0-hde9e2c9_0 
  libstdcxx          conda-forge/linux-64::libstdcxx-14.1.0-hc0a3c3a_1 
  libstdcxx-ng       conda-forge/linux-64::libstdcxx-ng-14.1.0-h4852527_1 
  libuuid            conda-forge/linux-64::libuuid-2.38.1-h0b41bf4_0 
  libxcrypt          conda-forge/linux-64::libxcrypt-4.4.36-hd590300_1 
  libxml2            conda-forge/linux-64::libxml2-2.12.7-he7c6b58_4 
  libzlib            conda-forge/linux-64::libzlib-1.3.1-h4ab18f5_1 
  metis              conda-forge/linux-64::metis-5.1.0-h59595ed_1007 
  mumps-include      conda-forge/linux-64::mumps-include-5.7.2-ha770c72_0 
  mumps-seq          conda-forge/linux-64::mumps-seq-5.7.2-h6e8dedb_0 
  ncurses            conda-forge/linux-64::ncurses-6.5-he02047a_1 
  numpy              conda-forge/linux-64::numpy-1.26.4-py312heda63a1_0 
  openssl            conda-forge/linux-64::openssl-3.3.1-hb9d3cd8_3 
  pip                conda-forge/noarch::pip-24.2-pyhd8ed1ab_0 
  python             conda-forge/linux-64::python-3.12.5-h2ad013b_0_cpython 
  python_abi         conda-forge/linux-64::python_abi-3.12-5_cp312 
  readline           conda-forge/linux-64::readline-8.2-h8228510_1 
  setuptools         conda-forge/noarch::setuptools-72.2.0-pyhd8ed1ab_0 
  tk                 conda-forge/linux-64::tk-8.6.13-noxft_h4845f30_101 
  tzdata             conda-forge/noarch::tzdata-2024a-h8827d51_1 
  unixodbc           conda-forge/linux-64::unixodbc-2.3.12-h661eb56_0 
  wheel              conda-forge/noarch::wheel-0.44.0-pyhd8ed1ab_0 
  xz                 conda-forge/linux-64::xz-5.2.6-h166bdaf_0 
  zlib               conda-forge/linux-64::zlib-1.3.1-h4ab18f5_1 

Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate cyipopt-num1
#
# To deactivate an active environment, use
#
#     $ conda deactivate

moorepants@nandi:examples(master)$ act cyipopt-num1 
(cyipopt-num1) moorepants@nandi:examples(master)$ python hs071.py 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

This is Ipopt version 3.14.16, running with linear solver MUMPS 5.7.2.

Number of nonzeros in equality constraint Jacobian...:        4
Number of nonzeros in inequality constraint Jacobian.:        4
Number of nonzeros in Lagrangian Hessian.............:       10

Total number of variables............................:        4
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        4
                     variables with only upper bounds:        0
Total number of equality constraints.................:        1
Total number of inequality constraints...............:        1
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

Objective value at iteration #0 is - 16.1097
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.6109693e+01 1.12e+01 1.02e+00   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
Objective value at iteration #1 is - 17.3461
   1  1.7346108e+01 7.50e-01 2.37e+01  -0.3 7.22e-01    -  3.51e-01 1.00e+00f  1
Objective value at iteration #2 is - 17.9222
   2  1.7922201e+01 7.70e-03 5.29e+00  -0.2 6.00e-02   2.0 9.96e-01 1.00e+00h  1
Objective value at iteration #3 is - 17.1673
   3  1.7167308e+01 6.72e-02 1.66e+00  -0.8 1.37e+00    -  9.95e-01 6.98e-01f  1
Objective value at iteration #4 is - 16.9893
   4  1.6989299e+01 1.02e-01 1.47e-01  -1.2 2.30e-01    -  9.92e-01 1.00e+00f  1
Objective value at iteration #5 is - 16.9944
   5  1.6994402e+01 3.39e-02 1.19e-02  -2.3 8.69e-02    -  9.84e-01 1.00e+00h  1
Objective value at iteration #6 is - 17.014
   6  1.7013957e+01 2.20e-04 3.14e-04  -3.8 1.15e-02    -  9.99e-01 1.00e+00h  1
Objective value at iteration #7 is - 17.014
   7  1.7014017e+01 6.30e-07 1.31e-06  -9.7 3.43e-04    -  9.99e-01 9.99e-01h  1
Objective value at iteration #8 is - 17.014
   8  1.7014017e+01 5.68e-13 8.43e-13 -11.0 5.69e-07    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 8

                                   (scaled)                 (unscaled)
Objective...............:   3.4028034280427242e+01    1.7014017140213621e+01
Dual infeasibility......:   8.4300285623552048e-13    4.2150142811776024e-13
Constraint violation....:   5.6843418860808015e-13    5.6843418860808015e-13
Variable bound violation:   9.9952566223748818e-09    9.9952566223748818e-09
Complementarity.........:   1.1688338036422999e-11    5.8441690182114995e-12
Overall NLP error.......:   1.1688338036422999e-11    5.8441690182114995e-12

Number of objective function evaluations             = 9
Number of objective gradient evaluations             = 9
Number of equality constraint evaluations            = 9
Number of inequality constraint evaluations          = 9
Number of equality constraint Jacobian evaluations   = 9
Number of inequality constraint Jacobian evaluations = 9
Number of Lagrangian Hessian evaluations             = 8
Total seconds in IPOPT                               = 0.008

EXIT: Optimal Solution Found.
Solution of the primal variables: x=array([0.99999999, 4.74299964, 3.82114998, 1.37940829])

Solution of the dual variables: lambda=array([-0.55229366,  0.16146856])

Objective=17.01401714021362

(cyipopt-num1) moorepants@nandi:examples(master)$ conda list cyiopt
# packages in environment at /home/moorepants/miniconda/envs/cyipopt-num1:
#
# Name                    Version                   Build  Channel
(cyipopt-num1) moorepants@nandi:examples(master)$ conda list cyipopt
# packages in environment at /home/moorepants/miniconda/envs/cyipopt-num1:
#
# Name                    Version                   Build  Channel
cyipopt                   1.4.1           py312hfd7c8c3_3    conda-forge
(cyipopt-num1) moorepants@nandi:examples(master)$ conda list numpy
# packages in environment at /home/moorepants/miniconda/envs/cyipopt-num1:
#
# Name                    Version                   Build  Channel
numpy                     1.26.4          py312heda63a1_0    conda-forge
moorepants commented 1 week ago

So, closing.