pkpdutils-core 0.2.1__tar.gz → 0.2.2__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.
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/Cargo.lock +5 -5
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/Cargo.toml +1 -1
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/PKG-INFO +1 -1
- {pkpdutils_core-0.2.1/crates/core → pkpdutils_core-0.2.2/crates/abi}/README.md +4 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/Cargo.toml +2 -2
- {pkpdutils_core-0.2.1/crates/units → pkpdutils_core-0.2.2/crates/core}/README.md +4 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/terminal.rs +95 -8
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/Cargo.toml +2 -2
- {pkpdutils_core-0.2.1/crates/abi → pkpdutils_core-0.2.2/crates/units}/README.md +4 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/tests/data/pint_gate.json +18156 -7345
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/tests/pint_gate.rs +2 -2
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/LICENSE +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/README.md +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/Cargo.toml +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/batch.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/enums.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/lib.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/nonfinite.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/options.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/result.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/src/window.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/enum_values.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_all_fields.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_default.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_effect.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_full.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_manual_points.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/data/options_windows.json +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/abi/tests/options_from_python.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/examples/kernel_timing.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/assemble.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/auc.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/blq.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/dose.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/lib.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/pack.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/parameters.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/core/src/shard.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/LICENSE +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/README.md +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/src/convert.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/src/lib.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/src/options.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/src/result.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/python/tests/test_bindings.py +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/Cargo.toml +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/src/format.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/src/lib.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/src/parameter.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/crates/units/src/registry.rs +0 -0
- {pkpdutils_core-0.2.1 → pkpdutils_core-0.2.2}/pyproject.toml +0 -0
|
@@ -238,7 +238,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
|
238
238
|
|
|
239
239
|
[[package]]
|
|
240
240
|
name = "pkpdutils-abi"
|
|
241
|
-
version = "0.2.
|
|
241
|
+
version = "0.2.2"
|
|
242
242
|
dependencies = [
|
|
243
243
|
"bitflags",
|
|
244
244
|
"serde",
|
|
@@ -248,7 +248,7 @@ dependencies = [
|
|
|
248
248
|
|
|
249
249
|
[[package]]
|
|
250
250
|
name = "pkpdutils-core"
|
|
251
|
-
version = "0.2.
|
|
251
|
+
version = "0.2.2"
|
|
252
252
|
dependencies = [
|
|
253
253
|
"pkpdutils-abi",
|
|
254
254
|
"pkpdutils-units",
|
|
@@ -258,7 +258,7 @@ dependencies = [
|
|
|
258
258
|
|
|
259
259
|
[[package]]
|
|
260
260
|
name = "pkpdutils-oracles"
|
|
261
|
-
version = "0.2.
|
|
261
|
+
version = "0.2.2"
|
|
262
262
|
dependencies = [
|
|
263
263
|
"pkpdutils-abi",
|
|
264
264
|
"pkpdutils-core",
|
|
@@ -270,7 +270,7 @@ dependencies = [
|
|
|
270
270
|
|
|
271
271
|
[[package]]
|
|
272
272
|
name = "pkpdutils-python"
|
|
273
|
-
version = "0.2.
|
|
273
|
+
version = "0.2.2"
|
|
274
274
|
dependencies = [
|
|
275
275
|
"mimalloc",
|
|
276
276
|
"numpy",
|
|
@@ -281,7 +281,7 @@ dependencies = [
|
|
|
281
281
|
|
|
282
282
|
[[package]]
|
|
283
283
|
name = "pkpdutils-units"
|
|
284
|
-
version = "0.2.
|
|
284
|
+
version = "0.2.2"
|
|
285
285
|
dependencies = [
|
|
286
286
|
"serde",
|
|
287
287
|
"serde_json",
|
|
@@ -168,6 +168,10 @@ uv run --with-editable path/to/pkpdutils python scripts/crosswalk_gate.py --chec
|
|
|
168
168
|
|
|
169
169
|
`scripts/pint_gate.py` writes `crates/units/tests/data/pint_gate.json`, pint's answer for every unit spelling of the package and every derived parameter unit, and `scripts/crosswalk_gate.py` writes `crates/oracles/tests/data/crosswalk.json`, the map from the variables of `pkpdutils` to the column names of the three NCA tools; the sections above describe both. `scripts/vendor_oracles.py --check` is the third, and it needs no checkout unless `--source` is given.
|
|
170
170
|
|
|
171
|
+
## Release
|
|
172
|
+
|
|
173
|
+
A tag `vx.y.z` publishes the distribution to PyPI and creates the release of this repository from `release-notes/x.y.z.md`. [docs/release.md](docs/release.md) has the steps.
|
|
174
|
+
|
|
171
175
|
## License
|
|
172
176
|
|
|
173
177
|
MIT, see `LICENSE`.
|
|
@@ -14,8 +14,8 @@ categories.workspace = true
|
|
|
14
14
|
[dependencies]
|
|
15
15
|
# the version is what a published `pkpdutils-core` resolves against; the path is
|
|
16
16
|
# what the workspace builds
|
|
17
|
-
pkpdutils-abi = { path = "../abi", version = "0.2.
|
|
18
|
-
pkpdutils-units = { path = "../units", version = "0.2.
|
|
17
|
+
pkpdutils-abi = { path = "../abi", version = "0.2.2" }
|
|
18
|
+
pkpdutils-units = { path = "../units", version = "0.2.2" }
|
|
19
19
|
thiserror.workspace = true
|
|
20
20
|
rayon = { workspace = true, optional = true }
|
|
21
21
|
|
|
@@ -168,6 +168,10 @@ uv run --with-editable path/to/pkpdutils python scripts/crosswalk_gate.py --chec
|
|
|
168
168
|
|
|
169
169
|
`scripts/pint_gate.py` writes `crates/units/tests/data/pint_gate.json`, pint's answer for every unit spelling of the package and every derived parameter unit, and `scripts/crosswalk_gate.py` writes `crates/oracles/tests/data/crosswalk.json`, the map from the variables of `pkpdutils` to the column names of the three NCA tools; the sections above describe both. `scripts/vendor_oracles.py --check` is the third, and it needs no checkout unless `--source` is given.
|
|
170
170
|
|
|
171
|
+
## Release
|
|
172
|
+
|
|
173
|
+
A tag `vx.y.z` publishes the distribution to PyPI and creates the release of this repository from `release-notes/x.y.z.md`. [docs/release.md](docs/release.md) has the steps.
|
|
174
|
+
|
|
171
175
|
## License
|
|
172
176
|
|
|
173
177
|
MIT, see `LICENSE`.
|
|
@@ -30,6 +30,25 @@ use pkpdutils_abi::{NcaFlag, TerminalMethod, TerminalPhase};
|
|
|
30
30
|
/// The half-lives a terminal window should cover at least, `SPAN_MINIMUM` of `nca.py`.
|
|
31
31
|
pub(crate) const SPAN_MINIMUM: f64 = 2.0;
|
|
32
32
|
|
|
33
|
+
/// Multiple of `n * eps * syy` below which a residual sum of squares is zero.
|
|
34
|
+
///
|
|
35
|
+
/// The residual of a window is `syy_c - slope * sxy_c`, two quantities which
|
|
36
|
+
/// are equal for a perfect fit, so what is left there is the rounding of the
|
|
37
|
+
/// sums themselves and its sign is arbitrary. Clamping it at zero reported
|
|
38
|
+
/// either 0 or the square root of that noise, around 1e-9, and which one
|
|
39
|
+
/// depended on the platform: this kernel and the python core disagreed on a
|
|
40
|
+
/// noise free curve, which the engine gate of `pkpdutils` caught.
|
|
41
|
+
///
|
|
42
|
+
/// The floor is taken against the uncentred `syy` and not against `syy_c`,
|
|
43
|
+
/// because every window of a row shares one origin, the row's first sample,
|
|
44
|
+
/// so a short window late in the curve has `syy` and `sy * sy / n` both of
|
|
45
|
+
/// the order of the whole drop of the curve while their difference is small.
|
|
46
|
+
/// The multiple is 16 from measurement over 120 000 windows: the ratio
|
|
47
|
+
/// `|ss_res| / (n * eps * syy)` reaches 1.20 for a noise free curve and stays
|
|
48
|
+
/// above 1.9e+05 for a curve of 1 % noise from four samples up. It must stay
|
|
49
|
+
/// identical to `pkpdutils.nca.terminal.RESIDUAL_FLOOR`.
|
|
50
|
+
pub(crate) const RESIDUAL_FLOOR: f64 = 16.0 * f64::EPSILON;
|
|
51
|
+
|
|
33
52
|
/// The regression statistics of one window.
|
|
34
53
|
#[derive(Debug, Clone, Copy)]
|
|
35
54
|
pub(crate) struct WindowStats {
|
|
@@ -151,15 +170,20 @@ fn window_of(sums: Sums, x_origin: f64, y_origin: f64) -> WindowStats {
|
|
|
151
170
|
let syy_c = syy - sy * sy / n;
|
|
152
171
|
if n >= 3.0 && sxx_c > 0.0 && syy_c > 0.0 {
|
|
153
172
|
let slope = sxy_c / sxx_c;
|
|
154
|
-
let
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
let raw = syy_c - slope * sxy_c;
|
|
174
|
+
// the residual subtracts two quantities which are equal for a perfect
|
|
175
|
+
// fit, so below the rounding of its own operands it is not a small
|
|
176
|
+
// number but no number. A NaN fails this comparison and is kept,
|
|
177
|
+
// which is what `numpy.where` does on the python side as well, and a
|
|
178
|
+
// negative value is below the floor, which subsumes the `numpy.maximum`
|
|
179
|
+
// this replaces.
|
|
180
|
+
let residual = if raw < RESIDUAL_FLOOR * n * syy {
|
|
161
181
|
0.0
|
|
182
|
+
} else {
|
|
183
|
+
raw
|
|
162
184
|
};
|
|
185
|
+
// `numpy.clip` lets a NaN through, which `f64::clamp` does as well
|
|
186
|
+
let r2 = (1.0 - residual / syy_c).clamp(0.0, 1.0);
|
|
163
187
|
WindowStats {
|
|
164
188
|
n,
|
|
165
189
|
slope,
|
|
@@ -652,6 +676,66 @@ pub(crate) fn span_flag(fit: &TerminalFit) -> NcaFlag {
|
|
|
652
676
|
|
|
653
677
|
#[cfg(test)]
|
|
654
678
|
mod tests {
|
|
679
|
+
|
|
680
|
+
#[test]
|
|
681
|
+
fn an_exact_fit_has_no_residual_in_any_window() {
|
|
682
|
+
// the residual `syy_c - slope * sxy_c` is zero for a perfect fit, so
|
|
683
|
+
// what survived the subtraction was the rounding of the sums and its
|
|
684
|
+
// sign decided between 0.0 and the square root of that noise, around
|
|
685
|
+
// 1e-9. Half of a batch therefore carried a standard error made of
|
|
686
|
+
// nothing, and which half differed between this kernel and the python
|
|
687
|
+
// core: the engine gate of `pkpdutils` failed on linux while passing
|
|
688
|
+
// on the developer's machine for the same commit. Every window of the
|
|
689
|
+
// row is checked, because the floor is written against the uncentred
|
|
690
|
+
// `syy` precisely for the short ones late in the curve, whose sums
|
|
691
|
+
// carry the whole drop while their difference is small.
|
|
692
|
+
let times = [0.25_f64, 0.5, 1.0, 2.0, 4.0, 6.0, 8.0, 12.0];
|
|
693
|
+
let regressable = [true; 8];
|
|
694
|
+
let mut out = [WindowStats::NONE; 8];
|
|
695
|
+
let mut checked = 0_usize;
|
|
696
|
+
for step in 0..512 {
|
|
697
|
+
let k = 0.05 + 0.45 * (step as f64) / 511.0;
|
|
698
|
+
let y: Vec<f64> = times.iter().map(|t| (10.0 * (-k * t).exp()).ln()).collect();
|
|
699
|
+
window_statistics(×, &y, ®ressable, &mut out);
|
|
700
|
+
for (start, stats) in out.iter().enumerate() {
|
|
701
|
+
if stats.n >= 3.0 {
|
|
702
|
+
assert_eq!(
|
|
703
|
+
stats.se_slope, 0.0,
|
|
704
|
+
"k {k} start {start}: se_slope {}",
|
|
705
|
+
stats.se_slope
|
|
706
|
+
);
|
|
707
|
+
assert_eq!(stats.r2, 1.0, "k {k} start {start}: r2 {}", stats.r2);
|
|
708
|
+
let lambda_z = -stats.slope;
|
|
709
|
+
assert!(
|
|
710
|
+
(lambda_z - k).abs() < 1e-12,
|
|
711
|
+
"k {k} start {start}: {lambda_z}"
|
|
712
|
+
);
|
|
713
|
+
checked += 1;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
// columns 0 to 5 hold 8 down to 3 points, the last two are below three
|
|
718
|
+
assert_eq!(checked, 512 * 6, "every window of every curve was examined");
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
#[test]
|
|
722
|
+
fn a_noisy_fit_keeps_its_residual() {
|
|
723
|
+
// the floor must only reach an exact fit: four samples a few percent
|
|
724
|
+
// off sit far above it, so the standard error has to survive untouched
|
|
725
|
+
let times = [1.0_f64, 2.0, 4.0, 8.0];
|
|
726
|
+
let offsets = [1.03_f64, 0.97, 1.04, 0.96];
|
|
727
|
+
let y: Vec<f64> = times
|
|
728
|
+
.iter()
|
|
729
|
+
.zip(offsets)
|
|
730
|
+
.map(|(t, off)| (10.0 * (-0.2 * t).exp() * off).ln())
|
|
731
|
+
.collect();
|
|
732
|
+
let regressable = [true; 4];
|
|
733
|
+
let mut out = [WindowStats::NONE; 4];
|
|
734
|
+
window_statistics(×, &y, ®ressable, &mut out);
|
|
735
|
+
assert_eq!(out[0].n, 4.0);
|
|
736
|
+
assert!(out[0].se_slope > 1e-6, "se_slope {}", out[0].se_slope);
|
|
737
|
+
assert!(out[0].r2 < 1.0, "r2 {}", out[0].r2);
|
|
738
|
+
}
|
|
655
739
|
use super::*;
|
|
656
740
|
|
|
657
741
|
use pkpdutils_abi::TerminalMethod;
|
|
@@ -733,7 +817,10 @@ mod tests {
|
|
|
733
817
|
close(fit.intercept, 2.302_585_092_994_045);
|
|
734
818
|
close(fit.r2, 1.0);
|
|
735
819
|
close(fit.r2_adj, 1.0);
|
|
736
|
-
|
|
820
|
+
// an exact fit has no residual at all, not a small one: `RESIDUAL_FLOOR`
|
|
821
|
+
// takes the rounding of the sums to zero, so this is exactly 0.0 on
|
|
822
|
+
// every platform and agrees with the python core bit for bit
|
|
823
|
+
assert_eq!(fit.se_slope, 0.0, "no residual: {}", fit.se_slope);
|
|
737
824
|
|
|
738
825
|
// terminal.md section 1 step 1 and hazard 5: the sums are taken around the
|
|
739
826
|
// first valid point of the row, so the same curve measured from t = 1e8 gives
|
|
@@ -36,8 +36,8 @@ parallel = ["pkpdutils-core/parallel"]
|
|
|
36
36
|
# `parallel` feature of the kernel is not enabled here by default: which features a wheel carries
|
|
37
37
|
# is settled where the wheel is built, and a build without it runs every shard plan in the
|
|
38
38
|
# calling thread, which is the same numbers and one thread
|
|
39
|
-
pkpdutils-abi = { path = "../abi", version = "0.2.
|
|
40
|
-
pkpdutils-core = { path = "../core", version = "0.2.
|
|
39
|
+
pkpdutils-abi = { path = "../abi", version = "0.2.2" }
|
|
40
|
+
pkpdutils-core = { path = "../core", version = "0.2.2" }
|
|
41
41
|
pyo3 = { workspace = true }
|
|
42
42
|
numpy = { workspace = true }
|
|
43
43
|
# The allocator of the extension module, set as the `#[global_allocator]` in `src/lib.rs`. It is
|
|
@@ -168,6 +168,10 @@ uv run --with-editable path/to/pkpdutils python scripts/crosswalk_gate.py --chec
|
|
|
168
168
|
|
|
169
169
|
`scripts/pint_gate.py` writes `crates/units/tests/data/pint_gate.json`, pint's answer for every unit spelling of the package and every derived parameter unit, and `scripts/crosswalk_gate.py` writes `crates/oracles/tests/data/crosswalk.json`, the map from the variables of `pkpdutils` to the column names of the three NCA tools; the sections above describe both. `scripts/vendor_oracles.py --check` is the third, and it needs no checkout unless `--source` is given.
|
|
170
170
|
|
|
171
|
+
## Release
|
|
172
|
+
|
|
173
|
+
A tag `vx.y.z` publishes the distribution to PyPI and creates the release of this repository from `release-notes/x.y.z.md`. [docs/release.md](docs/release.md) has the steps.
|
|
174
|
+
|
|
171
175
|
## License
|
|
172
176
|
|
|
173
177
|
MIT, see `LICENSE`.
|