fastmixture2 2.0.4__tar.gz → 2.0.5__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.
- {fastmixture2-2.0.4/fastmixture2.egg-info → fastmixture2-2.0.5}/PKG-INFO +40 -54
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/README.md +39 -53
- fastmixture2-2.0.5/fastmixture2/__init__.py +1 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/em.pyx +32 -24
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/fastmixture2.py +19 -12
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/functions.py +102 -18
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/gpu.py +366 -300
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/kernels.py +54 -20
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/main.py +12 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/packed.pxd +17 -1
- fastmixture2-2.0.5/fastmixture2/plink.py +119 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/shared.pyx +45 -35
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/sqp.pyx +19 -15
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/svd.pyx +13 -9
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/utils.py +131 -82
- {fastmixture2-2.0.4 → fastmixture2-2.0.5/fastmixture2.egg-info}/PKG-INFO +40 -54
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2.egg-info/SOURCES.txt +4 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/check_portable.py +5 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_adversarial_io.py +1 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_bootstrap.py +2 -2
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_cli.py +18 -3
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_convergence.py +2 -2
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_cpu_subset.py +6 -4
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_cross_validation.py +1 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_called.py +28 -1
- fastmixture2-2.0.5/tests/test_gpu_em.py +256 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_gl_precision.py +2 -2
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_large.py +2 -4
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_modes.py +6 -2
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_precision.py +3 -3
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_safety.py +8 -8
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_streamed.py +30 -5
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_subset.py +4 -2
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_svd_cache.py +26 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_initialization.py +49 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_likelihoods.py +32 -35
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_numerical_equivalence.py +92 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_optimizers.py +11 -11
- fastmixture2-2.0.5/tests/test_plink_files.py +493 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_q_constraints.py +2 -2
- fastmixture2-2.0.5/tests/test_restarts.py +362 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/validate_distribution.py +1 -0
- fastmixture2-2.0.4/fastmixture2/__init__.py +0 -1
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/LICENSE +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/MANIFEST.in +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/defaults.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2/threads.pxd +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2.egg-info/dependency_links.txt +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2.egg-info/entry_points.txt +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2.egg-info/requires.txt +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/fastmixture2.egg-info/top_level.txt +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/pyproject.toml +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/setup.cfg +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/setup.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/helpers.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/run_tests.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_cpu_scaling.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_distribution.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_frequency_cache.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_genotypes.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_stat_reuse.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_gpu_supervision.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_sqp_scoring.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_sqp_solver.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_subset_modes.py +0 -0
- {fastmixture2-2.0.4 → fastmixture2-2.0.5}/tests/test_threads.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastmixture2
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: Biobank-scale ancestry estimation in unrelated individuals
|
|
5
5
|
Author-email: "J. Meisner" <meisnerucph@gmail.com>, "L. Thunegard" <lisathunegard@icloud.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -111,11 +111,25 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
|
111
111
|
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
- `--bfile` takes
|
|
115
|
-
files. Genotypes stay packed on CPU and GPU. Missing genotypes are
|
|
114
|
+
- `--bfile` takes one or more ordered prefixes of SNP-major PLINK `.bed`, `.bim`
|
|
115
|
+
and `.fam` files. Genotypes stay packed on CPU and GPU. Missing genotypes are
|
|
116
|
+
supported.
|
|
116
117
|
- `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
|
|
117
118
|
internally. Exactly uniform triplets contribute no ancestry information.
|
|
118
119
|
|
|
120
|
+
Per-chromosome inputs are fitted jointly without creating a merged BED:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
|
|
127
|
+
such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
|
|
128
|
+
in the same order. Marker rows, including annotated P output, follow the supplied
|
|
129
|
+
file order. The files remain memory-mapped, with an additional native address
|
|
130
|
+
per marker (8 bytes on 64-bit systems) and bounded transfer tiles. This works
|
|
131
|
+
with CPU, CUDA, supervised estimation, projection, CV, bootstrap and checkpoints.
|
|
132
|
+
|
|
119
133
|
Perform sample and variant QC first. For each K, try several seeds and keep
|
|
120
134
|
the converged fit with the highest log-likelihood. Component labels may change
|
|
121
135
|
between runs, so align them before comparing Q or P.
|
|
@@ -125,6 +139,15 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
|
|
|
125
139
|
in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
|
|
126
140
|
Resuming a checkpoint retains its saved estimates.
|
|
127
141
|
|
|
142
|
+
Add `--restarts N` to try N additional restart attempts in unsupervised mode (default 0).
|
|
143
|
+
Each starts from the original finished fit, permutes Q columns while retaining P, and
|
|
144
|
+
jointly refines a fresh genome-wide 50,000-SNP subset. Smaller panels use all SNPs.
|
|
145
|
+
Larger panels then project P and refit the full data. Only full-data improvements are
|
|
146
|
+
retained. This works with both input formats on CPU and CUDA, uses `--seed`,
|
|
147
|
+
and keeps the same `--iter` and `--tole` per stage. CV and bootstrap retain their
|
|
148
|
+
usual refit settings.
|
|
149
|
+
At K = 1 it has no effect.
|
|
150
|
+
|
|
128
151
|
Add `--gpu` to use CUDA with either input format:
|
|
129
152
|
|
|
130
153
|
```bash
|
|
@@ -142,67 +165,28 @@ retain the refined subset rows. This applies to both input formats, including
|
|
|
142
165
|
missing genotypes.
|
|
143
166
|
Panels up to 50,000 SNPs proceed directly from SVD/ALS to full-data refinement,
|
|
144
167
|
without a duplicate subset fit or projection. For PLINK, subset refinement is
|
|
145
|
-
skipped if any sample has no observed subset genotypes. Exact CV folds
|
|
146
|
-
|
|
168
|
+
skipped if any sample has no observed subset genotypes. Exact CV folds skip
|
|
169
|
+
subset likelihood refinement.
|
|
147
170
|
|
|
148
171
|
Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
|
|
149
172
|
into a temporary memory-mapped file. CUDA streams the subset when it does not
|
|
150
173
|
fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
|
|
151
174
|
storage.
|
|
152
175
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
Genotype-likelihood fits use Q-first SQP/ZAL on both CPU and CUDA, with exact
|
|
163
|
-
EM/QN rescue and an independent EM check before convergence. CUDA fits start
|
|
164
|
-
with float32 probabilities, derivatives and statistics in either storage mode,
|
|
165
|
-
then switch to float64 refinement. Near frequency bounds, GL probabilities
|
|
166
|
-
and derivatives use float64. cuBLAS tile sums, parameters, solves and scores stay
|
|
167
|
-
in float64.
|
|
168
|
-
CPU and CUDA start directly with SQP and use ZAL history depth 3.
|
|
169
|
-
`--iter` and `--tole` apply to each SQP/ZAL stage.
|
|
170
|
-
EM skips missing genotypes and exactly uniform likelihood triplets, with
|
|
171
|
-
normalization over informative entries. Nonuniform likelihoods are retained.
|
|
172
|
-
Full likelihood scores retain the constant contribution from uniform triplets.
|
|
173
|
-
|
|
174
|
-
CPU SQP uses tiled BLAS statistics for Q and P at every supported K.
|
|
175
|
-
This applies to PLINK and genotype likelihoods in all modes.
|
|
176
|
-
BLAS scratch and P statistics each have a separate 512 MiB cap. Q statistics
|
|
177
|
-
use 4096-sample shards with a separate 4 GiB cap. Optional update caches
|
|
178
|
-
remain capped at 64 MiB. Input storage, factors and optimizer history are
|
|
179
|
-
additional allocations.
|
|
180
|
-
|
|
181
|
-
At K <= 16, CUDA fits use native kernels at K = 1..3
|
|
182
|
-
and tiled cuBLAS at K = 4..16 during float32 refinement. Resident tiles share
|
|
183
|
-
64 MiB of scratch and keep float32 copies of P and Q. At K = 8..16,
|
|
184
|
-
resident mixed fits reuse frequency scratch for cooperative float64 solves.
|
|
185
|
-
Tiles that cannot hold the solve tables use the native solve. Streamed fits keep
|
|
186
|
-
float32 copies within tiles and reuse their float64 Q-statistics buffers, with
|
|
187
|
-
up to 128 MiB of compute scratch.
|
|
188
|
-
Final refinement uses native float64 kernels, except
|
|
189
|
-
resident GL P updates at K = 8..16 with up to 1024 samples. Those share the tiled
|
|
190
|
-
cuBLAS P routine and keep combined scratch within 64 MiB.
|
|
191
|
-
Unsupervised resident PLINK fits at K = 10..16 keep the first eight iterations
|
|
192
|
-
fresh, then alternate Q-Hessian reuse during float32 refinement. The cache is
|
|
193
|
-
capped at 64 MiB. Weak cached proposals retry with fresh curvature, and
|
|
194
|
-
float64 refinement always uses fresh curvature.
|
|
195
|
-
|
|
196
|
-
At K > 16, CUDA uses tiled cuBLAS statistics and a cooperative active-set
|
|
197
|
-
solver for both input formats. Resident and bootstrap maps share 64 MiB of
|
|
198
|
-
scratch. Streamed maps allow up to 128 MiB of compute scratch and 512 MiB of
|
|
199
|
-
Q statistics, with free-VRAM guards. Streamed tiles adapt to the panel width,
|
|
200
|
-
with at most 8192 rows within the same memory caps. Curvature stays fresh.
|
|
176
|
+
Refinement uses safeguarded SQP/ZAL with EM/QN rescue when needed, for both
|
|
177
|
+
input formats and all modes. CPU refinement uses float64. CUDA uses mixed
|
|
178
|
+
SQP statistics before final float64 refinement. Parameters, constrained solves,
|
|
179
|
+
EM/QN and likelihood checks stay in float64. EM/QN runs on CUDA for both
|
|
180
|
+
resident and streamed input. PLINK rescue falls back to CPU if a CUDA allocation
|
|
181
|
+
fails.
|
|
182
|
+
|
|
183
|
+
Workspaces use bounded blocks. Input storage, Q, P and optimizer history are
|
|
184
|
+
additional allocations that grow with panel size and K.
|
|
201
185
|
|
|
202
186
|
The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
203
187
|
`--threads` caps CPU computation, including BLAS and GPU host copies.
|
|
204
188
|
The optimizer scales the tolerance by observed genotypes or informative
|
|
205
|
-
likelihood triplets.
|
|
189
|
+
likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
|
|
206
190
|
Check the log for convergence. Run `fastmixture2 --help` for the full CLI.
|
|
207
191
|
|
|
208
192
|
### Beagle cache
|
|
@@ -322,6 +306,8 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
|
322
306
|
```
|
|
323
307
|
|
|
324
308
|
Keep the same input, supervision and projection files when resuming.
|
|
309
|
+
With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
|
|
310
|
+
requested number of additional restarts after the resumed fit.
|
|
325
311
|
|
|
326
312
|
## Output
|
|
327
313
|
|
|
@@ -80,11 +80,25 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
|
80
80
|
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
- `--bfile` takes
|
|
84
|
-
files. Genotypes stay packed on CPU and GPU. Missing genotypes are
|
|
83
|
+
- `--bfile` takes one or more ordered prefixes of SNP-major PLINK `.bed`, `.bim`
|
|
84
|
+
and `.fam` files. Genotypes stay packed on CPU and GPU. Missing genotypes are
|
|
85
|
+
supported.
|
|
85
86
|
- `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
|
|
86
87
|
internally. Exactly uniform triplets contribute no ancestry information.
|
|
87
88
|
|
|
89
|
+
Per-chromosome inputs are fitted jointly without creating a merged BED:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
|
|
96
|
+
such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
|
|
97
|
+
in the same order. Marker rows, including annotated P output, follow the supplied
|
|
98
|
+
file order. The files remain memory-mapped, with an additional native address
|
|
99
|
+
per marker (8 bytes on 64-bit systems) and bounded transfer tiles. This works
|
|
100
|
+
with CPU, CUDA, supervised estimation, projection, CV, bootstrap and checkpoints.
|
|
101
|
+
|
|
88
102
|
Perform sample and variant QC first. For each K, try several seeds and keep
|
|
89
103
|
the converged fit with the highest log-likelihood. Component labels may change
|
|
90
104
|
between runs, so align them before comparing Q or P.
|
|
@@ -94,6 +108,15 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
|
|
|
94
108
|
in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
|
|
95
109
|
Resuming a checkpoint retains its saved estimates.
|
|
96
110
|
|
|
111
|
+
Add `--restarts N` to try N additional restart attempts in unsupervised mode (default 0).
|
|
112
|
+
Each starts from the original finished fit, permutes Q columns while retaining P, and
|
|
113
|
+
jointly refines a fresh genome-wide 50,000-SNP subset. Smaller panels use all SNPs.
|
|
114
|
+
Larger panels then project P and refit the full data. Only full-data improvements are
|
|
115
|
+
retained. This works with both input formats on CPU and CUDA, uses `--seed`,
|
|
116
|
+
and keeps the same `--iter` and `--tole` per stage. CV and bootstrap retain their
|
|
117
|
+
usual refit settings.
|
|
118
|
+
At K = 1 it has no effect.
|
|
119
|
+
|
|
97
120
|
Add `--gpu` to use CUDA with either input format:
|
|
98
121
|
|
|
99
122
|
```bash
|
|
@@ -111,67 +134,28 @@ retain the refined subset rows. This applies to both input formats, including
|
|
|
111
134
|
missing genotypes.
|
|
112
135
|
Panels up to 50,000 SNPs proceed directly from SVD/ALS to full-data refinement,
|
|
113
136
|
without a duplicate subset fit or projection. For PLINK, subset refinement is
|
|
114
|
-
skipped if any sample has no observed subset genotypes. Exact CV folds
|
|
115
|
-
|
|
137
|
+
skipped if any sample has no observed subset genotypes. Exact CV folds skip
|
|
138
|
+
subset likelihood refinement.
|
|
116
139
|
|
|
117
140
|
Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
|
|
118
141
|
into a temporary memory-mapped file. CUDA streams the subset when it does not
|
|
119
142
|
fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
|
|
120
143
|
storage.
|
|
121
144
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Genotype-likelihood fits use Q-first SQP/ZAL on both CPU and CUDA, with exact
|
|
132
|
-
EM/QN rescue and an independent EM check before convergence. CUDA fits start
|
|
133
|
-
with float32 probabilities, derivatives and statistics in either storage mode,
|
|
134
|
-
then switch to float64 refinement. Near frequency bounds, GL probabilities
|
|
135
|
-
and derivatives use float64. cuBLAS tile sums, parameters, solves and scores stay
|
|
136
|
-
in float64.
|
|
137
|
-
CPU and CUDA start directly with SQP and use ZAL history depth 3.
|
|
138
|
-
`--iter` and `--tole` apply to each SQP/ZAL stage.
|
|
139
|
-
EM skips missing genotypes and exactly uniform likelihood triplets, with
|
|
140
|
-
normalization over informative entries. Nonuniform likelihoods are retained.
|
|
141
|
-
Full likelihood scores retain the constant contribution from uniform triplets.
|
|
142
|
-
|
|
143
|
-
CPU SQP uses tiled BLAS statistics for Q and P at every supported K.
|
|
144
|
-
This applies to PLINK and genotype likelihoods in all modes.
|
|
145
|
-
BLAS scratch and P statistics each have a separate 512 MiB cap. Q statistics
|
|
146
|
-
use 4096-sample shards with a separate 4 GiB cap. Optional update caches
|
|
147
|
-
remain capped at 64 MiB. Input storage, factors and optimizer history are
|
|
148
|
-
additional allocations.
|
|
149
|
-
|
|
150
|
-
At K <= 16, CUDA fits use native kernels at K = 1..3
|
|
151
|
-
and tiled cuBLAS at K = 4..16 during float32 refinement. Resident tiles share
|
|
152
|
-
64 MiB of scratch and keep float32 copies of P and Q. At K = 8..16,
|
|
153
|
-
resident mixed fits reuse frequency scratch for cooperative float64 solves.
|
|
154
|
-
Tiles that cannot hold the solve tables use the native solve. Streamed fits keep
|
|
155
|
-
float32 copies within tiles and reuse their float64 Q-statistics buffers, with
|
|
156
|
-
up to 128 MiB of compute scratch.
|
|
157
|
-
Final refinement uses native float64 kernels, except
|
|
158
|
-
resident GL P updates at K = 8..16 with up to 1024 samples. Those share the tiled
|
|
159
|
-
cuBLAS P routine and keep combined scratch within 64 MiB.
|
|
160
|
-
Unsupervised resident PLINK fits at K = 10..16 keep the first eight iterations
|
|
161
|
-
fresh, then alternate Q-Hessian reuse during float32 refinement. The cache is
|
|
162
|
-
capped at 64 MiB. Weak cached proposals retry with fresh curvature, and
|
|
163
|
-
float64 refinement always uses fresh curvature.
|
|
164
|
-
|
|
165
|
-
At K > 16, CUDA uses tiled cuBLAS statistics and a cooperative active-set
|
|
166
|
-
solver for both input formats. Resident and bootstrap maps share 64 MiB of
|
|
167
|
-
scratch. Streamed maps allow up to 128 MiB of compute scratch and 512 MiB of
|
|
168
|
-
Q statistics, with free-VRAM guards. Streamed tiles adapt to the panel width,
|
|
169
|
-
with at most 8192 rows within the same memory caps. Curvature stays fresh.
|
|
145
|
+
Refinement uses safeguarded SQP/ZAL with EM/QN rescue when needed, for both
|
|
146
|
+
input formats and all modes. CPU refinement uses float64. CUDA uses mixed
|
|
147
|
+
SQP statistics before final float64 refinement. Parameters, constrained solves,
|
|
148
|
+
EM/QN and likelihood checks stay in float64. EM/QN runs on CUDA for both
|
|
149
|
+
resident and streamed input. PLINK rescue falls back to CPU if a CUDA allocation
|
|
150
|
+
fails.
|
|
151
|
+
|
|
152
|
+
Workspaces use bounded blocks. Input storage, Q, P and optimizer history are
|
|
153
|
+
additional allocations that grow with panel size and K.
|
|
170
154
|
|
|
171
155
|
The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
172
156
|
`--threads` caps CPU computation, including BLAS and GPU host copies.
|
|
173
157
|
The optimizer scales the tolerance by observed genotypes or informative
|
|
174
|
-
likelihood triplets.
|
|
158
|
+
likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
|
|
175
159
|
Check the log for convergence. Run `fastmixture2 --help` for the full CLI.
|
|
176
160
|
|
|
177
161
|
### Beagle cache
|
|
@@ -291,6 +275,8 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
|
291
275
|
```
|
|
292
276
|
|
|
293
277
|
Keep the same input, supervision and projection files when resuming.
|
|
278
|
+
With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
|
|
279
|
+
requested number of additional restarts after the resumed fit.
|
|
294
280
|
|
|
295
281
|
## Output
|
|
296
282
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.0.5"
|
|
@@ -8,9 +8,9 @@ __author__ = "Jonas Meisner"
|
|
|
8
8
|
cimport openmp as omp
|
|
9
9
|
from cython.parallel import parallel, prange
|
|
10
10
|
from libc.math cimport fmax, fmin
|
|
11
|
-
from libc.stdint cimport uint8_t, uint32_t, uint64_t
|
|
11
|
+
from libc.stdint cimport uint8_t, uint32_t, uint64_t, uintptr_t
|
|
12
12
|
from libc.stdlib cimport calloc, free
|
|
13
|
-
from fastmixture2.packed cimport decodePacked, flatLikelihood, heldOut
|
|
13
|
+
from fastmixture2.packed cimport packedRow, packedCount, decodePacked, flatLikelihood, heldOut
|
|
14
14
|
|
|
15
15
|
ctypedef uint8_t u8
|
|
16
16
|
ctypedef uint32_t u32
|
|
@@ -1180,7 +1180,8 @@ cpdef int accelPacked(
|
|
|
1180
1180
|
const u8[:, ::1] B, const f64[:, ::1] P,
|
|
1181
1181
|
f64[:, ::1] P1, const f64[:, ::1] Q,
|
|
1182
1182
|
f64[:, ::1] T, const Py_ssize_t N,
|
|
1183
|
-
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0
|
|
1183
|
+
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0,
|
|
1184
|
+
const uintptr_t[::1] rows=None
|
|
1184
1185
|
) except -1 nogil:
|
|
1185
1186
|
cdef:
|
|
1186
1187
|
bint masked = fold >= 0
|
|
@@ -1193,7 +1194,7 @@ cpdef int accelPacked(
|
|
|
1193
1194
|
f64* p_all
|
|
1194
1195
|
f64* q_all
|
|
1195
1196
|
f64* t = &T[0, 0]
|
|
1196
|
-
Py_ssize_t M = B
|
|
1197
|
+
Py_ssize_t M = packedCount(B, rows)
|
|
1197
1198
|
Py_ssize_t K = Q.shape[1]
|
|
1198
1199
|
Py_ssize_t L
|
|
1199
1200
|
Py_ssize_t i, j, x
|
|
@@ -1221,9 +1222,9 @@ cpdef int accelPacked(
|
|
|
1221
1222
|
for j in prange(M, schedule="static"):
|
|
1222
1223
|
p = &P[j, 0]
|
|
1223
1224
|
if masked:
|
|
1224
|
-
_unpackPackedRowFold(
|
|
1225
|
+
_unpackPackedRowFold(packedRow(B, rows, j), g_thr, j, N, fold, folds, seed)
|
|
1225
1226
|
else:
|
|
1226
|
-
_unpackPackedRow(
|
|
1227
|
+
_unpackPackedRow(packedRow(B, rows, j), g_thr, N)
|
|
1227
1228
|
if not _specializedEmRow(g_thr, p, &Q[0, 0], &P1[j, 0], q_thr, N, K):
|
|
1228
1229
|
for i in range(N):
|
|
1229
1230
|
if g_thr[i] == 9:
|
|
@@ -1250,7 +1251,8 @@ cpdef int batchPackedW(
|
|
|
1250
1251
|
f64[:, ::1] P1, const f64[:, ::1] Q,
|
|
1251
1252
|
f64[:, ::1] T, const u32[::1] s, const u32[::1] w,
|
|
1252
1253
|
const Py_ssize_t N, Py_ssize_t fold=-1,
|
|
1253
|
-
Py_ssize_t folds=1, uint64_t seed=0
|
|
1254
|
+
Py_ssize_t folds=1, uint64_t seed=0,
|
|
1255
|
+
const uintptr_t[::1] rows=None
|
|
1254
1256
|
) except -1 nogil:
|
|
1255
1257
|
cdef:
|
|
1256
1258
|
bint masked = fold >= 0
|
|
@@ -1298,11 +1300,11 @@ cpdef int batchPackedW(
|
|
|
1298
1300
|
continue
|
|
1299
1301
|
if masked:
|
|
1300
1302
|
_unpackPackedRowFold(
|
|
1301
|
-
|
|
1303
|
+
packedRow(B, rows, marker), g_thr, marker, N,
|
|
1302
1304
|
fold, folds, seed
|
|
1303
1305
|
)
|
|
1304
1306
|
else:
|
|
1305
|
-
_unpackPackedRow(
|
|
1307
|
+
_unpackPackedRow(packedRow(B, rows, marker), g_thr, N)
|
|
1306
1308
|
if not _specializedEmRowW(
|
|
1307
1309
|
g_thr, p, &Q[0, 0], &P1[marker, 0], q_thr, wt[j], N, K
|
|
1308
1310
|
):
|
|
@@ -1330,7 +1332,8 @@ cpdef int stepQPacked(
|
|
|
1330
1332
|
const u8[:, ::1] B, const f64[:, ::1] P,
|
|
1331
1333
|
const f64[:, ::1] Q, f64[:, ::1] T,
|
|
1332
1334
|
const Py_ssize_t N, Py_ssize_t fold=-1,
|
|
1333
|
-
Py_ssize_t folds=1, uint64_t seed=0
|
|
1335
|
+
Py_ssize_t folds=1, uint64_t seed=0,
|
|
1336
|
+
const uintptr_t[::1] rows=None
|
|
1334
1337
|
) except -1 nogil:
|
|
1335
1338
|
cdef:
|
|
1336
1339
|
bint masked = fold >= 0
|
|
@@ -1339,7 +1342,7 @@ cpdef int stepQPacked(
|
|
|
1339
1342
|
f64* q_thr
|
|
1340
1343
|
f64* q_all
|
|
1341
1344
|
f64* t = &T[0, 0]
|
|
1342
|
-
Py_ssize_t M = B
|
|
1345
|
+
Py_ssize_t M = packedCount(B, rows)
|
|
1343
1346
|
Py_ssize_t K = Q.shape[1]
|
|
1344
1347
|
Py_ssize_t L
|
|
1345
1348
|
Py_ssize_t i, j, x
|
|
@@ -1362,9 +1365,9 @@ cpdef int stepQPacked(
|
|
|
1362
1365
|
g_thr = &g_all[tid * N]
|
|
1363
1366
|
for j in prange(M, schedule="static"):
|
|
1364
1367
|
if masked:
|
|
1365
|
-
_unpackPackedRowFold(
|
|
1368
|
+
_unpackPackedRowFold(packedRow(B, rows, j), g_thr, j, N, fold, folds, seed)
|
|
1366
1369
|
else:
|
|
1367
|
-
_unpackPackedRow(
|
|
1370
|
+
_unpackPackedRow(packedRow(B, rows, j), g_thr, N)
|
|
1368
1371
|
if not _specializedQRow(g_thr, &P[j, 0], &Q[0, 0], q_thr, N, K):
|
|
1369
1372
|
for i in range(N):
|
|
1370
1373
|
if g_thr[i] == 9:
|
|
@@ -1384,7 +1387,8 @@ cpdef int stepBatchQPackedW(
|
|
|
1384
1387
|
const u8[:, ::1] B, const f64[:, ::1] P, const f64[:, ::1] Q,
|
|
1385
1388
|
f64[:, ::1] T, const u32[::1] s, const u32[::1] w,
|
|
1386
1389
|
const Py_ssize_t N, Py_ssize_t fold=-1,
|
|
1387
|
-
Py_ssize_t folds=1, uint64_t seed=0
|
|
1390
|
+
Py_ssize_t folds=1, uint64_t seed=0,
|
|
1391
|
+
const uintptr_t[::1] rows=None
|
|
1388
1392
|
) except -1 nogil:
|
|
1389
1393
|
cdef:
|
|
1390
1394
|
bint masked = fold >= 0
|
|
@@ -1421,11 +1425,11 @@ cpdef int stepBatchQPackedW(
|
|
|
1421
1425
|
continue
|
|
1422
1426
|
if masked:
|
|
1423
1427
|
_unpackPackedRowFold(
|
|
1424
|
-
|
|
1428
|
+
packedRow(B, rows, marker), g_thr, marker, N,
|
|
1425
1429
|
fold, folds, seed
|
|
1426
1430
|
)
|
|
1427
1431
|
else:
|
|
1428
|
-
_unpackPackedRow(
|
|
1432
|
+
_unpackPackedRow(packedRow(B, rows, marker), g_thr, N)
|
|
1429
1433
|
if not _specializedQRowW(
|
|
1430
1434
|
g_thr, &P[marker, 0], &Q[0, 0], q_thr, wt[j], N, K
|
|
1431
1435
|
):
|
|
@@ -1718,13 +1722,14 @@ cdef int _tiledEm(
|
|
|
1718
1722
|
const f64[:, ::1] P,
|
|
1719
1723
|
f64[:, ::1] P1, const f64[:, ::1] Q, f64[:, ::1] T,
|
|
1720
1724
|
const Py_ssize_t N, const u32[::1] s=None, const u32[::1] weights=None,
|
|
1721
|
-
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0
|
|
1725
|
+
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0,
|
|
1726
|
+
const uintptr_t[::1] rows=None
|
|
1722
1727
|
) except -1 nogil:
|
|
1723
1728
|
cdef:
|
|
1724
1729
|
bint gl = L is not None
|
|
1725
|
-
Py_ssize_t M = (L.shape[0] if gl else B
|
|
1730
|
+
Py_ssize_t M = (L.shape[0] if gl else packedCount(B, rows)) if s is None else s.shape[0]
|
|
1726
1731
|
Py_ssize_t K = Q.shape[1]
|
|
1727
|
-
Py_ssize_t c = min(128, max(1, _EM_DATA_TILE_BYTES // (12 * N if gl else
|
|
1732
|
+
Py_ssize_t c = min(128, max(1, _EM_DATA_TILE_BYTES // (12 * N if gl else (N + 3) // 4)))
|
|
1728
1733
|
Py_ssize_t n_blk = min(4096, max(16, _EM_STATS_TILE_BYTES // (8 * K)))
|
|
1729
1734
|
Py_ssize_t mb, nb, b, e, beg, end, j, marker, z, i, k, x, r
|
|
1730
1735
|
int tid, n_thr, n_use
|
|
@@ -1819,16 +1824,18 @@ cdef int _tiledEm(
|
|
|
1819
1824
|
if not masked:
|
|
1820
1825
|
i = 0
|
|
1821
1826
|
while i < r and ((z + i) & 3):
|
|
1822
|
-
g_buf[i] = decodePacked(
|
|
1827
|
+
g_buf[i] = decodePacked(packedRow(B, rows, marker), z + i)
|
|
1823
1828
|
i = i + 1
|
|
1824
1829
|
if i < r:
|
|
1825
|
-
_unpackPackedRow(
|
|
1830
|
+
_unpackPackedRow(
|
|
1831
|
+
packedRow(B, rows, marker) + ((z + i) >> 2), g_buf + i, r - i
|
|
1832
|
+
)
|
|
1826
1833
|
else:
|
|
1827
1834
|
for i in range(r):
|
|
1828
1835
|
if heldOut(marker, z + i, N, fold, folds, seed):
|
|
1829
1836
|
g_buf[i] = 9
|
|
1830
1837
|
else:
|
|
1831
|
-
g_buf[i] = decodePacked(
|
|
1838
|
+
g_buf[i] = decodePacked(packedRow(B, rows, marker), z + i)
|
|
1832
1839
|
if fixed:
|
|
1833
1840
|
if not _tiledQRowW(g, &P[marker, 0], &Q[z, 0], &T[z, 0], w, r, K):
|
|
1834
1841
|
fm_q_weight_generic(&P[marker, 0], &Q[z, 0], &T[z, 0], g, r, w, K)
|
|
@@ -1859,9 +1866,10 @@ cpdef int tiledPacked(
|
|
|
1859
1866
|
const u8[:, ::1] B, const f64[:, ::1] P,
|
|
1860
1867
|
f64[:, ::1] P1, const f64[:, ::1] Q, f64[:, ::1] T,
|
|
1861
1868
|
const Py_ssize_t N, const u32[::1] s=None, const u32[::1] weights=None,
|
|
1862
|
-
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0
|
|
1869
|
+
Py_ssize_t fold=-1, Py_ssize_t folds=1, uint64_t seed=0,
|
|
1870
|
+
const uintptr_t[::1] rows=None
|
|
1863
1871
|
) except -1 nogil:
|
|
1864
|
-
return _tiledEm(B, None, P, P1, Q, T, N, s, weights, fold, folds, seed)
|
|
1872
|
+
return _tiledEm(B, None, P, P1, Q, T, N, s, weights, fold, folds, seed, rows)
|
|
1865
1873
|
|
|
1866
1874
|
|
|
1867
1875
|
### Apply one likelihood full, indexed, or weighted tiled EM map
|
|
@@ -5,6 +5,7 @@ __author__ = "Jonas Meisner"
|
|
|
5
5
|
import errno
|
|
6
6
|
import json
|
|
7
7
|
import os
|
|
8
|
+
import shlex
|
|
8
9
|
import shutil
|
|
9
10
|
import stat
|
|
10
11
|
import sys
|
|
@@ -15,7 +16,7 @@ from contextlib import ExitStack, suppress
|
|
|
15
16
|
from datetime import datetime
|
|
16
17
|
from time import perf_counter as time
|
|
17
18
|
|
|
18
|
-
from fastmixture2 import __version__, defaults
|
|
19
|
+
from fastmixture2 import __version__, defaults, plink
|
|
19
20
|
|
|
20
21
|
CHECKPOINT_VERSION = 4
|
|
21
22
|
OUTPUT_TRANSACTION_VERSION = 1
|
|
@@ -23,11 +24,7 @@ OUTPUT_TRANSACTION_VERSION = 1
|
|
|
23
24
|
|
|
24
25
|
### Bind checkpoints to the selected input and auxiliary files
|
|
25
26
|
def inputKey(args):
|
|
26
|
-
paths = (
|
|
27
|
-
[f"{args.bfile}.{ext}" for ext in ("bed", "bim", "fam")]
|
|
28
|
-
if args.bfile is not None
|
|
29
|
-
else [args.beagle]
|
|
30
|
-
)
|
|
27
|
+
paths = list(plink.files(args.bfile)) if args.bfile is not None else [args.beagle]
|
|
31
28
|
paths += [pth for pth in (args.supervised, args.projection) if pth is not None]
|
|
32
29
|
key = []
|
|
33
30
|
|
|
@@ -63,9 +60,9 @@ def _samePath(a, b):
|
|
|
63
60
|
def _validatePaths(args, q_path, p_path, se_path, log_path, cache):
|
|
64
61
|
inputs = (
|
|
65
62
|
[
|
|
66
|
-
("
|
|
67
|
-
|
|
68
|
-
("
|
|
63
|
+
(f"{ext.upper()} input", f"{pfx}.{ext}")
|
|
64
|
+
for pfx in plink.prefixes(args.bfile)
|
|
65
|
+
for ext in ("bed", "bim", "fam")
|
|
69
66
|
]
|
|
70
67
|
if args.bfile is not None
|
|
71
68
|
else [("Beagle input", args.beagle)]
|
|
@@ -517,6 +514,8 @@ def methodInfo(args, use_gpu, mode):
|
|
|
517
514
|
f"Convergence: {defaults.LIKELIHOOD_CONVERGENCE_WINDOW}-iteration window | "
|
|
518
515
|
"independent float64 EM check",
|
|
519
516
|
]
|
|
517
|
+
if args.restarts:
|
|
518
|
+
res.append(f"Restarts: {args.restarts} | Q permutations and fresh SNP subsets")
|
|
520
519
|
return res
|
|
521
520
|
|
|
522
521
|
|
|
@@ -637,6 +636,10 @@ def _validateArgs(args):
|
|
|
637
636
|
raise ValueError("Choose either supervised or projection mode")
|
|
638
637
|
if args.random_init and (args.supervised is not None or args.projection is not None):
|
|
639
638
|
raise ValueError("--random-init is available in unsupervised mode")
|
|
639
|
+
if args.restarts < 0:
|
|
640
|
+
raise ValueError("--restarts must be non-negative")
|
|
641
|
+
if args.restarts and (args.supervised is not None or args.projection is not None):
|
|
642
|
+
raise ValueError("--restarts is available in unsupervised mode")
|
|
640
643
|
if args.allow_ambiguous and args.projection is None:
|
|
641
644
|
raise ValueError("--allow-ambiguous requires --projection")
|
|
642
645
|
save_gl = args.save_gl_cache
|
|
@@ -672,8 +675,7 @@ def _validateArgs(args):
|
|
|
672
675
|
if pth is not None and not os.path.isfile(pth):
|
|
673
676
|
raise FileNotFoundError(pth)
|
|
674
677
|
if args.bfile is not None:
|
|
675
|
-
for
|
|
676
|
-
pth = f"{args.bfile}.{ext}"
|
|
678
|
+
for pth in plink.files(args.bfile):
|
|
677
679
|
if not os.path.isfile(pth):
|
|
678
680
|
raise FileNotFoundError(pth)
|
|
679
681
|
elif not os.path.isfile(args.beagle):
|
|
@@ -743,6 +745,8 @@ def _run(args, stack):
|
|
|
743
745
|
if val:
|
|
744
746
|
rows.append(f"--{opt}")
|
|
745
747
|
elif val is not None and not (key == "cv_tole" and args.cv is None):
|
|
748
|
+
if key == "bfile":
|
|
749
|
+
val = shlex.join(plink.prefixes(val))
|
|
746
750
|
rows.append(f"--{opt} {val}")
|
|
747
751
|
_writeSection(log, "Options", rows)
|
|
748
752
|
_writeSection(log, "Method", methodInfo(args, use_gpu, mode))
|
|
@@ -751,7 +755,7 @@ def _run(args, stack):
|
|
|
751
755
|
from fastmixture2 import functions, kernels, utils
|
|
752
756
|
|
|
753
757
|
# Load packed genotypes or likelihoods
|
|
754
|
-
src = args.beagle if gl else
|
|
758
|
+
src = args.beagle if gl else plink.label(args.bfile)
|
|
755
759
|
print("Reading data...", end="", flush=True)
|
|
756
760
|
ts = time()
|
|
757
761
|
rng = np.random.default_rng(args.seed)
|
|
@@ -944,6 +948,9 @@ def _run(args, stack):
|
|
|
944
948
|
|
|
945
949
|
# Run fixed-P projection or joint P/Q estimation
|
|
946
950
|
res = functions.hybridRun(G, P, Q, q_nrm, y, run, fixed=args.projection is not None)
|
|
951
|
+
if args.restarts:
|
|
952
|
+
rs_rng = np.random.default_rng(np.random.SeedSequence([args.seed, 0x5253]))
|
|
953
|
+
res = functions.restartRun(G, P, Q, q_nrm, rs_rng, run, res, args.restarts)
|
|
947
954
|
|
|
948
955
|
# Refit isolated entry-masked folds from scalable or exact starts
|
|
949
956
|
if args.cv is not None:
|