fastmixture2 2.1.0__tar.gz → 2.3.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.
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/MANIFEST.in +1 -2
- fastmixture2-2.3.0/PKG-INFO +262 -0
- fastmixture2-2.3.0/README.md +231 -0
- fastmixture2-2.3.0/fastmixture2/__init__.py +4 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2/defaults.py +35 -6
- fastmixture2-2.3.0/fastmixture2/em.pyx +1025 -0
- fastmixture2-2.3.0/fastmixture2/fastmixture2.py +1735 -0
- fastmixture2-2.3.0/fastmixture2/functions.py +1661 -0
- fastmixture2-2.3.0/fastmixture2/gpu.py +8814 -0
- fastmixture2-2.3.0/fastmixture2/kernels.py +802 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2/main.py +27 -8
- fastmixture2-2.3.0/fastmixture2/math.pxd +387 -0
- fastmixture2-2.3.0/fastmixture2/packed.pxd +946 -0
- fastmixture2-2.3.0/fastmixture2/plink.py +719 -0
- fastmixture2-2.3.0/fastmixture2/shared.pyx +4513 -0
- fastmixture2-2.3.0/fastmixture2/sqp.pyx +3901 -0
- fastmixture2-2.3.0/fastmixture2/svd.pyx +1215 -0
- fastmixture2-2.3.0/fastmixture2/utils.py +2932 -0
- fastmixture2-2.3.0/fastmixture2.egg-info/PKG-INFO +262 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2.egg-info/SOURCES.txt +5 -18
- fastmixture2-2.3.0/setup.py +118 -0
- fastmixture2-2.3.0/tests/check_portable.py +130 -0
- fastmixture2-2.3.0/tests/helpers.py +538 -0
- fastmixture2-2.3.0/tests/test_adversarial_io.py +2307 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_bootstrap.py +654 -400
- fastmixture2-2.3.0/tests/test_cli.py +1577 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_convergence.py +451 -140
- fastmixture2-2.3.0/tests/test_cpu_scaling.py +4257 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_cross_validation.py +391 -98
- fastmixture2-2.3.0/tests/test_genotypes.py +766 -0
- fastmixture2-2.3.0/tests/test_gpu_init.py +862 -0
- fastmixture2-2.3.0/tests/test_gpu_kernels.py +2642 -0
- fastmixture2-2.3.0/tests/test_gpu_modes.py +913 -0
- fastmixture2-2.3.0/tests/test_gpu_planning.py +3706 -0
- fastmixture2-2.3.0/tests/test_gpu_streaming.py +1270 -0
- fastmixture2-2.3.0/tests/test_initialization.py +786 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_likelihoods.py +673 -779
- fastmixture2-2.3.0/tests/test_numerical_equivalence.py +989 -0
- fastmixture2-2.3.0/tests/test_optimizers.py +873 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_plink_files.py +309 -241
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_restarts.py +231 -166
- fastmixture2-2.3.0/tests/test_sample_subset.py +1309 -0
- fastmixture2-2.3.0/tests/test_sqp_solver.py +521 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/test_threads.py +126 -1
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/validate_distribution.py +59 -15
- fastmixture2-2.1.0/PKG-INFO +0 -327
- fastmixture2-2.1.0/README.md +0 -296
- fastmixture2-2.1.0/fastmixture2/__init__.py +0 -1
- fastmixture2-2.1.0/fastmixture2/em.pyx +0 -1887
- fastmixture2-2.1.0/fastmixture2/fastmixture2.py +0 -1067
- fastmixture2-2.1.0/fastmixture2/functions.py +0 -1111
- fastmixture2-2.1.0/fastmixture2/gpu.py +0 -5561
- fastmixture2-2.1.0/fastmixture2/kernels.py +0 -431
- fastmixture2-2.1.0/fastmixture2/packed.pxd +0 -277
- fastmixture2-2.1.0/fastmixture2/plink.py +0 -142
- fastmixture2-2.1.0/fastmixture2/shared.pyx +0 -2031
- fastmixture2-2.1.0/fastmixture2/sqp.pyx +0 -1152
- fastmixture2-2.1.0/fastmixture2/svd.pyx +0 -311
- fastmixture2-2.1.0/fastmixture2/threads.pxd +0 -42
- fastmixture2-2.1.0/fastmixture2/utils.py +0 -1483
- fastmixture2-2.1.0/fastmixture2.egg-info/PKG-INFO +0 -327
- fastmixture2-2.1.0/setup.py +0 -55
- fastmixture2-2.1.0/tests/check_portable.py +0 -56
- fastmixture2-2.1.0/tests/helpers.py +0 -256
- fastmixture2-2.1.0/tests/test_adversarial_io.py +0 -863
- fastmixture2-2.1.0/tests/test_cli.py +0 -885
- fastmixture2-2.1.0/tests/test_cpu_scaling.py +0 -1014
- fastmixture2-2.1.0/tests/test_cpu_subset.py +0 -525
- fastmixture2-2.1.0/tests/test_distribution.py +0 -84
- fastmixture2-2.1.0/tests/test_frequency_cache.py +0 -297
- fastmixture2-2.1.0/tests/test_genotypes.py +0 -545
- fastmixture2-2.1.0/tests/test_gpu_called.py +0 -1305
- fastmixture2-2.1.0/tests/test_gpu_em.py +0 -256
- fastmixture2-2.1.0/tests/test_gpu_gl_precision.py +0 -861
- fastmixture2-2.1.0/tests/test_gpu_large.py +0 -1025
- fastmixture2-2.1.0/tests/test_gpu_modes.py +0 -390
- fastmixture2-2.1.0/tests/test_gpu_precision.py +0 -813
- fastmixture2-2.1.0/tests/test_gpu_safety.py +0 -919
- fastmixture2-2.1.0/tests/test_gpu_stat_reuse.py +0 -193
- fastmixture2-2.1.0/tests/test_gpu_streamed.py +0 -770
- fastmixture2-2.1.0/tests/test_gpu_subset.py +0 -696
- fastmixture2-2.1.0/tests/test_gpu_supervision.py +0 -156
- fastmixture2-2.1.0/tests/test_gpu_svd_cache.py +0 -258
- fastmixture2-2.1.0/tests/test_initialization.py +0 -409
- fastmixture2-2.1.0/tests/test_numerical_equivalence.py +0 -711
- fastmixture2-2.1.0/tests/test_optimizers.py +0 -427
- fastmixture2-2.1.0/tests/test_q_constraints.py +0 -388
- fastmixture2-2.1.0/tests/test_sample_subset.py +0 -294
- fastmixture2-2.1.0/tests/test_sqp_scoring.py +0 -310
- fastmixture2-2.1.0/tests/test_sqp_solver.py +0 -435
- fastmixture2-2.1.0/tests/test_subset_modes.py +0 -410
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/LICENSE +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2.egg-info/dependency_links.txt +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2.egg-info/entry_points.txt +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2.egg-info/requires.txt +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/fastmixture2.egg-info/top_level.txt +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/pyproject.toml +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/setup.cfg +0 -0
- {fastmixture2-2.1.0 → fastmixture2-2.3.0}/tests/run_tests.py +0 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastmixture2
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Summary: Biobank-scale ancestry estimation in unrelated individuals
|
|
5
|
+
Author-email: "J. Meisner" <meisnerucph@gmail.com>, "L. Thunegard" <lisathunegard@icloud.com>
|
|
6
|
+
License-Expression: GPL-3.0-only
|
|
7
|
+
Project-URL: Homepage, https://github.com/MeisnerLab/fastmixture2
|
|
8
|
+
Project-URL: Documentation, https://github.com/MeisnerLab/fastmixture2#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/MeisnerLab/fastmixture2/issues
|
|
10
|
+
Project-URL: Source, https://github.com/MeisnerLab/fastmixture2
|
|
11
|
+
Keywords: admixture,ancestry,bioinformatics,genomics,population-genetics
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=2.0
|
|
26
|
+
Requires-Dist: scipy>=1.14
|
|
27
|
+
Requires-Dist: threadpoolctl>=3.5
|
|
28
|
+
Provides-Extra: gpu-cuda13
|
|
29
|
+
Requires-Dist: cupy-cuda13x[ctk]>=14.0; extra == "gpu-cuda13"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# fastmixture2 (v2.3.0)
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/MeisnerLab/fastmixture2/main/assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo" 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>
|
|
43
|
+
|
|
44
|
+
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
45
|
+
frequencies (`P`) by maximum likelihood from PLINK genotypes or ANGSD Beagle
|
|
46
|
+
genotype likelihoods. It supports unsupervised, supervised and projection modes
|
|
47
|
+
on CPU and NVIDIA CUDA.
|
|
48
|
+
|
|
49
|
+
## Citation
|
|
50
|
+
Please cite our preprint on [BioRxiv](https://www.biorxiv.org/content/10.64898/2026.11.30.770199v1).
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Use Python 3.11+. PyPI wheels support Linux (glibc) and macOS 15+ on x86-64
|
|
55
|
+
and ARM64, with AVX-512, AVX2, and NEON where available. For CUDA, use
|
|
56
|
+
`python -m pip install 'fastmixture2[gpu-cuda13]'` with a compatible NVIDIA
|
|
57
|
+
driver and pass `--gpu` when fitting.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m pip install fastmixture2
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Build from source for native CPU tuning. Install a C compiler and OpenMP
|
|
64
|
+
(`brew install libomp` on macOS).
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/MeisnerLab/fastmixture2.git
|
|
68
|
+
cd fastmixture2
|
|
69
|
+
python -m pip install .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use `python -m pip install '.[gpu-cuda13]'` for a CUDA source build.
|
|
73
|
+
For Conda, run `conda env create -f environment-cpu.yml` or use
|
|
74
|
+
`environment-gpu.yml` and activate `fastmixture2-cpu` or `fastmixture2-gpu`.
|
|
75
|
+
With [uv](https://docs.astral.sh/uv/), use `uv pip install` with the same arguments.
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
81
|
+
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
82
|
+
fastmixture2 --bfile chr{1..22} --K 4 5 6 --seed 42 43 --restarts 2 --threads 8 --out cohort
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`--bfile` accepts one SNP-major PLINK prefix or ordered chromosome prefixes.
|
|
86
|
+
The FAM files must have the same FID/IID pairs in the same order. `--beagle`
|
|
87
|
+
accepts gzipped ANGSD Beagle likelihoods.
|
|
88
|
+
|
|
89
|
+
Lists of K values and seeds run every combination sequentially. Fits share
|
|
90
|
+
the loaded data and reuse common initialization work where possible. Each
|
|
91
|
+
fit has its own outputs and log. For each K, keep the converged fit with the
|
|
92
|
+
highest log-likelihood and align components before comparing Q or P.
|
|
93
|
+
|
|
94
|
+
Both devices support K from 1 to 128. Remove monomorphic and uninformative
|
|
95
|
+
variants before fitting. Missing calls and uniform likelihood triplets
|
|
96
|
+
contribute no information. Unsupervised fits use SVD/ALS by default.
|
|
97
|
+
`--random-init` uses random P/Q starts for the fit and any `--exact-cv` folds.
|
|
98
|
+
|
|
99
|
+
Defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
100
|
+
Match `--threads` to your CPU allocation. On streamed `--gpu` runs, extra
|
|
101
|
+
threads also stage host tiles asynchronously. Iteration limits and likelihood
|
|
102
|
+
tolerances apply per fit stage. The tolerance is mean likelihood gain per
|
|
103
|
+
informative entry. See `fastmixture2 --help` for all options.
|
|
104
|
+
|
|
105
|
+
## Modes and options
|
|
106
|
+
|
|
107
|
+
`fastmixture2` runs in one of three mutually exclusive estimation modes (unsupervised
|
|
108
|
+
by default), with optional cross-validation, bootstrap standard errors and
|
|
109
|
+
checkpointing.
|
|
110
|
+
|
|
111
|
+
| Mode | Trigger | Mode-specific options | Compatible add-ons |
|
|
112
|
+
| --- | --- | --- | --- |
|
|
113
|
+
| **Unsupervised** | *(default)* | `--random-init`, `--restarts`, `--cv`, `--exact-cv`, `--cv-tole` | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
114
|
+
| **Supervised** | `--supervised FILE` | — | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
115
|
+
| **Projection** | `--projection FILE` | `--allow-ambiguous` | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
116
|
+
|
|
117
|
+
All modes accept `--bfile` or `--beagle`, `--K` (`1`–`128`), `--threads`, `--seed`,
|
|
118
|
+
`--gpu`, `--iter`, `--tole`, `--out`, `--write-info` and `--no-freqs` (projection
|
|
119
|
+
always omits `P`).
|
|
120
|
+
|
|
121
|
+
### Scratch and Beagle caches
|
|
122
|
+
|
|
123
|
+
Use `TMPDIR` or `SLURM_TMPDIR` for disk-backed scratch with space for input,
|
|
124
|
+
initialization and outputs. For shared filesystems, copy the panel once to
|
|
125
|
+
node-local disk and use its local prefixes. Recognized bucket mounts stage
|
|
126
|
+
mapped input once per command and publish each fit's outputs after it finishes.
|
|
127
|
+
Bucket output requires file replacement support.
|
|
128
|
+
|
|
129
|
+
- `--gl-cache FILE` — Read or write an explicit parsed Beagle cache (`--beagle` only).
|
|
130
|
+
- `--save-gl-cache` — Reuse or create `OUTPUT.gl.npy` as the Beagle cache (`--beagle` only).
|
|
131
|
+
|
|
132
|
+
The cache uses about `12 × variants × samples` bytes and stores sample, variant
|
|
133
|
+
and pooled-frequency metadata alongside it so `--write-info`, `--supervised` and
|
|
134
|
+
`--projection` avoid rereading the gzipped Beagle input. Invalid caches are rebuilt.
|
|
135
|
+
|
|
136
|
+
### Supervised estimation
|
|
137
|
+
|
|
138
|
+
Estimate P jointly with Q for unassigned samples, keeping reference Q rows fixed.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
142
|
+
--supervised populations.txt --out cohort.supervised
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- `--supervised FILE` — Population assignment file with labels `1`..`K` for
|
|
146
|
+
references and `0` for unassigned samples (at least one reference required).
|
|
147
|
+
- Supply labels in sample order or use `FID IID POP` columns to validate order
|
|
148
|
+
(use each Beagle sample label as both `FID` and `IID`).
|
|
149
|
+
- Supports `--bootstrap` (fixed reference rows have zero standard error) and
|
|
150
|
+
`--checkpoint` / `--resume`. Not compatible with `--random-init`, `--restarts`
|
|
151
|
+
or `--cv`.
|
|
152
|
+
|
|
153
|
+
### Projection
|
|
154
|
+
|
|
155
|
+
Estimate Q for new samples against fixed reference P. Use `--write-info` when
|
|
156
|
+
fitting the reference panel so projection can check marker IDs and alleles.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
fastmixture2 --bfile reference --K 5 --threads 8 --write-info --out reference
|
|
160
|
+
fastmixture2 --bfile new_samples --K 5 --threads 8 \
|
|
161
|
+
--projection reference.K5.s42.P --out new_samples.projected
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `--projection FILE` — Fixed reference P file matching the target markers in
|
|
165
|
+
order. Accepts multiple `--seed` values at the single `K` of `P`.
|
|
166
|
+
- `--allow-ambiguous` — Trust listed allele order for strand-ambiguous A/T and
|
|
167
|
+
C/G variants in annotated `P` files (otherwise remove them).
|
|
168
|
+
- Annotated `P` files (`SNP A1 A2`) handle allele swaps and strand complements,
|
|
169
|
+
while plain numeric `P` files assume matching counted alleles.
|
|
170
|
+
- Omits `P` output and supports `--bootstrap` (conditioned on `P`) and
|
|
171
|
+
`--checkpoint` / `--resume`. Not compatible with `--random-init`, `--restarts`
|
|
172
|
+
or `--cv`.
|
|
173
|
+
|
|
174
|
+
### Cross-validation
|
|
175
|
+
|
|
176
|
+
Compare K values in unsupervised mode using the same seed and number of folds.
|
|
177
|
+
Lower scores are better.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
fastmixture2 --bfile cohort --K 4 5 6 --threads 8 --seed 42 --cv 5 --out cohort.cv
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- `--cv INT` — Number of entry-masked folds (at least `2`, unsupervised only,
|
|
184
|
+
cannot be combined with `--bootstrap`). Starts from full-data estimates by default.
|
|
185
|
+
- `--exact-cv` — Fit each fold independently from training-only starts instead of
|
|
186
|
+
warm-starting from the full-data fit (respects `--random-init`).
|
|
187
|
+
- `--cv-tole FLOAT` — Fold convergence tolerance (default `1e-7`).
|
|
188
|
+
|
|
189
|
+
Use `--K 1` for a pooled-frequency baseline. PLINK scores use half binomial
|
|
190
|
+
deviance and Beagle scores use mean negative log marginal likelihood. Check fold
|
|
191
|
+
convergence in the log. Mapped CPU CV can use an extra BED-sized scratch file.
|
|
192
|
+
|
|
193
|
+
### Bootstrap uncertainty
|
|
194
|
+
|
|
195
|
+
Estimate Q standard errors in any mode by resampling blocks of neighboring SNPs.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
199
|
+
--bootstrap 200 --bootstrap-block 1500 --out cohort
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- `--bootstrap [INT]` — Number of moving-block replicates (default `200`, at
|
|
203
|
+
least `2`, cannot be combined with `--cv`).
|
|
204
|
+
- `--bootstrap-block INT` — Block length in SNPs. Defaults to ~10 cM within
|
|
205
|
+
chromosomes when PLINK `.bim` has a usable genetic map, and is required for
|
|
206
|
+
unmapped PLINK and for `--beagle`.
|
|
207
|
+
- `--bootstrap-iter INT` — Maximum SQP/ZAL iterations per replicate (default `3`).
|
|
208
|
+
- `--bootstrap-tole FLOAT` — Optional early-stopping likelihood tolerance per
|
|
209
|
+
replicate (disabled by default).
|
|
210
|
+
|
|
211
|
+
Projection conditions on fixed `P`. Fixed supervised reference rows have zero
|
|
212
|
+
standard error.
|
|
213
|
+
|
|
214
|
+
### Restarts
|
|
215
|
+
|
|
216
|
+
Escape local optima in unsupervised fits by running structured perturbation rounds.
|
|
217
|
+
|
|
218
|
+
- `--restarts INT` — Restart rounds per unsupervised `K` and seed (default `0`,
|
|
219
|
+
skipped at `K = 1`, unsupervised only).
|
|
220
|
+
- Each round tests a `Q` permutation and, at `K ≥ 3`, a merge/split proposal,
|
|
221
|
+
keeping the highest full-data log-likelihood and recording the selection in the log.
|
|
222
|
+
|
|
223
|
+
### Checkpointing
|
|
224
|
+
|
|
225
|
+
Save accepted optimizer states and resume an interrupted single fit or
|
|
226
|
+
multi-K/multi-seed batch.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
fastmixture2 --bfile cohort --K 4 5 --seed 42 43 --threads 8 \
|
|
230
|
+
--checkpoint run.ckpt --out cohort
|
|
231
|
+
fastmixture2 --bfile cohort --K 4 5 --seed 42 43 --threads 8 \
|
|
232
|
+
--resume run.ckpt --out cohort
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- `--checkpoint FILE` — Atomically save accepted state every `25` iterations or
|
|
236
|
+
`10` minutes. Multi-fit batches store a manifest in `FILE` and active fit state
|
|
237
|
+
in `FILE.fit.npz`.
|
|
238
|
+
- `--resume FILE` — Continue from a saved checkpoint or batch manifest (skipping
|
|
239
|
+
verified completed fits) using the same inputs, mode, options, `--K` and `--seed`.
|
|
240
|
+
Updates `FILE` in place unless a new `--checkpoint` path is also given.
|
|
241
|
+
- Use `--restarts` on a single resumed fit to run additional restart rounds after
|
|
242
|
+
convergence.
|
|
243
|
+
|
|
244
|
+
## Output
|
|
245
|
+
|
|
246
|
+
The table shows the files for `--out cohort --K 5 --seed 42`.
|
|
247
|
+
|
|
248
|
+
| File | Contents |
|
|
249
|
+
| --- | --- |
|
|
250
|
+
| `cohort.K5.s42.Q` | Ancestry proportions, one row per sample |
|
|
251
|
+
| `cohort.K5.s42.P` | Allele frequencies, one row per variant |
|
|
252
|
+
| `cohort.K5.s42.Q_se` | Q standard errors when bootstrap is requested |
|
|
253
|
+
| `cohort.K5.s42.log` | Settings, timing, convergence, likelihood and optional analysis summaries |
|
|
254
|
+
|
|
255
|
+
Rows follow input order. `--write-info` adds headers and IDs. P gives the
|
|
256
|
+
frequency of BIM A1 for PLINK and allele2 for Beagle. Projection and `--no-freqs` omit P.
|
|
257
|
+
Use separate `--out` prefixes for concurrent fits with the same K and seed.
|
|
258
|
+
|
|
259
|
+
## Authors and license
|
|
260
|
+
|
|
261
|
+
Lisa Thunegard and Jonas Meisner. Developed at **MeisnerLab** and distributed
|
|
262
|
+
under the [GNU General Public License v3.0](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE).
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# fastmixture2 (v2.3.0)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/MeisnerLab/fastmixture2/main/assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo" 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>
|
|
12
|
+
|
|
13
|
+
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
14
|
+
frequencies (`P`) by maximum likelihood from PLINK genotypes or ANGSD Beagle
|
|
15
|
+
genotype likelihoods. It supports unsupervised, supervised and projection modes
|
|
16
|
+
on CPU and NVIDIA CUDA.
|
|
17
|
+
|
|
18
|
+
## Citation
|
|
19
|
+
Please cite our preprint on [BioRxiv](https://www.biorxiv.org/content/10.64898/2026.11.30.770199v1).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Use Python 3.11+. PyPI wheels support Linux (glibc) and macOS 15+ on x86-64
|
|
24
|
+
and ARM64, with AVX-512, AVX2, and NEON where available. For CUDA, use
|
|
25
|
+
`python -m pip install 'fastmixture2[gpu-cuda13]'` with a compatible NVIDIA
|
|
26
|
+
driver and pass `--gpu` when fitting.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
python -m pip install fastmixture2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Build from source for native CPU tuning. Install a C compiler and OpenMP
|
|
33
|
+
(`brew install libomp` on macOS).
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/MeisnerLab/fastmixture2.git
|
|
37
|
+
cd fastmixture2
|
|
38
|
+
python -m pip install .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use `python -m pip install '.[gpu-cuda13]'` for a CUDA source build.
|
|
42
|
+
For Conda, run `conda env create -f environment-cpu.yml` or use
|
|
43
|
+
`environment-gpu.yml` and activate `fastmixture2-cpu` or `fastmixture2-gpu`.
|
|
44
|
+
With [uv](https://docs.astral.sh/uv/), use `uv pip install` with the same arguments.
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
50
|
+
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
51
|
+
fastmixture2 --bfile chr{1..22} --K 4 5 6 --seed 42 43 --restarts 2 --threads 8 --out cohort
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`--bfile` accepts one SNP-major PLINK prefix or ordered chromosome prefixes.
|
|
55
|
+
The FAM files must have the same FID/IID pairs in the same order. `--beagle`
|
|
56
|
+
accepts gzipped ANGSD Beagle likelihoods.
|
|
57
|
+
|
|
58
|
+
Lists of K values and seeds run every combination sequentially. Fits share
|
|
59
|
+
the loaded data and reuse common initialization work where possible. Each
|
|
60
|
+
fit has its own outputs and log. For each K, keep the converged fit with the
|
|
61
|
+
highest log-likelihood and align components before comparing Q or P.
|
|
62
|
+
|
|
63
|
+
Both devices support K from 1 to 128. Remove monomorphic and uninformative
|
|
64
|
+
variants before fitting. Missing calls and uniform likelihood triplets
|
|
65
|
+
contribute no information. Unsupervised fits use SVD/ALS by default.
|
|
66
|
+
`--random-init` uses random P/Q starts for the fit and any `--exact-cv` folds.
|
|
67
|
+
|
|
68
|
+
Defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
69
|
+
Match `--threads` to your CPU allocation. On streamed `--gpu` runs, extra
|
|
70
|
+
threads also stage host tiles asynchronously. Iteration limits and likelihood
|
|
71
|
+
tolerances apply per fit stage. The tolerance is mean likelihood gain per
|
|
72
|
+
informative entry. See `fastmixture2 --help` for all options.
|
|
73
|
+
|
|
74
|
+
## Modes and options
|
|
75
|
+
|
|
76
|
+
`fastmixture2` runs in one of three mutually exclusive estimation modes (unsupervised
|
|
77
|
+
by default), with optional cross-validation, bootstrap standard errors and
|
|
78
|
+
checkpointing.
|
|
79
|
+
|
|
80
|
+
| Mode | Trigger | Mode-specific options | Compatible add-ons |
|
|
81
|
+
| --- | --- | --- | --- |
|
|
82
|
+
| **Unsupervised** | *(default)* | `--random-init`, `--restarts`, `--cv`, `--exact-cv`, `--cv-tole` | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
83
|
+
| **Supervised** | `--supervised FILE` | — | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
84
|
+
| **Projection** | `--projection FILE` | `--allow-ambiguous` | `--bootstrap`, `--checkpoint` / `--resume` |
|
|
85
|
+
|
|
86
|
+
All modes accept `--bfile` or `--beagle`, `--K` (`1`–`128`), `--threads`, `--seed`,
|
|
87
|
+
`--gpu`, `--iter`, `--tole`, `--out`, `--write-info` and `--no-freqs` (projection
|
|
88
|
+
always omits `P`).
|
|
89
|
+
|
|
90
|
+
### Scratch and Beagle caches
|
|
91
|
+
|
|
92
|
+
Use `TMPDIR` or `SLURM_TMPDIR` for disk-backed scratch with space for input,
|
|
93
|
+
initialization and outputs. For shared filesystems, copy the panel once to
|
|
94
|
+
node-local disk and use its local prefixes. Recognized bucket mounts stage
|
|
95
|
+
mapped input once per command and publish each fit's outputs after it finishes.
|
|
96
|
+
Bucket output requires file replacement support.
|
|
97
|
+
|
|
98
|
+
- `--gl-cache FILE` — Read or write an explicit parsed Beagle cache (`--beagle` only).
|
|
99
|
+
- `--save-gl-cache` — Reuse or create `OUTPUT.gl.npy` as the Beagle cache (`--beagle` only).
|
|
100
|
+
|
|
101
|
+
The cache uses about `12 × variants × samples` bytes and stores sample, variant
|
|
102
|
+
and pooled-frequency metadata alongside it so `--write-info`, `--supervised` and
|
|
103
|
+
`--projection` avoid rereading the gzipped Beagle input. Invalid caches are rebuilt.
|
|
104
|
+
|
|
105
|
+
### Supervised estimation
|
|
106
|
+
|
|
107
|
+
Estimate P jointly with Q for unassigned samples, keeping reference Q rows fixed.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
111
|
+
--supervised populations.txt --out cohort.supervised
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- `--supervised FILE` — Population assignment file with labels `1`..`K` for
|
|
115
|
+
references and `0` for unassigned samples (at least one reference required).
|
|
116
|
+
- Supply labels in sample order or use `FID IID POP` columns to validate order
|
|
117
|
+
(use each Beagle sample label as both `FID` and `IID`).
|
|
118
|
+
- Supports `--bootstrap` (fixed reference rows have zero standard error) and
|
|
119
|
+
`--checkpoint` / `--resume`. Not compatible with `--random-init`, `--restarts`
|
|
120
|
+
or `--cv`.
|
|
121
|
+
|
|
122
|
+
### Projection
|
|
123
|
+
|
|
124
|
+
Estimate Q for new samples against fixed reference P. Use `--write-info` when
|
|
125
|
+
fitting the reference panel so projection can check marker IDs and alleles.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
fastmixture2 --bfile reference --K 5 --threads 8 --write-info --out reference
|
|
129
|
+
fastmixture2 --bfile new_samples --K 5 --threads 8 \
|
|
130
|
+
--projection reference.K5.s42.P --out new_samples.projected
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- `--projection FILE` — Fixed reference P file matching the target markers in
|
|
134
|
+
order. Accepts multiple `--seed` values at the single `K` of `P`.
|
|
135
|
+
- `--allow-ambiguous` — Trust listed allele order for strand-ambiguous A/T and
|
|
136
|
+
C/G variants in annotated `P` files (otherwise remove them).
|
|
137
|
+
- Annotated `P` files (`SNP A1 A2`) handle allele swaps and strand complements,
|
|
138
|
+
while plain numeric `P` files assume matching counted alleles.
|
|
139
|
+
- Omits `P` output and supports `--bootstrap` (conditioned on `P`) and
|
|
140
|
+
`--checkpoint` / `--resume`. Not compatible with `--random-init`, `--restarts`
|
|
141
|
+
or `--cv`.
|
|
142
|
+
|
|
143
|
+
### Cross-validation
|
|
144
|
+
|
|
145
|
+
Compare K values in unsupervised mode using the same seed and number of folds.
|
|
146
|
+
Lower scores are better.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
fastmixture2 --bfile cohort --K 4 5 6 --threads 8 --seed 42 --cv 5 --out cohort.cv
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- `--cv INT` — Number of entry-masked folds (at least `2`, unsupervised only,
|
|
153
|
+
cannot be combined with `--bootstrap`). Starts from full-data estimates by default.
|
|
154
|
+
- `--exact-cv` — Fit each fold independently from training-only starts instead of
|
|
155
|
+
warm-starting from the full-data fit (respects `--random-init`).
|
|
156
|
+
- `--cv-tole FLOAT` — Fold convergence tolerance (default `1e-7`).
|
|
157
|
+
|
|
158
|
+
Use `--K 1` for a pooled-frequency baseline. PLINK scores use half binomial
|
|
159
|
+
deviance and Beagle scores use mean negative log marginal likelihood. Check fold
|
|
160
|
+
convergence in the log. Mapped CPU CV can use an extra BED-sized scratch file.
|
|
161
|
+
|
|
162
|
+
### Bootstrap uncertainty
|
|
163
|
+
|
|
164
|
+
Estimate Q standard errors in any mode by resampling blocks of neighboring SNPs.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
168
|
+
--bootstrap 200 --bootstrap-block 1500 --out cohort
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
- `--bootstrap [INT]` — Number of moving-block replicates (default `200`, at
|
|
172
|
+
least `2`, cannot be combined with `--cv`).
|
|
173
|
+
- `--bootstrap-block INT` — Block length in SNPs. Defaults to ~10 cM within
|
|
174
|
+
chromosomes when PLINK `.bim` has a usable genetic map, and is required for
|
|
175
|
+
unmapped PLINK and for `--beagle`.
|
|
176
|
+
- `--bootstrap-iter INT` — Maximum SQP/ZAL iterations per replicate (default `3`).
|
|
177
|
+
- `--bootstrap-tole FLOAT` — Optional early-stopping likelihood tolerance per
|
|
178
|
+
replicate (disabled by default).
|
|
179
|
+
|
|
180
|
+
Projection conditions on fixed `P`. Fixed supervised reference rows have zero
|
|
181
|
+
standard error.
|
|
182
|
+
|
|
183
|
+
### Restarts
|
|
184
|
+
|
|
185
|
+
Escape local optima in unsupervised fits by running structured perturbation rounds.
|
|
186
|
+
|
|
187
|
+
- `--restarts INT` — Restart rounds per unsupervised `K` and seed (default `0`,
|
|
188
|
+
skipped at `K = 1`, unsupervised only).
|
|
189
|
+
- Each round tests a `Q` permutation and, at `K ≥ 3`, a merge/split proposal,
|
|
190
|
+
keeping the highest full-data log-likelihood and recording the selection in the log.
|
|
191
|
+
|
|
192
|
+
### Checkpointing
|
|
193
|
+
|
|
194
|
+
Save accepted optimizer states and resume an interrupted single fit or
|
|
195
|
+
multi-K/multi-seed batch.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
fastmixture2 --bfile cohort --K 4 5 --seed 42 43 --threads 8 \
|
|
199
|
+
--checkpoint run.ckpt --out cohort
|
|
200
|
+
fastmixture2 --bfile cohort --K 4 5 --seed 42 43 --threads 8 \
|
|
201
|
+
--resume run.ckpt --out cohort
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- `--checkpoint FILE` — Atomically save accepted state every `25` iterations or
|
|
205
|
+
`10` minutes. Multi-fit batches store a manifest in `FILE` and active fit state
|
|
206
|
+
in `FILE.fit.npz`.
|
|
207
|
+
- `--resume FILE` — Continue from a saved checkpoint or batch manifest (skipping
|
|
208
|
+
verified completed fits) using the same inputs, mode, options, `--K` and `--seed`.
|
|
209
|
+
Updates `FILE` in place unless a new `--checkpoint` path is also given.
|
|
210
|
+
- Use `--restarts` on a single resumed fit to run additional restart rounds after
|
|
211
|
+
convergence.
|
|
212
|
+
|
|
213
|
+
## Output
|
|
214
|
+
|
|
215
|
+
The table shows the files for `--out cohort --K 5 --seed 42`.
|
|
216
|
+
|
|
217
|
+
| File | Contents |
|
|
218
|
+
| --- | --- |
|
|
219
|
+
| `cohort.K5.s42.Q` | Ancestry proportions, one row per sample |
|
|
220
|
+
| `cohort.K5.s42.P` | Allele frequencies, one row per variant |
|
|
221
|
+
| `cohort.K5.s42.Q_se` | Q standard errors when bootstrap is requested |
|
|
222
|
+
| `cohort.K5.s42.log` | Settings, timing, convergence, likelihood and optional analysis summaries |
|
|
223
|
+
|
|
224
|
+
Rows follow input order. `--write-info` adds headers and IDs. P gives the
|
|
225
|
+
frequency of BIM A1 for PLINK and allele2 for Beagle. Projection and `--no-freqs` omit P.
|
|
226
|
+
Use separate `--out` prefixes for concurrent fits with the same K and seed.
|
|
227
|
+
|
|
228
|
+
## Authors and license
|
|
229
|
+
|
|
230
|
+
Lisa Thunegard and Jonas Meisner. Developed at **MeisnerLab** and distributed
|
|
231
|
+
under the [GNU General Public License v3.0](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE).
|
|
@@ -8,13 +8,16 @@ from numbers import Integral
|
|
|
8
8
|
K_MAX = 128
|
|
9
9
|
|
|
10
10
|
# Genotype storage and likelihood caching
|
|
11
|
-
MEMMAP_THRESHOLD_BYTES = 1 << 30 # Packed bytes
|
|
11
|
+
MEMMAP_THRESHOLD_BYTES = 1 << 30 # Packed or float32 bytes
|
|
12
|
+
INPUT_COPY_BYTES = 64 << 20
|
|
12
13
|
LIKELIHOOD_PARSE_BLOCK_BYTES = 64 << 20
|
|
14
|
+
PROJECTION_BLOCK_BYTES = 8 << 20
|
|
13
15
|
LIKELIHOOD_CACHE_HEADER_BYTES = 256
|
|
14
|
-
LIKELIHOOD_CACHE_VERSION =
|
|
16
|
+
LIKELIHOOD_CACHE_VERSION = 6
|
|
15
17
|
LIKELIHOOD_FREQUENCY_VERSION = 2
|
|
16
18
|
|
|
17
19
|
# Initialization
|
|
20
|
+
BATCH_CACHE_BYTES = 128 << 20
|
|
18
21
|
INITIALIZATION_MARKERS = 50_000
|
|
19
22
|
INITIALIZATION_SAMPLES = 50_000
|
|
20
23
|
SVD_POWER_ITERATIONS = 10
|
|
@@ -39,9 +42,9 @@ LIKELIHOOD_CONVERGENCE_WINDOW = 10
|
|
|
39
42
|
# CUDA storage
|
|
40
43
|
GPU_TILE_BYTES = 512 << 20
|
|
41
44
|
GPU_SQP_STAT_BYTES = 512 << 20
|
|
42
|
-
GPU_SQP_FULL_STAT_BYTES =
|
|
45
|
+
GPU_SQP_FULL_STAT_BYTES = 36 << 30
|
|
43
46
|
GPU_SQP_WORKSPACE_BYTES = 128 << 20
|
|
44
|
-
GPU_BOOT_STAT_BYTES =
|
|
47
|
+
GPU_BOOT_STAT_BYTES = 36 << 30
|
|
45
48
|
GPU_MIN_TILE_BYTES = 128 << 20
|
|
46
49
|
GPU_PREFETCH_MIN_TILES = 3
|
|
47
50
|
GPU_MEMORY_RESERVE_BYTES = 512 << 20
|
|
@@ -53,8 +56,11 @@ EM_TILED_MIN_SAMPLES = 16_384
|
|
|
53
56
|
SQP_MARKER_CHUNK = 65_536
|
|
54
57
|
SQP_SAMPLE_CHUNK = 4_096
|
|
55
58
|
SQP_MARKER_WORKSPACE_BYTES = 512 << 20
|
|
59
|
+
SQP_PAIR_WORKSPACE_BYTES = 1 << 30
|
|
60
|
+
SQP_PAIR_MAX_BYTES = 8 << 30
|
|
56
61
|
SQP_SAMPLE_WORKSPACE_BYTES = 4 << 30
|
|
57
62
|
SQP_BLAS_WORKSPACE_BYTES = 64 << 20
|
|
63
|
+
CPU_READAHEAD_BYTES = 64 << 20
|
|
58
64
|
|
|
59
65
|
# ZAL acceleration
|
|
60
66
|
ZAL_DEPTH = 3
|
|
@@ -69,6 +75,7 @@ BOOT_REPLICATES = 200
|
|
|
69
75
|
BOOT_ITERATIONS = 3
|
|
70
76
|
BOOT_BLOCK_CM = 10.0
|
|
71
77
|
CHECKPOINT_INTERVAL = 25
|
|
78
|
+
CHECKPOINT_SECONDS = 600.0
|
|
72
79
|
OUTPUT_FORMAT = "%.10f"
|
|
73
80
|
|
|
74
81
|
|
|
@@ -103,13 +110,35 @@ def sqpMarkerChunk(M, K, chunk=SQP_MARKER_CHUNK):
|
|
|
103
110
|
|
|
104
111
|
|
|
105
112
|
### Bound CPU sample shards
|
|
106
|
-
def sqpSampleChunk(N, K, chunk=None):
|
|
113
|
+
def sqpSampleChunk(N, K, chunk=None, mapped=False):
|
|
107
114
|
if chunk is None:
|
|
108
|
-
chunk = 16_384 if K <= 16 else SQP_SAMPLE_CHUNK
|
|
115
|
+
chunk = 16_384 if K <= (32 if mapped else 16) else SQP_SAMPLE_CHUNK
|
|
109
116
|
n = max(1, SQP_SAMPLE_WORKSPACE_BYTES // (8 * K * (K + 1)))
|
|
110
117
|
return min(N, chunk, n)
|
|
111
118
|
|
|
112
119
|
|
|
120
|
+
### Adapt the CPU pair-statistics budget to capacity and live headroom
|
|
121
|
+
def sqpPairWorkspaceBytes(ram=0, data_bytes=0, work_bytes=0, over_ram=False, avail_ram=None):
|
|
122
|
+
base = SQP_PAIR_WORKSPACE_BYTES
|
|
123
|
+
cap = SQP_PAIR_MAX_BYTES
|
|
124
|
+
if base <= 0:
|
|
125
|
+
return 0
|
|
126
|
+
if ram > 0 and cap > base and base >= (1 << 30):
|
|
127
|
+
share = ram // 4
|
|
128
|
+
avail = (
|
|
129
|
+
share - work_bytes if over_ram else min(share, (3 * ram) // 4 - data_bytes - work_bytes)
|
|
130
|
+
)
|
|
131
|
+
budget = min(cap, max(base, avail))
|
|
132
|
+
else:
|
|
133
|
+
budget = base
|
|
134
|
+
if avail_ram is not None:
|
|
135
|
+
# Leave headroom for peer allocations and keep cached panels resident
|
|
136
|
+
free = avail_ram if over_ram else avail_ram - data_bytes
|
|
137
|
+
live = min(max(0, free) // 2, max(0, free - SQP_MARKER_WORKSPACE_BYTES))
|
|
138
|
+
budget = min(budget, live)
|
|
139
|
+
return max(0, budget)
|
|
140
|
+
|
|
141
|
+
|
|
113
142
|
### Bound the CUDA tile size
|
|
114
143
|
def gpuTileBytes(size, limit=GPU_TILE_BYTES):
|
|
115
144
|
return min(limit, max(GPU_MIN_TILE_BYTES, size // 8))
|