Skip to main content

qmc-sampler

PyPI GitHub Dataset

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 point cloud over every wave vector of an exclusion region. 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 are available:

  • sample_l2(N, D): isotropic L2 ball, the classical choice.
  • sample_l1(N, D): L1 ball, anisotropic, useful when the integrand has a low effective dimension.
  • sample_wd(N, D): weights of the wrap-around discrepancy, which push this low-effective-dimension idea further.

Extra parameters (Chi, n_iter, seed, precision, eps, ...) can be set to the samplers, and are described in Params.md.

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, use precision="float64" (and, with the (cu)FINUFFT backends, a small eps):

x = sample_l2(1000, 2, precision="float64")

Backends

All Fourier sums go through one of four backends:

backend method cost dimensions accuracy
"keops" direct sums, pykeops (GPU if available) O(N M) any exact (machine precision)
"torch" direct sums, torch (CUDA if available) O(N M) any exact (machine precision)
"cufinufft" non-uniform FFT on GPU (cufinufft + cupy) O(N log N + M) D <= 3 tolerance eps (1e-4 float32, 1e-8 float64)
"finufft" non-uniform FFT on CPU O(N log N + M) D <= 3 tolerance eps (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.

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 used trades accuracy for speed; pass a smaller eps to go down to machine precision.

pip install finufft                  # or: pip install "qmc-sampler[finufft]"
pip install cufinufft cupy-cuda12x   # GPU, CUDA 12 (CUDA 11: cupy-cuda11x)
import qmc_sampler

qmc_sampler.select_backend(dimensions={2, 3}, backend="finufft")   # or "cufinufft"

Plotting

from qmc_sampler import plot, plot_structure_factor   # adapted from blue_sampler

plot_structure_factor uses the backend selected for the dimension of the points.

License

MIT

Metadata

Release files for qmc-sampler 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qmc-sampler 3.0.1
File Size Uploaded Provenance Actions
qmc_sampler-3.0.1.tar.gz 20.3 kB Without provenance Details for qmc_sampler-3.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qmc-sampler 3.0.1
File Interpreter ABI Platform Actions
qmc_sampler-3.0.1-py3-none-any.whl Python 3 none any Details for qmc_sampler-3.0.1-py3-none-any.whl

Total release size: 42.9 kB

Release files / qmc_sampler-3.0.1.tar.gz

Download URL qmc_sampler-3.0.1.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a9e7b010442719f7627837f7b7a6093cec7023e1687bda981ee2314698cac880
BLAKE2b-256 checksum
How to use checksums
4defd0f52c43ae5e7aea75ee855de60b794a35c76910781cac23f8de1c56141c
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.0.1-py3-none-any.whl

Download URL qmc_sampler-3.0.1-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb29866b95150701bf555fb30082e4c254272c56d9c12f2493980f908c82fe3a
BLAKE2b-256 checksum
How to use checksums
cdf2e2fbd2eb62dc21ada64ea9ad327921c9fb01a44f0aa21ddbedce5f47deb4
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.0.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page