fastmixture2 2.0.5__tar.gz → 2.0.7__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 (68) hide show
  1. {fastmixture2-2.0.5/fastmixture2.egg-info → fastmixture2-2.0.7}/PKG-INFO +47 -54
  2. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/README.md +46 -53
  3. fastmixture2-2.0.7/fastmixture2/__init__.py +1 -0
  4. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/defaults.py +1 -3
  5. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/fastmixture2.py +15 -5
  6. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/functions.py +154 -72
  7. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/gpu.py +561 -225
  8. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/kernels.py +37 -15
  9. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/main.py +1 -1
  10. fastmixture2-2.0.7/fastmixture2/plink.py +142 -0
  11. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/shared.pyx +133 -22
  12. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/sqp.pyx +37 -5
  13. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/svd.pyx +30 -7
  14. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/utils.py +109 -36
  15. {fastmixture2-2.0.5 → fastmixture2-2.0.7/fastmixture2.egg-info}/PKG-INFO +47 -54
  16. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/check_portable.py +4 -0
  17. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/helpers.py +11 -0
  18. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_bootstrap.py +9 -5
  19. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_cli.py +4 -0
  20. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_cpu_scaling.py +205 -2
  21. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_cpu_subset.py +202 -10
  22. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_cross_validation.py +5 -0
  23. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_frequency_cache.py +76 -1
  24. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_genotypes.py +28 -1
  25. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_called.py +254 -233
  26. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_gl_precision.py +64 -14
  27. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_large.py +6 -6
  28. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_modes.py +11 -2
  29. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_precision.py +2 -2
  30. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_safety.py +75 -3
  31. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_streamed.py +222 -0
  32. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_subset.py +200 -7
  33. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_svd_cache.py +4 -8
  34. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_initialization.py +17 -2
  35. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_likelihoods.py +24 -3
  36. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_numerical_equivalence.py +3 -5
  37. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_plink_files.py +198 -38
  38. fastmixture2-2.0.7/tests/test_restarts.py +853 -0
  39. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_subset_modes.py +56 -6
  40. fastmixture2-2.0.5/fastmixture2/__init__.py +0 -1
  41. fastmixture2-2.0.5/fastmixture2/plink.py +0 -119
  42. fastmixture2-2.0.5/tests/test_restarts.py +0 -362
  43. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/LICENSE +0 -0
  44. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/MANIFEST.in +0 -0
  45. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/em.pyx +0 -0
  46. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/packed.pxd +0 -0
  47. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2/threads.pxd +0 -0
  48. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2.egg-info/SOURCES.txt +0 -0
  49. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2.egg-info/dependency_links.txt +0 -0
  50. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2.egg-info/entry_points.txt +0 -0
  51. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2.egg-info/requires.txt +0 -0
  52. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/fastmixture2.egg-info/top_level.txt +0 -0
  53. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/pyproject.toml +0 -0
  54. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/setup.cfg +0 -0
  55. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/setup.py +0 -0
  56. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/run_tests.py +0 -0
  57. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_adversarial_io.py +0 -0
  58. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_convergence.py +0 -0
  59. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_distribution.py +0 -0
  60. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_em.py +0 -0
  61. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_stat_reuse.py +0 -0
  62. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_gpu_supervision.py +0 -0
  63. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_optimizers.py +0 -0
  64. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_q_constraints.py +0 -0
  65. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_sqp_scoring.py +0 -0
  66. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_sqp_solver.py +0 -0
  67. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/test_threads.py +0 -0
  68. {fastmixture2-2.0.5 → fastmixture2-2.0.7}/tests/validate_distribution.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastmixture2
3
- Version: 2.0.5
3
+ Version: 2.0.7
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
@@ -31,15 +31,20 @@ Dynamic: license-file
31
31
 
32
32
  # fastmixture2
33
33
 
34
- [![Tests](https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg)](https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml)
35
- [![PyPI](https://img.shields.io/pypi/v/fastmixture2.svg)](https://pypi.org/project/fastmixture2/)
36
- [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE)
34
+ <p align="center">
35
+ <img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo: a snake-shaped 2 intertwined with a colorful DNA helix" width="300">
36
+ </p>
37
+
38
+ <p align="center">
39
+ <a href="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml"><img src="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg" alt="Tests"></a>
40
+ <a href="https://pypi.org/project/fastmixture2/"><img src="https://img.shields.io/pypi/v/fastmixture2.svg" alt="PyPI"></a>
41
+ <a href="https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
42
+ </p>
37
43
 
38
44
  `fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
39
45
  frequencies (`P`) by maximum likelihood. It reads SNP-major PLINK genotypes
40
- or ANGSD Beagle genotype likelihoods. Unsupervised initialization uses SVD/ALS
41
- for K > 1, with subset likelihood refinement for large panels.
42
- All modes use safeguarded SQP/ZAL updates on CPU or, with `--gpu`, on NVIDIA CUDA.
46
+ or ANGSD Beagle genotype likelihoods. Unsupervised, supervised and projection
47
+ modes run on CPU or, with `--gpu`, on NVIDIA CUDA.
43
48
 
44
49
  ## Installation
45
50
 
@@ -70,7 +75,7 @@ conda activate fastmixture2-cpu
70
75
 
71
76
  For GPU use, select `environment-gpu.yml` and activate `fastmixture2-gpu`.
72
77
 
73
- PyPI wheels cover Linux (glibc) and macOS 14 or newer, on x86-64 and ARM64.
78
+ PyPI wheels cover Linux (glibc) and macOS 15 or newer, on x86-64 and ARM64.
74
79
  They use AVX2 on supported x86-64 CPUs and NEON on ARM64, including Apple Silicon:
75
80
 
76
81
  ```bash
@@ -117,7 +122,7 @@ fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
117
122
  - `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
118
123
  internally. Exactly uniform triplets contribute no ancestry information.
119
124
 
120
- Per-chromosome inputs are fitted jointly without creating a merged BED:
125
+ Per-chromosome inputs are memory-mapped and fitted jointly without a merged BED:
121
126
 
122
127
  ```bash
123
128
  fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
@@ -126,9 +131,7 @@ fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
126
131
  The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
127
132
  such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
128
133
  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.
134
+ file order. Per-chromosome input works on CPU and CUDA in all modes.
132
135
 
133
136
  Perform sample and variant QC first. For each K, try several seeds and keep
134
137
  the converged fit with the highest log-likelihood. Component labels may change
@@ -139,15 +142,6 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
139
142
  in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
140
143
  Resuming a checkpoint retains its saved estimates.
141
144
 
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
-
151
145
  Add `--gpu` to use CUDA with either input format:
152
146
 
153
147
  ```bash
@@ -158,36 +152,21 @@ CPU and CUDA support `1 <= K <= 128` for both input formats in all modes.
158
152
  CUDA keeps input data on the GPU when they fit and streams in blocks otherwise.
159
153
  Small CPU/GPU differences can arise from floating-point arithmetic.
160
154
 
161
- At K > 1, unsupervised initialization uses 10 SVD power iterations on all SNPs
162
- up to 50,000, or a genome-wide 50,000-SNP subset otherwise. Larger panels refine
163
- subset Q/P with SQP/ZAL, then fit full-marker P by least squares at fixed Q and
164
- retain the refined subset rows. This applies to both input formats, including
165
- missing genotypes.
166
- Panels up to 50,000 SNPs proceed directly from SVD/ALS to full-data refinement,
167
- without a duplicate subset fit or projection. For PLINK, subset refinement is
168
- skipped if any sample has no observed subset genotypes. Exact CV folds skip
169
- subset likelihood refinement.
170
-
171
- Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
172
- into a temporary memory-mapped file. CUDA streams the subset when it does not
173
- fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
174
- storage.
175
-
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.
155
+ At K > 1, unsupervised fits use SVD/ALS on up to 50,000 genome-wide SNPs, with
156
+ subset refinement for larger panels. All modes use safeguarded SQP/ZAL with EM/QN
157
+ rescue and float64 likelihood checks. CPU fitting uses float64. CUDA uses
158
+ mixed precision followed by float64 refinement.
159
+
160
+ Processing uses bounded tiles. Total memory still grows with panel size and K.
161
+ Initialization subsets use memory-mapped temporary files when needed. Temporary
162
+ files use `TMPDIR`. For large panels, point it to disk-backed scratch with
163
+ sufficient space.
185
164
 
186
165
  The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
187
- `--threads` caps CPU computation, including BLAS and GPU host copies.
166
+ `--threads` also controls CPU work during GPU fits.
188
167
  The optimizer scales the tolerance by observed genotypes or informative
189
168
  likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
190
- Check the log for convergence. Run `fastmixture2 --help` for the full CLI.
169
+ Run `fastmixture2 --help` for the full CLI.
191
170
 
192
171
  ### Beagle cache
193
172
 
@@ -282,7 +261,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 \
282
261
  ```
283
262
 
284
263
  `--bootstrap` defaults to 200 replicates. Each replicate starts from the
285
- full-data fit and takes up to three weighted SQP/ZAL iterations with EM rescue.
264
+ full-data fit and takes up to three refinement iterations.
286
265
  Use `--bootstrap-iter` for longer refits. Add `--bootstrap-tole` to stop at a mean
287
266
  likelihood gain per informative entry, within that iteration limit. The log
288
267
  reports refit termination. Short refits give a local estimate of uncertainty.
@@ -296,6 +275,23 @@ Add `--gpu` for CUDA refits. Projection errors are conditional on the supplied
296
275
  P matrix. Supervised reference samples have zero Q uncertainty. Bootstrap and
297
276
  CV must be run separately.
298
277
 
278
+ ### Restarts
279
+
280
+ Try additional unsupervised fits with `--restarts N` (default 0):
281
+
282
+ ```bash
283
+ fastmixture2 --bfile cohort --K 5 --threads 8 --restarts 6 --out cohort
284
+ ```
285
+
286
+ Each round tries a Q-column permutation and a component merge/split mutation,
287
+ followed by full-data refits. Panels above 50,000 SNPs use fresh subsets.
288
+ For K >= 3, N rounds add up to 2N full-data fits. Outputs and checkpoints
289
+ retain the best full-data fit.
290
+
291
+ Restarts support both input formats on CPU and CUDA, use `--seed`, and keep
292
+ the same `--iter` and `--tole` per stage. K = 2 uses only Q permutations.
293
+ At K = 1 they have no effect.
294
+
299
295
  ### Checkpointing
300
296
 
301
297
  Save accepted estimates and resume an interrupted CPU or GPU fit:
@@ -307,7 +303,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
307
303
 
308
304
  Keep the same input, supervision and projection files when resuming.
309
305
  With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
310
- requested number of additional restarts after the resumed fit.
306
+ requested number of additional restart rounds after the resumed fit.
311
307
 
312
308
  ## Output
313
309
 
@@ -325,10 +321,8 @@ Rows follow input order and columns correspond to components. Use
325
321
  P. Projection does not write P. For PLINK, P is the frequency of BIM A1.
326
322
  For Beagle, it is the frequency of allele2.
327
323
 
328
- Q and Q_se contain N x K values, and P contains M x K values. Matrices use
329
- ten decimal places. The log records export counts and full-precision
330
- likelihoods before output rounding. Console likelihoods use six decimal
331
- places. Numbers have no thousands separators.
324
+ Matrices use ten decimal places. Logs retain full-precision likelihoods and
325
+ iteration counts, including ALS when used.
332
326
 
333
327
  Outputs, checkpoints and caches use standard file permissions controlled by
334
328
  your umask.
@@ -338,7 +332,6 @@ numerical failure. Unsuccessful fits retain the best accepted parameters.
338
332
 
339
333
  Parallel jobs should use distinct output prefixes. Build each likelihood cache
340
334
  with one job, then reuse it across fits, or use a separate cache path per job.
341
- fastmixture2 does not create filesystem locks or require private lock directories.
342
335
 
343
336
  ## Authors and license
344
337
 
@@ -1,14 +1,19 @@
1
1
  # fastmixture2
2
2
 
3
- [![Tests](https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg)](https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml)
4
- [![PyPI](https://img.shields.io/pypi/v/fastmixture2.svg)](https://pypi.org/project/fastmixture2/)
5
- [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE)
3
+ <p align="center">
4
+ <img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo: a snake-shaped 2 intertwined with a colorful DNA helix" width="300">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml"><img src="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg" alt="Tests"></a>
9
+ <a href="https://pypi.org/project/fastmixture2/"><img src="https://img.shields.io/pypi/v/fastmixture2.svg" alt="PyPI"></a>
10
+ <a href="https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
11
+ </p>
6
12
 
7
13
  `fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
8
14
  frequencies (`P`) by maximum likelihood. It reads SNP-major PLINK genotypes
9
- or ANGSD Beagle genotype likelihoods. Unsupervised initialization uses SVD/ALS
10
- for K > 1, with subset likelihood refinement for large panels.
11
- All modes use safeguarded SQP/ZAL updates on CPU or, with `--gpu`, on NVIDIA CUDA.
15
+ or ANGSD Beagle genotype likelihoods. Unsupervised, supervised and projection
16
+ modes run on CPU or, with `--gpu`, on NVIDIA CUDA.
12
17
 
13
18
  ## Installation
14
19
 
@@ -39,7 +44,7 @@ conda activate fastmixture2-cpu
39
44
 
40
45
  For GPU use, select `environment-gpu.yml` and activate `fastmixture2-gpu`.
41
46
 
42
- PyPI wheels cover Linux (glibc) and macOS 14 or newer, on x86-64 and ARM64.
47
+ PyPI wheels cover Linux (glibc) and macOS 15 or newer, on x86-64 and ARM64.
43
48
  They use AVX2 on supported x86-64 CPUs and NEON on ARM64, including Apple Silicon:
44
49
 
45
50
  ```bash
@@ -86,7 +91,7 @@ fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
86
91
  - `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
87
92
  internally. Exactly uniform triplets contribute no ancestry information.
88
93
 
89
- Per-chromosome inputs are fitted jointly without creating a merged BED:
94
+ Per-chromosome inputs are memory-mapped and fitted jointly without a merged BED:
90
95
 
91
96
  ```bash
92
97
  fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
@@ -95,9 +100,7 @@ fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
95
100
  The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
96
101
  such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
97
102
  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.
103
+ file order. Per-chromosome input works on CPU and CUDA in all modes.
101
104
 
102
105
  Perform sample and variant QC first. For each K, try several seeds and keep
103
106
  the converged fit with the highest log-likelihood. Component labels may change
@@ -108,15 +111,6 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
108
111
  in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
109
112
  Resuming a checkpoint retains its saved estimates.
110
113
 
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
-
120
114
  Add `--gpu` to use CUDA with either input format:
121
115
 
122
116
  ```bash
@@ -127,36 +121,21 @@ CPU and CUDA support `1 <= K <= 128` for both input formats in all modes.
127
121
  CUDA keeps input data on the GPU when they fit and streams in blocks otherwise.
128
122
  Small CPU/GPU differences can arise from floating-point arithmetic.
129
123
 
130
- At K > 1, unsupervised initialization uses 10 SVD power iterations on all SNPs
131
- up to 50,000, or a genome-wide 50,000-SNP subset otherwise. Larger panels refine
132
- subset Q/P with SQP/ZAL, then fit full-marker P by least squares at fixed Q and
133
- retain the refined subset rows. This applies to both input formats, including
134
- missing genotypes.
135
- Panels up to 50,000 SNPs proceed directly from SVD/ALS to full-data refinement,
136
- without a duplicate subset fit or projection. For PLINK, subset refinement is
137
- skipped if any sample has no observed subset genotypes. Exact CV folds skip
138
- subset likelihood refinement.
139
-
140
- Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
141
- into a temporary memory-mapped file. CUDA streams the subset when it does not
142
- fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
143
- storage.
144
-
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.
124
+ At K > 1, unsupervised fits use SVD/ALS on up to 50,000 genome-wide SNPs, with
125
+ subset refinement for larger panels. All modes use safeguarded SQP/ZAL with EM/QN
126
+ rescue and float64 likelihood checks. CPU fitting uses float64. CUDA uses
127
+ mixed precision followed by float64 refinement.
128
+
129
+ Processing uses bounded tiles. Total memory still grows with panel size and K.
130
+ Initialization subsets use memory-mapped temporary files when needed. Temporary
131
+ files use `TMPDIR`. For large panels, point it to disk-backed scratch with
132
+ sufficient space.
154
133
 
155
134
  The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
156
- `--threads` caps CPU computation, including BLAS and GPU host copies.
135
+ `--threads` also controls CPU work during GPU fits.
157
136
  The optimizer scales the tolerance by observed genotypes or informative
158
137
  likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
159
- Check the log for convergence. Run `fastmixture2 --help` for the full CLI.
138
+ Run `fastmixture2 --help` for the full CLI.
160
139
 
161
140
  ### Beagle cache
162
141
 
@@ -251,7 +230,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 \
251
230
  ```
252
231
 
253
232
  `--bootstrap` defaults to 200 replicates. Each replicate starts from the
254
- full-data fit and takes up to three weighted SQP/ZAL iterations with EM rescue.
233
+ full-data fit and takes up to three refinement iterations.
255
234
  Use `--bootstrap-iter` for longer refits. Add `--bootstrap-tole` to stop at a mean
256
235
  likelihood gain per informative entry, within that iteration limit. The log
257
236
  reports refit termination. Short refits give a local estimate of uncertainty.
@@ -265,6 +244,23 @@ Add `--gpu` for CUDA refits. Projection errors are conditional on the supplied
265
244
  P matrix. Supervised reference samples have zero Q uncertainty. Bootstrap and
266
245
  CV must be run separately.
267
246
 
247
+ ### Restarts
248
+
249
+ Try additional unsupervised fits with `--restarts N` (default 0):
250
+
251
+ ```bash
252
+ fastmixture2 --bfile cohort --K 5 --threads 8 --restarts 6 --out cohort
253
+ ```
254
+
255
+ Each round tries a Q-column permutation and a component merge/split mutation,
256
+ followed by full-data refits. Panels above 50,000 SNPs use fresh subsets.
257
+ For K >= 3, N rounds add up to 2N full-data fits. Outputs and checkpoints
258
+ retain the best full-data fit.
259
+
260
+ Restarts support both input formats on CPU and CUDA, use `--seed`, and keep
261
+ the same `--iter` and `--tole` per stage. K = 2 uses only Q permutations.
262
+ At K = 1 they have no effect.
263
+
268
264
  ### Checkpointing
269
265
 
270
266
  Save accepted estimates and resume an interrupted CPU or GPU fit:
@@ -276,7 +272,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
276
272
 
277
273
  Keep the same input, supervision and projection files when resuming.
278
274
  With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
279
- requested number of additional restarts after the resumed fit.
275
+ requested number of additional restart rounds after the resumed fit.
280
276
 
281
277
  ## Output
282
278
 
@@ -294,10 +290,8 @@ Rows follow input order and columns correspond to components. Use
294
290
  P. Projection does not write P. For PLINK, P is the frequency of BIM A1.
295
291
  For Beagle, it is the frequency of allele2.
296
292
 
297
- Q and Q_se contain N x K values, and P contains M x K values. Matrices use
298
- ten decimal places. The log records export counts and full-precision
299
- likelihoods before output rounding. Console likelihoods use six decimal
300
- places. Numbers have no thousands separators.
293
+ Matrices use ten decimal places. Logs retain full-precision likelihoods and
294
+ iteration counts, including ALS when used.
301
295
 
302
296
  Outputs, checkpoints and caches use standard file permissions controlled by
303
297
  your umask.
@@ -307,7 +301,6 @@ numerical failure. Unsuccessful fits retain the best accepted parameters.
307
301
 
308
302
  Parallel jobs should use distinct output prefixes. Build each likelihood cache
309
303
  with one job, then reuse it across fits, or use a separate cache path per job.
310
- fastmixture2 does not create filesystem locks or require private lock directories.
311
304
 
312
305
  ## Authors and license
313
306
 
@@ -0,0 +1 @@
1
+ __version__ = "2.0.7"
@@ -30,9 +30,6 @@ ALS_TOLERANCE = 1e-4
30
30
 
31
31
  # Refinement
32
32
  GPU_SQP_EXACT_POLISH_ITERATIONS = 2
33
- GPU_SQP_Q_REUSE_MIN_K = 10
34
- GPU_SQP_Q_REUSE_DELAY = 8
35
- GPU_SQP_Q_CACHE_BYTES = 64 << 20
36
33
  LIKELIHOOD_TRUST_RADIUS = 0.02
37
34
  # Halve the step before falling back to EM
38
35
  LIKELIHOOD_BACKTRACK_STEPS = 3
@@ -42,6 +39,7 @@ LIKELIHOOD_CONVERGENCE_WINDOW = 10
42
39
  GPU_TILE_BYTES = 512 << 20
43
40
  GPU_SQP_STAT_BYTES = 512 << 20
44
41
  GPU_SQP_WORKSPACE_BYTES = 128 << 20
42
+ GPU_BOOT_STAT_BYTES = 64 << 20
45
43
  GPU_MIN_TILE_BYTES = 128 << 20
46
44
  GPU_PREFETCH_MIN_TILES = 3
47
45
  GPU_MEMORY_RESERVE_BYTES = 512 << 20
@@ -514,8 +514,11 @@ def methodInfo(args, use_gpu, mode):
514
514
  f"Convergence: {defaults.LIKELIHOOD_CONVERGENCE_WINDOW}-iteration window | "
515
515
  "independent float64 EM check",
516
516
  ]
517
- if args.restarts:
518
- res.append(f"Restarts: {args.restarts} | Q permutations and fresh SNP subsets")
517
+ if args.restarts and args.K > 1:
518
+ n = args.restarts if args.K >= 3 else 0
519
+ res.append(
520
+ f"Restarts: {args.restarts} rounds | Q permutations {args.restarts} | merge/split {n}"
521
+ )
519
522
  return res
520
523
 
521
524
 
@@ -574,7 +577,11 @@ def cvRun(G, P0, Q0, q_nrm0, K, rng, run):
574
577
  if run.get("random_init", False):
575
578
  P, Q = utils.initializeRandom(X, K, rng)
576
579
  else:
577
- P, Q = utils.initializeUnsupervised(X, K, rng, strict=False)
580
+
581
+ def log(val):
582
+ functions.logInfo(run, f"CV fold {f + 1}: {val}")
583
+
584
+ P, Q = utils.initializeUnsupervised(X, K, rng, strict=False, run={"log": log})
578
585
  f_run = dict(run)
579
586
  f_run.pop("log", None)
580
587
  f_run["quiet"] = True
@@ -810,6 +817,7 @@ def _run(args, stack):
810
817
  boot_h, b_chr = utils.bootBlock(args.bfile, M, args.bootstrap_block)
811
818
 
812
819
  run = {
820
+ "seed": args.seed,
813
821
  "iter": args.iter,
814
822
  "tole": args.tole,
815
823
  "check": check,
@@ -916,8 +924,9 @@ def _run(args, stack):
916
924
  else:
917
925
  P, Q = resumed[:2]
918
926
 
919
- # Release pooled frequencies after initialization
920
- G.pop("freq", None)
927
+ # Restarts reuse pooled frequencies for full-marker projection
928
+ if not args.restarts:
929
+ G.pop("freq", None)
921
930
 
922
931
  # Reject input changes during parsing or initialization
923
932
  if inputKey(args) != src_key:
@@ -951,6 +960,7 @@ def _run(args, stack):
951
960
  if args.restarts:
952
961
  rs_rng = np.random.default_rng(np.random.SeedSequence([args.seed, 0x5253]))
953
962
  res = functions.restartRun(G, P, Q, q_nrm, rs_rng, run, res, args.restarts)
963
+ G.pop("freq", None)
954
964
 
955
965
  # Refit isolated entry-masked folds from scalable or exact starts
956
966
  if args.cv is not None: