modelon-community / Assimulo

Assimulo is a simulation package for solving ordinary differential equations.
https://jmodelica.org/assimulo/index.html
GNU Lesser General Public License v3.0
70 stars 17 forks source link

Cython 3.0 support #74

Closed modelonrobinandersson closed 6 months ago

modelonrobinandersson commented 1 year ago

Assimulo does not build with Cython 3. We should add support for that.

Build error I got when trying with latest Cython available with Python 3.8:

[1/1] Cythonizing assimulo/explicit_ode.pyx
/opt/venv/lib/python3.8/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: /opt/build/wheel_build/build/assimulo/explicit_ode.pxd
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
        cdef N.ndarray[double, mode="c", ndim=1] g_high_c = N.empty(n_g, dtype = N.double)
        cdef N.ndarray[double, mode="c", ndim=1] y_high_c = N.array(y_high)
        cdef int nstatefcns = 0
        cdef int ret = explicit_ode.f_event_locator(len(y_high), n_g, 1.e-13, t_low, &t_high,
                                                    &y_high_c[0], &g_low_c[0], &g_mid_c[0], &g_high_c[0],
                                                    callback_event, <void*>self.event_func,
                                                    ^
------------------------------------------------------------

assimulo/explicit_ode.pyx:345:52: Cannot assign type 'int (int, int, double, double *, double *, void *) except? -1' to 'FP_event_func'. Exception values are incompatible. Suggest adding 'noexcept' to type 'int (int, int, double, double *, double *, void *) except? -1'.

Error compiling Cython file:
------------------------------------------------------------
...
        cdef N.ndarray[double, mode="c", ndim=1] y_high_c = N.array(y_high)
        cdef int nstatefcns = 0
        cdef int ret = explicit_ode.f_event_locator(len(y_high), n_g, 1.e-13, t_low, &t_high,
                                                    &y_high_c[0], &g_low_c[0], &g_mid_c[0], &g_high_c[0],
                                                    callback_event, <void*>self.event_func,
                                                    callback_interp, <void*>self.interpolate,
                                                    ^
------------------------------------------------------------

assimulo/explicit_ode.pyx:346:52: Cannot assign type 'int (int, double, double *, void *) except? -1' to 'FP_interpolation'. Exception values are incompatible. Suggest adding 'noexcept' to type 'int (int, double, double *, void *) except? -1'.
Traceback (most recent call last):
  File "setup.py", line 652, in <module>
    ext_list = prepare.cython_extensionlists()
  File "setup.py", line 472, in cython_extensionlists
    ext_list = cythonize([os.path.join("assimulo", "explicit_ode.pyx")],
  File "/opt/venv/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
  File "/opt/venv/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: assimulo/explicit_ode.pyx