mxlpy-native 0.6.0__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. {mxlpy_native-0.6.0/src/mxlpy_native.egg-info → mxlpy_native-0.7.0}/PKG-INFO +2 -2
  2. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/README.md +1 -1
  3. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/mxn_solvers.c +83 -18
  4. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/VENDORED +10 -6
  5. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/adjoint_wrapper.c +12 -6
  6. mxlpy_native-0.7.0/c/vendor/discrete_adjoint.c +1529 -0
  7. mxlpy_native-0.7.0/c/vendor/discrete_adjoint.h +109 -0
  8. mxlpy_native-0.7.0/c/vendor/finite_jacobian.h +61 -0
  9. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/lsoda.c +19 -7
  10. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/lsoda.h +8 -0
  11. mxlpy_native-0.7.0/c/vendor/nordsieck_tape.h +46 -0
  12. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode.c +34 -0
  13. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_impl.h +4 -0
  14. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/pyproject.toml +1 -1
  15. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/setup.py +2 -1
  16. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native/__init__.py +1 -1
  17. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0/src/mxlpy_native.egg-info}/PKG-INFO +2 -2
  18. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native.egg-info/SOURCES.txt +5 -0
  19. mxlpy_native-0.7.0/tests/test_discrete_adjoint.py +141 -0
  20. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/tests/test_solvers.py +13 -2
  21. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/LICENSE +0 -0
  22. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/MANIFEST.in +0 -0
  23. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/HAIRER-LICENCE.txt +0 -0
  24. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/SCIPY-LICENCE.txt +0 -0
  25. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/SUNDIALS-LICENCE.txt +0 -0
  26. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/SUNDIALS-NOTICE.txt +0 -0
  27. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/blaslapack_declarations.h +0 -0
  28. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/dc_decsol.c +0 -0
  29. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/decsol.c +0 -0
  30. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/dop853.c +0 -0
  31. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/dopri5.c +0 -0
  32. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/f2c.h +0 -0
  33. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/fit_experiments.c +0 -0
  34. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/fit_experiments.h +0 -0
  35. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/jacobian_wrapper.c +0 -0
  36. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/libf2c_stubs.c +0 -0
  37. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/COPYRIGHT.txt +0 -0
  38. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/cminpack.h +0 -0
  39. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/cminpackP.h +0 -0
  40. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/dpmpar.c +0 -0
  41. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/enorm.c +0 -0
  42. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/fdjac2.c +0 -0
  43. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/lmder.c +0 -0
  44. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/lmdif.c +0 -0
  45. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/lmpar.c +0 -0
  46. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/minpackP.h +0 -0
  47. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/qrfac.c +0 -0
  48. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/minpack/qrsolv.c +0 -0
  49. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/mxs_lapack.c +0 -0
  50. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/radau5.c +0 -0
  51. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/radau5_wrapper.c +0 -0
  52. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/solver_common.c +0 -0
  53. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/solver_common.h +0 -0
  54. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/cvode/cvode.h +0 -0
  55. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/cvode/cvode_diag.h +0 -0
  56. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/cvode/cvode_ls.h +0 -0
  57. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/cvode/cvode_proj.h +0 -0
  58. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/nvector/nvector_serial.h +0 -0
  59. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/priv/sundials_context_impl.h +0 -0
  60. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/priv/sundials_errors_impl.h +0 -0
  61. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/priv/sundials_logger_macros.h +0 -0
  62. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_adaptcontroller.h +0 -0
  63. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_adjointcheckpointscheme.h +0 -0
  64. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_adjointstepper.h +0 -0
  65. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_band.h +0 -0
  66. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_config.h +0 -0
  67. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_context.h +0 -0
  68. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_core.h +0 -0
  69. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_dense.h +0 -0
  70. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_direct.h +0 -0
  71. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_domeigestimator.h +0 -0
  72. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_errors.h +0 -0
  73. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_export.h +0 -0
  74. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_futils.h +0 -0
  75. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_iterative.h +0 -0
  76. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_linearsolver.h +0 -0
  77. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_logger.h +0 -0
  78. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_math.h +0 -0
  79. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_matrix.h +0 -0
  80. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_memory.h +0 -0
  81. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_nonlinearsolver.h +0 -0
  82. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_nvector.h +0 -0
  83. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_nvector_senswrapper.h +0 -0
  84. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_profiler.h +0 -0
  85. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_stepper.h +0 -0
  86. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_types.h +0 -0
  87. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sundials/sundials_version.h +0 -0
  88. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunlinsol/sunlinsol_dense.h +0 -0
  89. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunmatrix/sunmatrix_band.h +0 -0
  90. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunmatrix/sunmatrix_dense.h +0 -0
  91. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunmatrix/sunmatrix_sparse.h +0 -0
  92. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h +0 -0
  93. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/include/sunnonlinsol/sunnonlinsol_newton.h +0 -0
  94. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_diag_impl.h +0 -0
  95. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_fused_stubs.c +0 -0
  96. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_io.c +0 -0
  97. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_ls.c +0 -0
  98. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_ls_impl.h +0 -0
  99. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_nls.c +0 -0
  100. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_proj.c +0 -0
  101. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/cvode/cvode_proj_impl.h +0 -0
  102. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/nvector/serial/nvector_serial.c +0 -0
  103. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/stl/sunstl_vector.h +0 -0
  104. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_adiak_metadata.h +0 -0
  105. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_band.c +0 -0
  106. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_context.c +0 -0
  107. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_debug.h +0 -0
  108. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_dense.c +0 -0
  109. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_errors.c +0 -0
  110. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_futils.c +0 -0
  111. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_hashmap_impl.h +0 -0
  112. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_linearsolver.c +0 -0
  113. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_logger.c +0 -0
  114. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_logger_impl.h +0 -0
  115. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_macros.h +0 -0
  116. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_math.c +0 -0
  117. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_matrix.c +0 -0
  118. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_memory.c +0 -0
  119. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_nonlinearsolver.c +0 -0
  120. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_nvector.c +0 -0
  121. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_nvector_senswrapper.c +0 -0
  122. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_utils.h +0 -0
  123. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sundials/sundials_version.c +0 -0
  124. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sunlinsol/dense/sunlinsol_dense.c +0 -0
  125. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sunmatrix/band/sunmatrix_band.c +0 -0
  126. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sunmatrix/dense/sunmatrix_dense.c +0 -0
  127. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c +0 -0
  128. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/c/vendor/sundials/src/sunnonlinsol/newton/sunnonlinsol_newton.c +0 -0
  129. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/setup.cfg +0 -0
  130. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native/__main__.py +0 -0
  131. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native.egg-info/dependency_links.txt +0 -0
  132. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native.egg-info/requires.txt +0 -0
  133. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/src/mxlpy_native.egg-info/top_level.txt +0 -0
  134. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/tests/test_adjoint.py +0 -0
  135. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/tests/test_build_errors.py +0 -0
  136. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/tests/test_fit.py +0 -0
  137. {mxlpy_native-0.6.0 → mxlpy_native-0.7.0}/tests/test_vendor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mxlpy-native
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Compiled ODE solvers (RADAU5, LSODA, SUNDIALS CVODE) for MxlPy's Native integrator
5
5
  Author-email: Marvin van Aalst <marvin.vanaalst@gmail.com>
6
6
  License-Expression: MIT
@@ -63,7 +63,7 @@ uv sync # builds the extension in place
63
63
  uv run pytest
64
64
  ```
65
65
 
66
- `c/vendor/` is copied from [mxl-solvers](https://github.com/Computational-Biology-Aachen/mxl-solvers) by its `scripts/vendor.sh`. `vendor/VENDORED` records the commit and file hashes, which `tests/test_vendor.py` checks. Fix solvers there, not here. `c/mxn_solvers.c` is the glue MxlPy calls (`mxn_radau` / `mxn_lsoda` / `mxn_cvode` for simulations, `mxn_fit_*` for least-squares fits, `mxn_adjoint_*` for adjoint gradients), compiled unchanged into the wheel and into MxlPy's `solvers.wasm` (`scripts/build_native_wasm.sh` in MxlPy).
66
+ `c/vendor/` is copied from [mxl-solvers](https://github.com/Computational-Biology-Aachen/mxl-solvers) by its `scripts/vendor.sh`. `vendor/VENDORED` records the commit and file hashes, which `tests/test_vendor.py` checks. Fix solvers there, not here. `c/mxn_solvers.c` is the glue MxlPy calls (`mxn_radau` / `mxn_lsoda` / `mxn_cvode` for simulations, optionally with the model's analytic Jacobian, `mxn_fit_*` for least-squares fits, `mxn_adjoint_*` for continuous and `mxn_da_*` for discrete adjoint gradients), compiled unchanged into the wheel and into MxlPy's `solvers.wasm` (`scripts/build_native_wasm.sh` in MxlPy).
67
67
 
68
68
  When an exported function's signature or meaning changes, bump `MXN_ABI_VERSION` in `c/mxn_solvers.c`, `ABI_VERSION` in `src/mxlpy_native/__init__.py` and the ABI MxlPy expects, then release both. MxlPy refuses a mismatched pair with an upgrade hint instead of crashing.
69
69
 
@@ -39,7 +39,7 @@ uv sync # builds the extension in place
39
39
  uv run pytest
40
40
  ```
41
41
 
42
- `c/vendor/` is copied from [mxl-solvers](https://github.com/Computational-Biology-Aachen/mxl-solvers) by its `scripts/vendor.sh`. `vendor/VENDORED` records the commit and file hashes, which `tests/test_vendor.py` checks. Fix solvers there, not here. `c/mxn_solvers.c` is the glue MxlPy calls (`mxn_radau` / `mxn_lsoda` / `mxn_cvode` for simulations, `mxn_fit_*` for least-squares fits, `mxn_adjoint_*` for adjoint gradients), compiled unchanged into the wheel and into MxlPy's `solvers.wasm` (`scripts/build_native_wasm.sh` in MxlPy).
42
+ `c/vendor/` is copied from [mxl-solvers](https://github.com/Computational-Biology-Aachen/mxl-solvers) by its `scripts/vendor.sh`. `vendor/VENDORED` records the commit and file hashes, which `tests/test_vendor.py` checks. Fix solvers there, not here. `c/mxn_solvers.c` is the glue MxlPy calls (`mxn_radau` / `mxn_lsoda` / `mxn_cvode` for simulations, optionally with the model's analytic Jacobian, `mxn_fit_*` for least-squares fits, `mxn_adjoint_*` for continuous and `mxn_da_*` for discrete adjoint gradients), compiled unchanged into the wheel and into MxlPy's `solvers.wasm` (`scripts/build_native_wasm.sh` in MxlPy).
43
43
 
44
44
  When an exported function's signature or meaning changes, bump `MXN_ABI_VERSION` in `c/mxn_solvers.c`, `ABI_VERSION` in `src/mxlpy_native/__init__.py` and the ABI MxlPy expects, then release both. MxlPy refuses a mismatched pair with an upgrade hint instead of crashing.
45
45
 
@@ -3,7 +3,9 @@
3
3
  * themselves are vendored from mxl-solvers (see vendor/VENDORED); CVODE is SUNDIALS'
4
4
  * (vendor/sundials, BSD-3-Clause, see vendor/SUNDIALS-LICENCE.txt). RADAU5 and this
5
5
  * file keep global state, so only one solve can run at a time in a process. */
6
+ #include "discrete_adjoint.h"
6
7
  #include "f2c.h"
8
+ #include "finite_jacobian.h"
7
9
  #include "lsoda.h"
8
10
  #include <cvode/cvode.h>
9
11
  #include <nvector/nvector_serial.h>
@@ -23,7 +25,7 @@
23
25
 
24
26
  /* Bump whenever an exported signature or its meaning changes, together with ABI_VERSION
25
27
  * in mxlpy_native/__init__.py and the version MxlPy's Native integrator expects. */
26
- #define MXN_ABI_VERSION 4
28
+ #define MXN_ABI_VERSION 5
27
29
  MXN_API int mxn_abi_version(void) { return MXN_ABI_VERSION; }
28
30
 
29
31
  extern int radau5_(integer *n, U_fp fcn, doublereal *x, doublereal *y, doublereal *xend, doublereal *h,
@@ -36,6 +38,9 @@ extern double radau5_jac_growth;
36
38
 
37
39
  typedef void (*ModelFn)(int, double, double *, double *, double *);
38
40
  static ModelFn g_model;
41
+ /* The model's Jacobian df/dy (ModelFn signature, n x n column-major), NULL = the solvers'
42
+ * finite differences. Called through finite_jacobian, which differences its non-finite columns. */
43
+ static ModelFn g_jac;
39
44
  static double *g_pars; /* LSODA's right-hand side takes no parameter array. */
40
45
  static const double *g_t_out;
41
46
  static double *g_y_out;
@@ -50,7 +55,13 @@ static int fcn_dispatch(integer *n, doublereal *x, doublereal *y, doublereal *f,
50
55
  return 0;
51
56
  }
52
57
 
53
- static int no_jac(void) { return 0; }
58
+ static int radau_jac(integer *n, doublereal *x, doublereal *y, doublereal *dfy, integer *ldfy,
59
+ doublereal *rpar, integer *ipar) {
60
+ (void)ldfy; /* full Jacobian: ldfy == n */
61
+ (void)ipar;
62
+ finite_jacobian(g_model, g_jac, (int)*n, *x, y, dfy, rpar);
63
+ return 0;
64
+ }
54
65
  static int no_mas(void) { return 0; }
55
66
 
56
67
  static int solout(integer *nr, doublereal *xold, doublereal *x, doublereal *y, doublereal *cont, integer *lrc,
@@ -71,12 +82,14 @@ static int solout(integer *nr, doublereal *xold, doublereal *x, doublereal *y, d
71
82
  }
72
83
 
73
84
  /* Integrates from t_out[0] to t_out[n_out - 1], writing rows of n values into y_out.
74
- * y holds the initial state on entry and the final state on return. Returns RADAU5's
85
+ * y holds the initial state on entry and the final state on return. jac is the model's
86
+ * Jacobian (see g_jac), 0 for finite differences. Returns RADAU5's
75
87
  * IDID: positive on success, -1 bad input, -2 too many steps, -3 step too small,
76
88
  * -4 singular matrix. Returns -5 if allocation fails or the result isn't finite. */
77
- MXN_API int mxn_radau(int n, double *y, double *pars, double rtol, double atol, int nmax, int reuse_jacobian,
78
- int n_out, const double *t_out, double *y_out) {
79
- integer N = n, itol = 0, ijac = 0, mljac = n, mujac = n, imas = 0, mlmas = n, mumas = n, iout = 1, idid = 0, ipar = 0;
89
+ MXN_API int mxn_radau(int n, double *y, double *pars, intptr_t jac, double rtol, double atol, int nmax,
90
+ int reuse_jacobian, int n_out, const double *t_out, double *y_out) {
91
+ g_jac = (ModelFn)jac;
92
+ integer N = n, itol = 0, ijac = jac ? 1 : 0, mljac = n, mujac = n, imas = 0, mlmas = n, mumas = n, iout = 1, idid = 0, ipar = 0;
80
93
  integer lwork = 4 * N * N + 12 * N + 20, liwork = 3 * N + 20;
81
94
  doublereal *work = calloc((size_t)lwork, sizeof(doublereal));
82
95
  integer *iwork = calloc((size_t)liwork, sizeof(integer));
@@ -101,7 +114,7 @@ MXN_API int mxn_radau(int n, double *y, double *pars, double rtol, double atol,
101
114
  g_y_out = y_out;
102
115
  g_n_out = n_out;
103
116
  g_next = 0;
104
- radau5_(&N, (U_fp)fcn_dispatch, &x, y, &xend, &h, &rt, &at, &itol, (U_fp)no_jac, &ijac, &mljac, &mujac,
117
+ radau5_(&N, (U_fp)fcn_dispatch, &x, y, &xend, &h, &rt, &at, &itol, (U_fp)radau_jac, &ijac, &mljac, &mujac,
105
118
  (U_fp)no_mas, &imas, &mlmas, &mumas, (U_fp)solout, &iout, work, &lwork, iwork, &liwork, pars, &ipar, &idid);
106
119
  free(work);
107
120
  free(iwork);
@@ -116,14 +129,20 @@ MXN_API int mxn_radau(int n, double *y, double *pars, double rtol, double atol,
116
129
 
117
130
  static void lsoda_fcn(int *n, double *t, double *y, double *dydt) { g_model(*n, *t, y, dydt, g_pars); }
118
131
 
119
- /* Same contract as mxn_radau, with LSODA (SciPy's C translation) and its internal
120
- * finite-difference Jacobian. nmax caps the total number of steps. Returns 2 on
132
+ static void lsoda_jac(int *n, double *t, double *y, int *ml, int *mu, double *pd, int *nrowpd) {
133
+ (void)ml; (void)mu; (void)nrowpd; /* full Jacobian: nrowpd == n */
134
+ finite_jacobian(g_model, g_jac, *n, *t, y, pd, g_pars);
135
+ }
136
+
137
+ /* Same contract as mxn_radau, with LSODA (SciPy's C translation), using jac or its
138
+ * internal finite-difference Jacobian. nmax caps the total number of steps. Returns 2 on
121
139
  * success, or LSODA's negative ISTATE: -1 too many steps, -2 too much accuracy
122
140
  * requested, -3 bad input, -4 repeated error test failures, -5 repeated convergence
123
141
  * failures, -6 an error weight became zero. Returns -9 if allocation fails or the
124
142
  * result isn't finite. */
125
- MXN_API int mxn_lsoda(int n, double *y, double *pars, double rtol, double atol, int nmax, int n_out,
126
- const double *t_out, double *y_out) {
143
+ MXN_API int mxn_lsoda(int n, double *y, double *pars, intptr_t jac, double rtol, double atol, int nmax,
144
+ int n_out, const double *t_out, double *y_out) {
145
+ g_jac = (ModelFn)jac;
127
146
  /* Work array sizes as in SciPy's odepack: Adams up to order 12, BDF up to 5. */
128
147
  const int lrn = 20 + n * 13 + 3 * n, lrs = 20 + n * 6 + 3 * n + n * n + 2;
129
148
  const int lrw = lrn > lrs ? lrn : lrs, liw = 20 + n;
@@ -143,8 +162,8 @@ MXN_API int mxn_lsoda(int n, double *y, double *pars, double rtol, double atol,
143
162
  for (int k = 1; k < n_out && istate > 0; k++) {
144
163
  double tout = t_out[k];
145
164
  if (tout != t_out[k - 1]) {
146
- lsoda(lsoda_fcn, n, y, &t, &tout, 1, &rtol, &atol, &itask, &istate, &iopt, rwork, lrw, iwork, liw, NULL,
147
- 2, &S);
165
+ lsoda(lsoda_fcn, n, y, &t, &tout, 1, &rtol, &atol, &itask, &istate, &iopt, rwork, lrw, iwork, liw,
166
+ jac ? lsoda_jac : NULL, jac ? 1 : 2, &S);
148
167
  if (istate > 0 && iwork[10] > nmax) istate = -1; /* IWORK(11): steps so far */
149
168
  }
150
169
  memcpy(y_out + (size_t)k * (size_t)n, y, (size_t)n * sizeof(double));
@@ -158,6 +177,14 @@ MXN_API int mxn_lsoda(int n, double *y, double *pars, double rtol, double atol,
158
177
  return 2;
159
178
  }
160
179
 
180
+ static int cvode_jac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix J, void *user_data, N_Vector tmp1,
181
+ N_Vector tmp2, N_Vector tmp3) {
182
+ (void)fy; (void)user_data; (void)tmp1; (void)tmp2; (void)tmp3;
183
+ finite_jacobian(g_model, g_jac, (int)N_VGetLength(y), t, N_VGetArrayPointer(y), SM_DATA_D(J),
184
+ g_pars); /* column-major */
185
+ return 0;
186
+ }
187
+
161
188
  static int cvode_rhs(sunrealtype t, N_Vector y, N_Vector dydt, void *user_data) {
162
189
  (void)user_data;
163
190
  int n = (int)N_VGetLength(y);
@@ -169,15 +196,16 @@ static int cvode_rhs(sunrealtype t, N_Vector y, N_Vector dydt, void *user_data)
169
196
  return 0;
170
197
  }
171
198
 
172
- /* Same contract as mxn_lsoda, with SUNDIALS' CVODE: BDF with Newton iteration and a dense
173
- * difference-quotient Jacobian, or with adams != 0, Adams-Moulton with fixed-point
199
+ /* Same contract as mxn_lsoda, with SUNDIALS' CVODE: BDF with Newton iteration and jac or a
200
+ * dense difference-quotient Jacobian, or with adams != 0, Adams-Moulton with fixed-point
174
201
  * iteration. nmax caps the total number of steps. Returns 1 on success, or CVODE's
175
202
  * negative flag: -1 too many steps, -2 too much accuracy requested, -3 repeated error
176
203
  * test failures, -4 repeated convergence failures, -8 the right-hand side kept failing
177
204
  * (non-finite), -22 bad input, ... (see cvode.h). Returns -99 if allocation fails or the
178
205
  * result isn't finite. */
179
- MXN_API int mxn_cvode(int n, double *y, double *pars, double rtol, double atol, int nmax, int adams, int n_out,
180
- const double *t_out, double *y_out) {
206
+ MXN_API int mxn_cvode(int n, double *y, double *pars, intptr_t jac, double rtol, double atol, int nmax,
207
+ int adams, int n_out, const double *t_out, double *y_out) {
208
+ g_jac = (ModelFn)jac;
181
209
  SUNContext ctx = NULL;
182
210
  if (SUNContext_Create(SUN_COMM_NULL, &ctx) != 0) return -99;
183
211
  N_Vector v = N_VMake_Serial(n, y, ctx); /* works on y in place */
@@ -198,6 +226,7 @@ MXN_API int mxn_cvode(int n, double *y, double *pars, double rtol, double atol,
198
226
  A = SUNDenseMatrix(n, n, ctx);
199
227
  ls = A ? SUNLinSol_Dense(v, A, ctx) : NULL;
200
228
  flag = ls ? CVodeSetLinearSolver(mem, ls, A) : -99;
229
+ if (flag == CV_SUCCESS && jac) flag = CVodeSetJacFn(mem, cvode_jac);
201
230
  }
202
231
  memcpy(y_out, y, (size_t)n * sizeof(double));
203
232
  double t = t_out[0];
@@ -330,7 +359,8 @@ MXN_API void mxn_adjoint_set_fns(intptr_t model, intptr_t adjoint, intptr_t deri
330
359
  /* Arguments as adjoint_vjp (adjoint_wrapper.c, fit_experiments.h's experiment layout), with the
331
360
  * cotangent in data_y's layout. Returns 0, -1 out of memory, -3 inconsistent experiments, -4 a
332
361
  * differentiated parameter is overridden, -5 derived targets without derived functions, -7
333
- * functions not set, or a failed experiment's negative solver code. */
362
+ * functions not set, or for a failed forward or backward solve -1000 plus the solver's negative
363
+ * code. */
334
364
  MXN_API int mxn_adjoint_vjp(int n_y, double *y0, int n_pars, double *pars, int n_theta,
335
365
  int *theta_idx, int n_targets, int *target_kind, int *target_index,
336
366
  int n_ovr, int *ovr_idx, int n_exp, int *exp_kind, int *exp_n_seg,
@@ -344,6 +374,41 @@ MXN_API int mxn_adjoint_vjp(int n_y, double *y0, int n_pars, double *pars, int n
344
374
  solver_id, rtol, atol, ss_tol, ss_t_max, out_pred, out_grad, out_lambda0);
345
375
  }
346
376
 
377
+ /* ------------------------------------------------------------------ */
378
+ /* Discrete adjoint gradients */
379
+ /* ------------------------------------------------------------------ */
380
+ /* Exported wrappers around mxl-solvers' discrete_adjoint.c (see its header for the
381
+ * arguments): mxn_da_forward integrates a protocol time course with RADAU5, LSODA or CVODE
382
+ * and records it on a tape (*out_tape, an opaque handle), mxn_da_backward returns the exact
383
+ * gradient of sum(cotangent * predictions) of that solution for any number of cotangents,
384
+ * mxn_da_free releases the tape. Tapes are independent, but a forward solve uses the
385
+ * solvers' global state, so only one runs at a time. */
386
+ MXN_API int mxn_da_forward(intptr_t model, intptr_t jac, intptr_t derived, int method, int n_y,
387
+ const double *y0, int n_pars, int n_seg, const double *seg_t_end,
388
+ const double *seg_pars, int n_points, const double *t_points,
389
+ int n_targets, const int *target_kind, const int *target_index,
390
+ int n_derived, double rtol, double atol, int nmax, int options,
391
+ double newton_scale, double max_tape_bytes, double *out_pred,
392
+ DaTape **out_tape) {
393
+ return da_forward(model, jac, derived, method, n_y, y0, n_pars, n_seg, seg_t_end, seg_pars,
394
+ n_points, t_points, n_targets, target_kind, target_index, n_derived, rtol,
395
+ atol, nmax, options, newton_scale, max_tape_bytes, out_pred, out_tape);
396
+ }
397
+
398
+ MXN_API int mxn_da_backward(DaTape *tape, intptr_t adjoint, intptr_t derived_grad, int n_theta,
399
+ const double *cotangent, double *out_grad, double *out_lambda0) {
400
+ return da_backward(tape, adjoint, derived_grad, n_theta, cotangent, out_grad, out_lambda0);
401
+ }
402
+
403
+ MXN_API int mxn_da_replay(const DaTape *tape, const double *seg_pars, const double *y0,
404
+ double *out_pred) {
405
+ return da_replay(tape, seg_pars, y0, out_pred);
406
+ }
407
+
408
+ MXN_API void mxn_da_free(DaTape *tape) { da_free(tape); }
409
+ MXN_API int mxn_da_tape_steps(const DaTape *tape) { return da_tape_steps(tape); }
410
+ MXN_API double mxn_da_tape_bytes(const DaTape *tape) { return da_tape_bytes(tape); }
411
+
347
412
  #ifdef MXN_WASM
348
413
  /* Model math stays inside wasm, rather than calling back into Python. */
349
414
  #define F1(name) double mxn_##name(double x) { return name(x); }
@@ -1,12 +1,12 @@
1
- # Vendored from https://github.com/Computational-Biology-Aachen/mxl-solvers at 183c01543986ea804afaaeae797d01207c1c7fa7.
1
+ # Vendored from https://github.com/Computational-Biology-Aachen/mxl-solvers at 0dd94e542c8ebfca2d021b0b714e58a0ce1d6c01.
2
2
  # Don't edit these files here: change mxl-solvers, then re-run its scripts/vendor.sh.
3
3
  da5d9b896c422aa002b6d8fc3c7003a6e6345454afd700ae65fa3cd944ab12e5 radau5.c
4
4
  8d2173c6ae898e77a71c2dc52e027ce2b6185d91170bd5f031b185aff6e1d354 dc_decsol.c
5
5
  9dc2c0ede63b1511813fbde4300c23a6c1e0536e4d316c6fd5492ae0f20d8195 decsol.c
6
6
  cf5d31866e63553809a79416b6baa957be45e3c03a5da59254fbbb317c735cfc f2c.h
7
7
  5ab404a0cbf7e02c21105b9f8322cb65ef78e10f40937740a9cc90b36796b8b8 libf2c_stubs.c
8
- 2f05643511057c06ceed0d8a1d7181857f93a759a60139d7506a4b6123654ac7 lsoda.c
9
- 751d5aa397f303b491d78f689dbf5b779f32b2d158b58c2b861d58143702e1f9 lsoda.h
8
+ 2a3f24685e1e99506afd9d8c8a7eeea06447645813cd23cbd368db6ef426ea3c lsoda.c
9
+ 1eef63be4ebc67b784b94a53505807248b880c63cf45a2b6ca1f0076d3cc825a lsoda.h
10
10
  8076d5b1bd27484ce6214cc5f9df7d6c88225182498538c9a878ed14d1743836 blaslapack_declarations.h
11
11
  c615cf28e6d41f150f631d0b7fa73f6b2d8b694a88818a38851f54b0efec042c mxs_lapack.c
12
12
  7d8f8f994e1c477fd023e0197fb7efde6287900010e96de3a3f188bc961cfb51 dop853.c
@@ -29,7 +29,10 @@ faac2ffbb50a7e0dad295bdf7f76e62fe625d3e6343ab1aa31b348d6fe5a411e minpack/lmpar.
29
29
  e69d3dde78e2724a74f0c94e328d38222aef85dd5f76dda49a3209d31eb4f58a minpack/minpackP.h
30
30
  58079701d6d569e71888e9fb3446f7e691db8f73ae0d8096cdfd92311eb4b0c6 minpack/qrfac.c
31
31
  fae6ee028024a1ea9f1fcf05cb0a840ee96c934aecd9e461d0266fda06b5abd1 minpack/qrsolv.c
32
- 3d71958c917a4f7eb85fdaeade0b274940a5e8b54b6c892dc877457c15b243d4 adjoint_wrapper.c
32
+ 80514e6a2cf6c8194b329979e2c89f3f10780622619d1f70f3fb012361b3f853 adjoint_wrapper.c
33
+ 1f1a41d4612766746ca6a48f2dea2d310b9c87c905813d8cc3b847c87dd862a1 discrete_adjoint.c
34
+ 7428b0dc5def76c85612661c687f8d11249b78a01e3734077fbc284b72a5dd7d discrete_adjoint.h
35
+ 27f173597a62f8c3b51355a9c9ac5a528e64c4a9157dd383a8c83177ee8a8bb0 nordsieck_tape.h
33
36
  0e9a5c3ba2637f05909967c3eeeac9c7b9a4a4c6e92801a408afd2aa725024e2 sundials/include/cvode/cvode.h
34
37
  adb1e5836989c630b595b14c0fa213426ddbfd3a87d14b581a470d5272b5881b sundials/include/cvode/cvode_diag.h
35
38
  84dfab497850c933b8020cc0b2236a2e85bfe5fceffe4b5aefc8a1b518dd68a3 sundials/include/cvode/cvode_ls.h
@@ -70,10 +73,10 @@ b1835f8bd9eecc879653d78782602123ca62b12fad1861f4c1973cadae2ec492 sundials/inclu
70
73
  76306ea569f779f18a1a79f82a27e6422db37e9bee0953099e65ec73095d109d sundials/include/sunmatrix/sunmatrix_sparse.h
71
74
  18afbd9ff9fd2a3ba9bbaecbb029250ec462571fa52f5562fa4f90255eba68af sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h
72
75
  ed507a3bb80066f07a267fdfe6e1af050b75dc896202585be69dcf8c8426761f sundials/include/sunnonlinsol/sunnonlinsol_newton.h
73
- 7590f4ec73215229be22479b3af8856395232191985eff364e30709aebe2322a sundials/src/cvode/cvode.c
76
+ 9ca065b7dd23a221d77d66db727a41a93022e880d2658e1d41547d3063b39418 sundials/src/cvode/cvode.c
74
77
  8a803cbdd874d462e4f8f1bebacea3e5aebed7b8cdc02dd94eaddc8637dcdee4 sundials/src/cvode/cvode_diag_impl.h
75
78
  33781c0673da6318a75b8577fe6d9f98800c6adcfff497ceeb15c9d8f95ef2d7 sundials/src/cvode/cvode_fused_stubs.c
76
- d22ef38c930b247dfaefc1d921ad3444f629a521998f0697c0227b29841da87d sundials/src/cvode/cvode_impl.h
79
+ 75a9d7dbb251fb09cd477756c1891c37b35b4e8944e9dfa02800ac1ff71bc075 sundials/src/cvode/cvode_impl.h
77
80
  e8fbe1785079b69f42c8d8c449c800512ab3a31f3c79f3226c7580283788b789 sundials/src/cvode/cvode_io.c
78
81
  31b16188b4257930832aeb5a4984d4fcebcb050c30cadf01603d63eb1ce07240 sundials/src/cvode/cvode_ls.c
79
82
  1c151437138df09b3b3f6d36be2453f068bfc5e04c05cc757152d85a0ff9a026 sundials/src/cvode/cvode_ls_impl.h
@@ -111,3 +114,4 @@ acc17ac1685b3ef154387b62ec8fe8f2b93d634c820d59d04b6d044f5c73bd66 sundials/src/s
111
114
  221e59f5e910fd7f94e44f0dac77436a11338c285c6346232e4a850a50da0e94 SCIPY-LICENCE.txt
112
115
  d83f244e1bef3d00a88d043d37d9cd2493c7aa19c9fbf35a837b310e867897a6 SUNDIALS-LICENCE.txt
113
116
  5cb9c6b0ca7c09b26fe2d1f9ef45231086c9ea2cdb32eb5f9dce7012e2364bc2 SUNDIALS-NOTICE.txt
117
+ ed87d347f0752da252ef700a1053338e10eda1e5be7f769688563a172b21ad2c finite_jacobian.h
@@ -103,6 +103,9 @@ void adjoint_set_progress_fn(intptr_t table_idx) {
103
103
  #define ADJOINT_INFO_BUDGET_REACHED 4
104
104
  /* Negative: genuine failure (allocation, or a solver IDID<0). */
105
105
  #define ADJOINT_INFO_ERROR (-1)
106
+ /* adjoint_vjp returns a failed solve's code (negative IDID or EXP_NOT_CONVERGED)
107
+ * offset by this, so it can't collide with its own setup errors (-1 .. -7). */
108
+ #define ADJOINT_VJP_SOLVE_FAILED (-1000)
106
109
 
107
110
  /* ------------------------------------------------------------------ */
108
111
  /* Forward-trajectory snapshot + cubic Hermite interpolation. */
@@ -505,8 +508,10 @@ static int backward_experiment(Pass *c, int e, const double *cot, double *grad_o
505
508
  * Returns 0, -1 on allocation failure, -3 if the experiment layout is
506
509
  * inconsistent, -4 if a parameter in theta_idx is also overridden, -5 if
507
510
  * derived targets lack set_derived_fn/set_derived_grad_fn, -7 without the
508
- * forward or adjoint function, or a failed experiment's negative solver code
509
- * (EXP_NOT_CONVERGED for a steady state that never converged).
511
+ * forward or adjoint function, or, for a failed forward or backward solve,
512
+ * ADJOINT_VJP_SOLVE_FAILED (-1000) plus the solver's negative code
513
+ * (EXP_NOT_CONVERGED for a steady state that never converged), so -1003 is
514
+ * RADAU5's IDID -3.
510
515
  */
511
516
  int adjoint_vjp(int n_y, double *y0, int n_pars, double *pars, int n_theta, int *theta_idx,
512
517
  int n_targets, int *target_kind, int *target_index, int n_ovr, int *ovr_idx,
@@ -543,12 +548,13 @@ int adjoint_vjp(int n_y, double *y0, int n_pars, double *pars, int n_theta, int
543
548
  }
544
549
  for (int e = 0; e < P.n_exp && rc == 0; e++) {
545
550
  rc = forward_experiment(&c, e, pars, y_work);
546
- if (rc == EXP_NO_MEMORY) rc = -1;
547
- if (rc == 0) {
551
+ if (rc == 0)
548
552
  rc = backward_experiment(&c, e, P.data_y, out_grad,
549
553
  out_lambda0 ? out_lambda0 + (size_t)e * n_y : NULL);
550
- if (rc == EXP_NO_MEMORY) rc = -1;
551
- }
554
+ if (rc == EXP_NO_MEMORY)
555
+ rc = -1;
556
+ else if (rc < 0)
557
+ rc += ADJOINT_VJP_SOLVE_FAILED;
552
558
  }
553
559
  pass_free(&c);
554
560
  free(y_work);