You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Evaluate replacing our hand-written Cython SUNDIALS wrapper (fidimag/common/sundials/cvode.pyx, ~750 lines) — and possibly the bin/install-sundials.sh + local/ SUNDIALS build — with the official LLNL Python bindings, sundials4py.
Potential upside: it is first-party (authored by the SUNDIALS team), tracks SUNDIALS releases for us (already at 7.8.0 vs our 7.6.0 pin), BSD-3-Clause, and could delete a large chunk of maintenance surface.
Note on performance: our current cv_rhs already calls a Python RHS callback per step (unpacking the N_Vector into numpy views), so sundials4py's Python-callback model is unlikely to regress the hot path — the usual dealbreaker does not apply here.
Blockers to verify before adopting
Our integration leans on several advanced SUNDIALS features. Each must be confirmed in sundials4py:
OpenMP N_Vector — we wrap state with N_VMake_OpenMP for parallel vector ops. Confirm nvector_openmp is exposed, not just the serial vector.
Zero-copy callback arrays — our cv_rhs writes ydot in place via a zero-copy view. Confirm the callback receives writable, zero-copy numpy views (no per-step O(N) copy in/out).
Matrix-free SPGMR + Jacobian-times-vector — we pass a jtimes_fun to a GMRES solver. Confirm support for the equivalent of CVodeSetJacTimes with a Python jtimes callback, plus reinit, tolerances (CVodeSStolerances), get_stats, and max-steps.
Do the wheels bundle SUNDIALS? — decides whether this actually removes the build burden (bundled → we can drop install-sundials.sh + local/; not bundled → we still maintain the native install).
Python floor — sundials4py requires Python ≥ 3.12; our pyproject.toml currently says >=3.9. Adopting it drops 3.9–3.11 (minor, since the uv branch targets 3.14).
API completeness — verify everything else the wrapper uses is covered (CVODE reinit, rootfinding if used, stats, custom tolerances).
Suggested approach
Prototype behind the existing Integrator abstraction (the CVODE wrapper is already isolated), keeping cvode.pyx as the fallback.
Run the LLG + NEB test suites and a timing comparison against the current wrapper.
Only remove the Cython wrapper / build scripts once all boxes above are checked.
Summary
Evaluate replacing our hand-written Cython SUNDIALS wrapper (
fidimag/common/sundials/cvode.pyx, ~750 lines) — and possibly thebin/install-sundials.sh+local/SUNDIALS build — with the official LLNL Python bindings, sundials4py.Potential upside: it is first-party (authored by the SUNDIALS team), tracks SUNDIALS releases for us (already at 7.8.0 vs our 7.6.0 pin), BSD-3-Clause, and could delete a large chunk of maintenance surface.
Note on performance: our current
cv_rhsalready calls a Python RHS callback per step (unpacking theN_Vectorinto numpy views), so sundials4py's Python-callback model is unlikely to regress the hot path — the usual dealbreaker does not apply here.Blockers to verify before adopting
Our integration leans on several advanced SUNDIALS features. Each must be confirmed in sundials4py:
N_VMake_OpenMPfor parallel vector ops. Confirmnvector_openmpis exposed, not just the serial vector.cv_rhswritesydotin place via a zero-copy view. Confirm the callback receives writable, zero-copy numpy views (no per-step O(N) copy in/out).jtimes_funto a GMRES solver. Confirm support for the equivalent ofCVodeSetJacTimeswith a Python jtimes callback, plus reinit, tolerances (CVodeSStolerances),get_stats, and max-steps.install-sundials.sh+local/; not bundled → we still maintain the native install).pyproject.tomlcurrently says>=3.9. Adopting it drops 3.9–3.11 (minor, since the uv branch targets 3.14).Suggested approach
Integratorabstraction (the CVODE wrapper is already isolated), keepingcvode.pyxas the fallback.References
fidimag/common/sundials/cvode.pyx