Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support numpy2 #411

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions .github/build_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ if [[ $IMAGE == "private" ]]; then
cp -r $HOME/SNOPT/* pyoptsparse/pySNOPT/source
fi

# temporarily disable pip constraints file for build-time dependencies
mv ~/.config/pip/constraints.txt ~/.config/pip/constraints.txt.bkup
touch ~/.config/pip/constraints.txt

pip install .[optview,testing] -v

# move pip constraints file back
mv ~/.config/pip/constraints.txt.bkup ~/.config/pip/constraints.txt
9 changes: 5 additions & 4 deletions .github/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies:
# build
- python >=3.9
- numpy >=1.21,<2
- numpy >=2.0
- ipopt
- swig
- meson >=1.3.2
Expand All @@ -10,10 +10,11 @@ dependencies:
- pip
- setuptools
- build
# runtime
- mdolab-baseclasses >=1.3.1
- scipy >=1.7
- sqlitedict >=1.6
- packaging
# testing
- parameterized
- testflo
- scipy >=1.7
- mdolab-baseclasses >=1.3.1
- sqlitedict >=1.6
20 changes: 14 additions & 6 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ on:
jobs:
build-windows:
runs-on: windows-latest

timeout-minutes: 10
strategy:
fail-fast: false
matrix:
numpy_version: ["1.21.6", "1.25.2", "2.0.2"]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.9
miniforge-variant: Mambaforge
python-version: "3.10"
channels: conda-forge,defaults
channel-priority: strict
activate-environment: pyos-build
Expand All @@ -26,7 +29,7 @@ jobs:
shell: bash -l {0}
run: |
conda activate pyos-build
mamba install libpgmath
conda install libpgmath
- name: Build and install pyoptsparse
shell: cmd /C CALL {0}
run: |
Expand All @@ -37,6 +40,11 @@ jobs:
set CC_LD=link
python -m build -n -x .
pip install --no-deps --no-index --find-links dist pyoptsparse
- name: Install runtime numpy ${{ matrix.numpy_version }}
shell: bash -l {0}
run: |
conda activate pyos-build
conda install numpy==${{ matrix.numpy_version }}
- name: Run tests
shell: bash -l {0}
run: |
Expand Down
18 changes: 9 additions & 9 deletions pyoptsparse/pyIPOPT/src/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ eval_f(Index n, Number * x, Bool new_x, Number * obj_value, UserDataPtr data)

import_array1(FALSE);
PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE, (char *)x);
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, (char *)x);
if (!arrayx)
return FALSE;

Expand Down Expand Up @@ -209,11 +209,11 @@ eval_grad_f(Index n, Number * x, Bool new_x, Number * grad_f, UserDataPtr data)
import_array1(FALSE);

/*
* PyObject *arrayx = PyArray_FromDimsAndData(1, dims, PyArray_DOUBLE
* PyObject *arrayx = PyArray_FromDimsAndData(1, dims, NPY_DOUBLE
* , (char*) x);
*/
PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE, (char *)x);
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, (char *)x);
if (!arrayx)
return FALSE;

Expand Down Expand Up @@ -287,11 +287,11 @@ eval_g(Index n, Number * x, Bool new_x, Index m, Number * g, UserDataPtr data)
import_array1(FALSE);

/*
* PyObject *arrayx = PyArray_FromDimsAndData(1, dims, PyArray_DOUBLE
* PyObject *arrayx = PyArray_FromDimsAndData(1, dims, NPY_DOUBLE
* , (char*) x);
*/
PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE, (char *)x);
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE, (char *)x);
if (!arrayx)
return FALSE;

Expand Down Expand Up @@ -372,7 +372,7 @@ eval_jac_g(Index n, Number * x, Bool new_x,
import_array1(FALSE);

PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE,
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE,
(char *)x);
if (!arrayx)
return FALSE;
Expand Down Expand Up @@ -420,7 +420,7 @@ eval_jac_g(Index n, Number * x, Bool new_x,
//logger("[Callback:R] eval_jac_g(1)");
} else {
PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE,
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE,
(char *)x);

if (!arrayx)
Expand Down Expand Up @@ -580,7 +580,7 @@ eval_h(Index n, Number * x, Bool new_x, Number obj_factor,

dims[0] = n;
PyObject *arrayx =
PyArray_SimpleNewFromData(1, dims, PyArray_DOUBLE,
PyArray_SimpleNewFromData(1, dims, NPY_DOUBLE,
(char *)x);
if (!arrayx)
return FALSE;
Expand All @@ -601,7 +601,7 @@ eval_h(Index n, Number * x, Bool new_x, Number obj_factor,
}
dims2[0] = m;
PyObject *lagrangex = PyArray_SimpleNewFromData(
1, dims2, PyArray_DOUBLE, (char *)lambda);
1, dims2, NPY_DOUBLE, (char *)lambda);
if (!lagrangex)
return FALSE;

Expand Down
8 changes: 4 additions & 4 deletions pyoptsparse/pyIPOPT/src/pyipoptcoremodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ PyObject *solve(PyObject * self, PyObject * args)
n = dim[0];
dX[0] = n;

x = (PyArrayObject *) PyArray_SimpleNew(1, dX, PyArray_DOUBLE);
x = (PyArrayObject *) PyArray_SimpleNew(1, dX, NPY_DOUBLE);
if (!x) {
retval = PyErr_NoMemory();
/* clean up and return */
Expand Down Expand Up @@ -663,11 +663,11 @@ PyObject *solve(PyObject * self, PyObject * args)

/* Allocate multiplier arrays */

mL = (PyArrayObject *) PyArray_SimpleNew(1, dX, PyArray_DOUBLE);
mU = (PyArrayObject *) PyArray_SimpleNew(1, dX, PyArray_DOUBLE);
mL = (PyArrayObject *) PyArray_SimpleNew(1, dX, NPY_DOUBLE);
mU = (PyArrayObject *) PyArray_SimpleNew(1, dX, NPY_DOUBLE);
dlambda[0] = m;
lambda = (PyArrayObject *) PyArray_SimpleNew(1, dlambda,
PyArray_DOUBLE);
NPY_DOUBLE);

/* For status code, see IpReturnCodes_inc.h in Ipopt */

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=42", "meson>=0.60.0", "oldest-supported-numpy", "ninja"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=42", "meson>=0.60.0", "ninja", "numpy>=2.0"]
build-backend = "setuptools.build_meta"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ def copy_shared_libraries():
install_requires=[
"packaging",
"sqlitedict>=1.6",
"numpy>=1.21,<2",
"numpy>=1.21",
"scipy>=1.7",
"mdolab-baseclasses>=1.3.1",
"setuptools",
],
extras_require={
"optview": [
Expand Down
Loading