mxlpy-native 0.1.0__tar.gz → 0.2.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.
- mxlpy_native-0.2.0/MANIFEST.in +1 -0
- {mxlpy_native-0.1.0/src/mxlpy_native.egg-info → mxlpy_native-0.2.0}/PKG-INFO +2 -2
- mxlpy_native-0.2.0/README.md +5 -0
- mxlpy_native-0.1.0/c/mxn_radau.c → mxlpy_native-0.2.0/c/mxn_solvers.c +60 -4
- mxlpy_native-0.2.0/c/vendor/SCIPY-LICENCE.txt +30 -0
- mxlpy_native-0.2.0/c/vendor/VENDORED +13 -0
- mxlpy_native-0.2.0/c/vendor/blaslapack_declarations.h +16 -0
- mxlpy_native-0.2.0/c/vendor/lsoda.c +2321 -0
- mxlpy_native-0.2.0/c/vendor/lsoda.h +85 -0
- mxlpy_native-0.2.0/c/vendor/mxs_lapack.c +150 -0
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/pyproject.toml +2 -2
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/setup.py +6 -5
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/src/mxlpy_native/__init__.py +4 -4
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0/src/mxlpy_native.egg-info}/PKG-INFO +2 -2
- mxlpy_native-0.2.0/src/mxlpy_native.egg-info/SOURCES.txt +22 -0
- mxlpy_native-0.1.0/MANIFEST.in +0 -1
- mxlpy_native-0.1.0/README.md +0 -3
- mxlpy_native-0.1.0/c/README.md +0 -3
- mxlpy_native-0.1.0/src/mxlpy_native.egg-info/SOURCES.txt +0 -17
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/HAIRER-LICENCE.txt +0 -0
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/dc_decsol.c +0 -0
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/decsol.c +0 -0
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/f2c.h +0 -0
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/libf2c_stubs.c +0 -0
- {mxlpy_native-0.1.0/c → mxlpy_native-0.2.0/c/vendor}/radau5.c +0 -0
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/setup.cfg +0 -0
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/src/mxlpy_native.egg-info/dependency_links.txt +0 -0
- {mxlpy_native-0.1.0 → mxlpy_native-0.2.0}/src/mxlpy_native.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include c/*.c c/vendor/*.c c/vendor/*.h c/vendor/*.txt c/vendor/VENDORED
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# mxlpy-native
|
|
2
|
+
|
|
3
|
+
The compiled Radau and LSODA solvers behind MxlPy's `Native` integrator. Install it with `pip install "mxlpy[native]"`, not on its own.
|
|
4
|
+
|
|
5
|
+
`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/integrators/test_native_vendor.py` checks. Fix solvers there, not here. `c/mxn_solvers.c` is MxlPy's own glue, compiled unchanged into both the wheel and `solvers.wasm`.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
/* RADAU5 for MxlPy's Native integrator, returning values at requested time
|
|
2
|
-
* The same source builds the native wheel and
|
|
3
|
-
*
|
|
1
|
+
/* RADAU5 and LSODA for MxlPy's Native integrator, returning values at requested time
|
|
2
|
+
* points. The same source builds the native wheel and solvers.wasm. The solvers
|
|
3
|
+
* themselves are vendored from mxl-solvers (see vendor/VENDORED). RADAU5 and this
|
|
4
|
+
* file keep global state, so only one solve can run at a time in a process. */
|
|
4
5
|
#include "f2c.h"
|
|
6
|
+
#include "lsoda.h"
|
|
5
7
|
#include <math.h>
|
|
6
8
|
#include <stdint.h>
|
|
7
9
|
#include <stdlib.h>
|
|
@@ -23,6 +25,7 @@ extern double radau5_jac_growth;
|
|
|
23
25
|
|
|
24
26
|
typedef void (*ModelFn)(int, double, double *, double *, double *);
|
|
25
27
|
static ModelFn g_model;
|
|
28
|
+
static double *g_pars; /* LSODA's right-hand side takes no parameter array. */
|
|
26
29
|
static const double *g_t_out;
|
|
27
30
|
static double *g_y_out;
|
|
28
31
|
static int g_n_out, g_next;
|
|
@@ -100,6 +103,59 @@ MXN_API int mxn_radau(int n, double *y, double *pars, double rtol, double atol,
|
|
|
100
103
|
return (int)idid;
|
|
101
104
|
}
|
|
102
105
|
|
|
106
|
+
static void lsoda_fcn(int *n, double *t, double *y, double *dydt) { g_model(*n, *t, y, dydt, g_pars); }
|
|
107
|
+
|
|
108
|
+
/* Same contract as mxn_radau, with LSODA (SciPy's C translation) and its internal
|
|
109
|
+
* finite-difference Jacobian. nmax caps the total number of steps. Returns 2 on
|
|
110
|
+
* success, or LSODA's negative ISTATE: -1 too many steps, -2 too much accuracy
|
|
111
|
+
* requested, -3 bad input, -4 repeated error test failures, -5 repeated convergence
|
|
112
|
+
* failures, -6 an error weight became zero. Returns -9 if allocation fails or the
|
|
113
|
+
* result isn't finite. */
|
|
114
|
+
MXN_API int mxn_lsoda(int n, double *y, double *pars, double rtol, double atol, int nmax, int n_out,
|
|
115
|
+
const double *t_out, double *y_out) {
|
|
116
|
+
/* Work array sizes as in SciPy's odepack: Adams up to order 12, BDF up to 5. */
|
|
117
|
+
const int lrn = 20 + n * 13 + 3 * n, lrs = 20 + n * 6 + 3 * n + n * n + 2;
|
|
118
|
+
const int lrw = lrn > lrs ? lrn : lrs, liw = 20 + n;
|
|
119
|
+
double *rwork = calloc((size_t)lrw, sizeof(double));
|
|
120
|
+
int *iwork = calloc((size_t)liw, sizeof(int));
|
|
121
|
+
if (!rwork || !iwork) {
|
|
122
|
+
free(rwork);
|
|
123
|
+
free(iwork);
|
|
124
|
+
return -9;
|
|
125
|
+
}
|
|
126
|
+
int itask = 1, istate = 1, iopt = 1;
|
|
127
|
+
iwork[5] = nmax; /* IWORK(6): steps allowed per output point */
|
|
128
|
+
lsoda_common_struct_t S = {0};
|
|
129
|
+
double t = t_out[0];
|
|
130
|
+
g_pars = pars;
|
|
131
|
+
memcpy(y_out, y, (size_t)n * sizeof(double));
|
|
132
|
+
for (int k = 1; k < n_out && istate > 0; k++) {
|
|
133
|
+
double tout = t_out[k];
|
|
134
|
+
if (tout != t_out[k - 1]) {
|
|
135
|
+
lsoda(lsoda_fcn, n, y, &t, &tout, 1, &rtol, &atol, &itask, &istate, &iopt, rwork, lrw, iwork, liw, NULL,
|
|
136
|
+
2, &S);
|
|
137
|
+
if (istate > 0 && iwork[10] > nmax) istate = -1; /* IWORK(11): steps so far */
|
|
138
|
+
}
|
|
139
|
+
memcpy(y_out + (size_t)k * (size_t)n, y, (size_t)n * sizeof(double));
|
|
140
|
+
}
|
|
141
|
+
free(rwork);
|
|
142
|
+
free(iwork);
|
|
143
|
+
if (istate < 0) return istate;
|
|
144
|
+
for (int i = 0; i < n; i++) {
|
|
145
|
+
if (!isfinite(y[i])) return -9;
|
|
146
|
+
}
|
|
147
|
+
return 2;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Evaluates fn once per row of y, writing n_out values per row into out. */
|
|
151
|
+
MXN_API void mxn_eval_rows(intptr_t fn, int n, int n_out, int rows, const double *t, double *y, double *out,
|
|
152
|
+
double *pars) {
|
|
153
|
+
ModelFn f = (ModelFn)fn;
|
|
154
|
+
for (int r = 0; r < rows; r++) {
|
|
155
|
+
f(n, t[r], y + (size_t)r * (size_t)n, out + (size_t)r * (size_t)n_out, pars);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
103
159
|
#ifdef MXN_WASM
|
|
104
160
|
/* Model math stays inside wasm, rather than calling back into Python. */
|
|
105
161
|
#define F1(name) double mxn_##name(double x) { return name(x); }
|
|
@@ -109,5 +165,5 @@ double mxn_pow(double a, double b) { return pow(a, b); }
|
|
|
109
165
|
#else
|
|
110
166
|
/* Loaded with ctypes, but setuptools builds it as an extension and Windows linkers
|
|
111
167
|
* insist on this symbol. It's never imported. */
|
|
112
|
-
MXN_API void
|
|
168
|
+
MXN_API void PyInit__solvers(void) {}
|
|
113
169
|
#endif
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Copyright (c) 2001-2002 Enthought, Inc. 2003, SciPy Developers.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above
|
|
12
|
+
copyright notice, this list of conditions and the following
|
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
|
14
|
+
with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived
|
|
18
|
+
from this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Vendored from https://github.com/Computational-Biology-Aachen/mxl-solvers at 497e21745295b74821db0e1b836812edbc180e29.
|
|
2
|
+
# Don't edit these files here: change mxl-solvers, then re-run its scripts/vendor.sh.
|
|
3
|
+
da5d9b896c422aa002b6d8fc3c7003a6e6345454afd700ae65fa3cd944ab12e5 radau5.c
|
|
4
|
+
8d2173c6ae898e77a71c2dc52e027ce2b6185d91170bd5f031b185aff6e1d354 dc_decsol.c
|
|
5
|
+
9dc2c0ede63b1511813fbde4300c23a6c1e0536e4d316c6fd5492ae0f20d8195 decsol.c
|
|
6
|
+
cf5d31866e63553809a79416b6baa957be45e3c03a5da59254fbbb317c735cfc f2c.h
|
|
7
|
+
5ab404a0cbf7e02c21105b9f8322cb65ef78e10f40937740a9cc90b36796b8b8 libf2c_stubs.c
|
|
8
|
+
2f05643511057c06ceed0d8a1d7181857f93a759a60139d7506a4b6123654ac7 lsoda.c
|
|
9
|
+
751d5aa397f303b491d78f689dbf5b779f32b2d158b58c2b861d58143702e1f9 lsoda.h
|
|
10
|
+
8076d5b1bd27484ce6214cc5f9df7d6c88225182498538c9a878ed14d1743836 blaslapack_declarations.h
|
|
11
|
+
c615cf28e6d41f150f631d0b7fa73f6b2d8b694a88818a38851f54b0efec042c mxs_lapack.c
|
|
12
|
+
49bcfad0e3bbe5c3a0428624254567f32786948332a3204fc1e35b8b2a02b0fd HAIRER-LICENCE.txt
|
|
13
|
+
221e59f5e910fd7f94e44f0dac77436a11338c285c6346232e4a850a50da0e94 SCIPY-LICENCE.txt
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* Replaces SciPy's header of the same name, so lsoda.c and lsoda.h compile unchanged
|
|
2
|
+
* without BLAS or LAPACK. The routines come from mxs_lapack.c, under an mxs_ prefix
|
|
3
|
+
* so they never clash with a real BLAS loaded in the same process. */
|
|
4
|
+
#ifndef BLASLAPACK_DECLARATIONS_H
|
|
5
|
+
#define BLASLAPACK_DECLARATIONS_H
|
|
6
|
+
|
|
7
|
+
#define CBLAS_INT int
|
|
8
|
+
#define BLAS_FUNC(name) mxs_##name
|
|
9
|
+
|
|
10
|
+
void mxs_dgetrf(int *m, int *n, double *a, int *lda, int *ipiv, int *info);
|
|
11
|
+
void mxs_dgetrs(char *trans, int *n, int *nrhs, double *a, int *lda, int *ipiv, double *b, int *ldb, int *info);
|
|
12
|
+
void mxs_dgbtrf(int *m, int *n, int *kl, int *ku, double *ab, int *ldab, int *ipiv, int *info);
|
|
13
|
+
void mxs_dgbtrs(char *trans, int *n, int *kl, int *ku, int *nrhs, double *ab, int *ldab, int *ipiv, double *b,
|
|
14
|
+
int *ldb, int *info);
|
|
15
|
+
|
|
16
|
+
#endif
|