mechmotum / cyipopt

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

Does not build with Cython 3 #211

Closed musicinmybrain closed 10 months ago

musicinmybrain commented 1 year ago

Cython 3.0.0 was just released (https://cython.readthedocs.io/en/latest/src/changes.html), and it looks like cyipopt will need some changes to be compatible with it.

python3 -m build
[...]
Compiling cyipopt/cython/ipopt_wrapper.pyx because it changed.
[1/1] Cythonizing cyipopt/cython/ipopt_wrapper.pyx
/tmp/build-env-9tlwx0y5/lib64/python3.11/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/build-via-sdist-_jz2qe4_/cyipopt-1.2.0.dev0/cyipopt/cython/ipopt_wrapper.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
                                        <Number*>np_cl.data,
                                        <Number*>np_cu.data,
                                        nele_jac,
                                        nele_hess,
                                        0,
                                        objective_cb,
                                        ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:416:40: Cannot assign type 'Bool (Index, Number *, Bool, Number *, UserDataPtr) except? -1' to 'Eval_F_CB'

Error compiling Cython file:
------------------------------------------------------------
...
                                        <Number*>np_cu.data,
                                        nele_jac,
                                        nele_hess,
                                        0,
                                        objective_cb,
                                        constraints_cb,
                                        ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:417:40: Cannot assign type 'Bool (Index, Number *, Bool, Index, Number *, UserDataPtr) except? -1' to 'Eval_G_CB'

Error compiling Cython file:
------------------------------------------------------------
...
                                        nele_jac,
                                        nele_hess,
                                        0,
                                        objective_cb,
                                        constraints_cb,
                                        gradient_cb,
                                        ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:418:40: Cannot assign type 'Bool (Index, Number *, Bool, Number *, UserDataPtr) except? -1' to 'Eval_Grad_F_CB'

Error compiling Cython file:
------------------------------------------------------------
...
                                        nele_hess,
                                        0,
                                        objective_cb,
                                        constraints_cb,
                                        gradient_cb,
                                        jacobian_cb,
                                        ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:419:40: Cannot assign type 'Bool (Index, Number *, Bool, Index, Index, Index *, Index *, Number *, UserDataPtr) except? -1' to 'Eval_Jac_G_CB'

Error compiling Cython file:
------------------------------------------------------------
...
                                        0,
                                        objective_cb,
                                        constraints_cb,
                                        gradient_cb,
                                        jacobian_cb,
                                        hessian_cb
                                        ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:420:40: Cannot assign type 'Bool (Index, Number *, Bool, Number, Index, Number *, Bool, Index, Index *, Index *, Number *, UserDataPtr) except? -1' to 'Eval_H_CB'

Error compiling Cython file:
------------------------------------------------------------
...

        if self.__nlp == NULL:
            msg = "Failed to create NLP problem. Make sure inputs are okay!"
            raise RuntimeError(msg)

        SetIntermediateCallback(self.__nlp, intermediate_cb)
                                            ^
------------------------------------------------------------

cyipopt/cython/ipopt_wrapper.pyx:427:44: Cannot assign type 'Bool (Index, Index, Number, Number, Number, Number, Number, Number, Number, Number, Index, UserDataPtr) except? -1' to 'Intermediate_CB'
Traceback (most recent call last):
[...]
musicinmybrain commented 1 year ago

For similar issues in other packages, see the section “Cannot assign type 'XXX (YYY) except? -1 nogil' to 'ZZZ *' (14 affected projects)” in https://github.com/cython/cython/issues/5305.

moorepants commented 1 year ago

Info on migration: https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html#exception-values-and-noexcept