qmc-sampler
Quasi-Monte Carlo point sets by spectral optimisation.
qmc-sampler generates QMC point sets on the torus [0, 1)^D by minimising the Fourier
coefficients of the points over every wave vector of an exclusion region $\Omega$ :
\text{Min loss(x)} = \sum_{k \in \Omega} \frac{1}{|k|^2} \left| \sum_{j=1}^{N} e^{2i\pi \langle k, x_j \rangle} \right|^2 .
It was used to generate a large dataset of hyperuniform point sets, published on Zenodo.
Installation
pip install qmc-sampler
Usage
from qmc_sampler import sample_l2, sample_l1, sample_wd
x = sample_l2(1000, 2) # (N, D) array of points in [0, 1)^D
Three shapes of exclusion region $\Omega$ are available:
sample_l2(N, D): $\Omega$ = isotropic L2 ball, the classical choice.sample_l1(N, D): $\Omega$ = L1 ball, anisotropic, useful when the integrand has a low effective dimension.sample_wd(N, D): $\Omega$ = star shaped region (based on the wrap-around discrepancy), push this low-effective-dimension idea further.
Extra parameters (Chi, n_iter, seed, ...) can be set to the samplers. They are described,
together with the module settings (backend, precision, NUFFT tolerance), in
Params.md.
Backends
We provide four different backends for computing the Fourier kernel. All four are available, provided that their respective dependencies are properly installed on the user's system. Backend selection affects both computational speed and numerical precision, and should therefore be made with extra care for big scale or high precision experiments.
| backend | method | cost | dimensions | accuracy |
|---|---|---|---|---|
"keops" |
direct sums, pykeops (GPU if available) | O(N M) | any | exact (machine precision) |
"torch" |
direct sums, torch (GPU if available) | O(N M) | any | exact (machine precision) |
"cufinufft" |
non-uniform FFT (GPU only) | O(N log N + M) | D <= 3 | nufft_tolerance (auto: 1e-4 float32, 1e-8 float64) |
"finufft" |
non-uniform FFT (CPU only) | O(N log N + M) | D <= 3 | nufft_tolerance (auto: 1e-4 float32, 1e-8 float64) |
M is the number of wave vectors and grows like N. Unless told otherwise, qmc-sampler uses
the first available backend in the order of the table, so by default every sum is exact.
KeOps counts as available only if it compiles and runs a tiny test reduction: where pykeops
installs but cannot compile (no C++ compiler, Windows), the next backend is used instead.
finufft is always installed, so D <= 3 always has a working backend.
In 2D and 3D, (cu)FINUFFT is strongly recommended, for l2 and l1 sampling: one iteration costs
O(N log N) instead of O(N^2), which is usually one or more orders of magnitude faster and makes large N reachable.
The default (cu)FINUFFT tolerance ("auto", which depends on the precision) trades accuracy for
speed; lower it to go down to machine precision.
pip install cufinufft cupy-cuda12x # GPU, CUDA 12 (CUDA 11: cupy-cuda11x); finufft is installed with qmc-sampler
import qmc_sampler
qmc_sampler.select_backend(dimensions={2, 3}, backend="finufft") # or "cufinufft"
qmc_sampler.select_nufft_tolerance(1e-12) # default "auto"
Precision: float32 by default
Computations run in float32 by default. This is a deliberate choice: it roughly halves memory
use and is much faster on GPU (KeOps, torch, cuFINUFFT), which matters for large N and D. The
price is a floor on the reachable structure factor, which grows with N and |k|:
S(k) ≤ α N + β |k|², with α = 2·10⁻¹⁴ and β = 3·10⁻¹²
For a deeper optimisation, switch to float64. Like the backend, the precision is a module setting: it applies to the samplers and to the structure factor, so that points are always measured with the precision they were sampled with.
import qmc_sampler
qmc_sampler.select_precision("float64")
x = qmc_sampler.sample_l2(1000, 2)
qmc_sampler.plot_structure_factor(x) # also in float64
Plotting
from qmc_sampler import plot, plot_structure_factor
Both come from structure-factor-v2, installed
with qmc-sampler. plot_structure_factor uses the same module settings as the samplers
(backend of the dimension of the points, precision, NUFFT tolerance), and accepts all the
options of structure_factor_v2.plot_structure_factor, e.g. the Kaiser-tapered estimate for
non-periodic windows:
plot_structure_factor(x, trust_boundary=False)
plot_structure_factor(x, backend="keops") # overrides the module setting for this plot
Links
- Source: GitHub repository
- Package: PyPI
- Dataset: Zenodo
License
MIT
Metadata
Release files for qmc-sampler 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qmc_sampler-3.1.0.tar.gz | 18.6 kB | Without provenance | Details for qmc_sampler-3.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qmc_sampler-3.1.0-py3-none-any.whl | Python 3 | none | any | Details for qmc_sampler-3.1.0-py3-none-any.whl |
Total release size: 38.3 kB
Release files / qmc_sampler-3.1.0.tar.gz
| Download URL | qmc_sampler-3.1.0.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ece5aef54b53e54b4357296bea843484791bd3f7e3ed79236b451937fde3a01a
|
|
BLAKE2b-256 checksum How to use checksums |
40c1f055bd8bf987a494377c5a197f00d57e55d38430b3e6e79d9587acc4ed37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / qmc_sampler-3.1.0-py3-none-any.whl
| Download URL | qmc_sampler-3.1.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12cea00431d4700bcd6f86f0e59029120104dd417dae0c50544e2bf6409497d3
|
|
BLAKE2b-256 checksum How to use checksums |
84dbea24493b346f9c2e1d7373a17788b42c898fefd6f9f00a3d1a0ad97b2073
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for qmc-sampler 3.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.