Skip to content

Add a meson-python build: the Fortran solvers back on Python 3.12, bit-identical on 3.11 - #136

Open
hubertus65 wants to merge 3 commits into
modelon-community:masterfrom
hubertus65:meson-build
Open

hubertus65 wants to merge 3 commits into
modelon-community:masterfrom
hubertus65:meson-build

Conversation

@hubertus65

Copy link
Copy Markdown

Problem

setup.py builds the f2py-wrapped Fortran solvers — Dopri5, RodasODE, Radau5ODE/Radar5ODE
(Fortran), LSODAR, ODASSL, DASP3ODE, GLIMDA — only when numpy.distutils imports
(have_nd), and drops them silently otherwise. numpy.distutils is gone on Python ≥ 3.12 and
broken by setuptools ≥ 70, so on a current interpreter Assimulo builds with the SUNDIALS and C
solvers only. The conda-forge 3.8.0 package already ships that way.

Change

A meson-python build next to setup.py (three commits). setup.py is not touched and still
works on Python 3.11
— this adds a second, supported way to build, it does not replace the first.

  • meson.build / meson.options: options sundials-home, superlu-home, blas-home,
    lapack-home, fortran (feature), extra-fortran-flags. The SUNDIALS version, index size,
    SuperLU_MT and rtol-vector support are read from sundials_config.h
    (tools/sundials_config.py) into Cython's compile-time environment exactly as setup.py does.
  • Cython: tools/cythonize_one.py drives Cython (a version tuple cannot be passed on Cython's
    command line); build-support/ mirrors the sources under the package name in the build tree so
    from assimulo.ode cimport ODE resolves and each module compiles as assimulo.<name>, as
    setup.py's copy into build/assimulo/ did.
  • f2py: tools/f2py_generate.py runs f2py on each .pyf and creates the wrapper files meson
    expects when f2py does not emit them; fortranobject.c comes from numpy. DASP3 gets
    -fdefault-double-8 -fdefault-real-8, GLIMDA links BLAS/LAPACK, Radau5 (C) links SuperLU_MT
    when given.
  • SuperLU_MT is found in a conda-forge prefix (include/superlu_mt/) without the symlink shim
    setup.py needs, and is identified by slu_mt_ddefs.h rather than supermatrix.h, which
    plain SuperLU also ships.

Equivalence, and the test that asserts it

Compiler flags match the numpy.distutils build (C: -O2 -fno-strict-aliasing -fwrapv -fno-merge-constants -msse -msse2 -msse3; Fortran: -O3 -funroll-loops -fno-second-underscore --std=legacy), so the numerics are the same rather than merely close.

tools/dump_examples.py dumps the trajectories and statistics of all 45 examples;
tests/test_build_equivalence.py (env ASSIMULO_REFERENCE_RESULTS) compares two builds.

result
Linux / gcc 13, conda-forge SUNDIALS 7.8 + SuperLU_MT, Python 3.11 136 of 136 arrays and statistics bit-identical to the numpy.distutils build
pytest tests under either build, 3.11 330 passed, 5 skipped
Python 3.12.14 (conda-forge gcc/gfortran, SUNDIALS 7.8) 330 passed; all 45 examples bit-identical to the 3.11 numpy.distutils reference — i.e. the Fortran solvers are back on 3.12

Review notes

  • Nothing under thirdparty/ is changed.
  • No public API changes; no solver behaviour changes.
  • Independent of the other branches I am opening — this one can go first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p

hubertus65 and others added 3 commits September 19, 2026 20:48
…the numpy.distutils build)

setup.py builds the Fortran solvers (Dopri5, RodasODE, Radau5/Radar5 Fortran,
LSODAR, ODASSL, DASP3, GLIMDA) only when numpy.distutils imports, which is
gone on Python >= 3.12 and broken by setuptools >= 70; the conda-forge
package already ships without them. This adds a meson-python build next to
setup.py (setup.py is unchanged and still works on Python 3.11):

- meson.build / meson.options: options sundials-home, superlu-home,
  blas-home, lapack-home, fortran (feature), extra-fortran-flags; SUNDIALS
  version, index size, SuperLU_MT and rtol-vector support are read from
  sundials_config.h (tools/sundials_config.py) into Cython's compile-time
  environment exactly as setup.py does.
- Cython: tools/cythonize_one.py drives Cython (a version tuple cannot be
  passed on cython's command line); build-support/ mirrors the sources
  under the package name in the build tree so that "from assimulo.ode
  cimport ODE" resolves and each module is compiled as assimulo.<name>,
  as setup.py's copy to build/assimulo/ did.
- f2py: tools/f2py_generate.py runs f2py on each .pyf and creates the
  wrapper files meson expects when f2py does not emit them; fortranobject.c
  comes from numpy. DASP3 gets -fdefault-double-8 -fdefault-real-8, GLIMDA
  links BLAS/LAPACK, Radau5 (C) links SuperLU_MT when given.
- Compiler flags match the numpy.distutils build (C: -O2 -fno-strict-aliasing
  -fwrapv -fno-merge-constants -msse -msse2 -msse3; Fortran: -O3
  -funroll-loops -fno-second-underscore --std=legacy), so the numerics are
  the same: tools/dump_examples.py dumps the trajectories and statistics of
  all 45 examples, and tests/test_build_equivalence.py (env
  ASSIMULO_REFERENCE_RESULTS) compares two builds. On Linux/gcc 13 with
  conda-forge SUNDIALS 7.8 and SuperLU_MT all 136 arrays and statistics
  are bit-identical between the two builds; pytest: 330 passed, 5 skipped
  with either.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p
…without a symlink shim

Verified on Python 3.12.14 (conda-forge gcc/gfortran, SUNDIALS 7.8): 330 tests pass and
all 45 examples are bit-identical to the Python 3.11 numpy.distutils build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p
…ts in plain SuperLU)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p
@hubertus65

Copy link
Copy Markdown
Author

You can ping me at my email hubertus dot tummescheit at modelbased dot cloud if you want to know the background. The basic idea was that I wanted to do a thorough benchmark against the Julia solvers from diffeq.jl. The "good" news is: most of them suck. And the FMI infrastructure sucks too. This was just a necessary prep step, but it allows to use Python > 3.11 for Assimulo, whcih I think is useful no matter what.

@hubertus65
hubertus65 marked this pull request as ready for review September 22, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant