Skip to content

feat(qmc): add Halton quasi-Monte Carlo sampler - #250

Open
Samuel-Vangu wants to merge 3 commits into
esa:developfrom
Samuel-Vangu:feat/add-halton-sampler
Open

feat(qmc): add Halton quasi-Monte Carlo sampler#250
Samuel-Vangu wants to merge 3 commits into
esa:developfrom
Samuel-Vangu:feat/add-halton-sampler

Conversation

@Samuel-Vangu

@Samuel-Vangu Samuel-Vangu commented Jul 30, 2026

Copy link
Copy Markdown

Description

Summary of changes

  • Adds Halton, a (optionally scrambled) Halton low-discrepancy sampler, shaped exactly like Sobol and RNG — plugs into MonteCarlo.integrate via the existing rng= slot, no changes to MonteCarlo itself.
  • torch backend: pure PyTorch implementation (digit extraction, hierarchical digit-shift scrambling, integer Horner reconstruction), generated directly on the target device — no CPU/NumPy round-trip needed, unlike SobolEngine.
  • numpy / jax / tensorflow backends: scipy.stats.qmc.Halton (already a hard dependency), converted to the requested backend.
  • Unlike Sobol, does not require the sample size to be a power of two.
  • Adds tests/halton_test.py, mirroring sobol_test.py's structure, plus Halton-specific regression tests (see Test plan).

Resolved Issues

How Has This Been Tested?

  • halton_test.py, all backends: analytic accuracy against the test-function collection, Halton < plain-MC error at equal N (fixed seed), seed reproducibility, torch gradient flow
  • test_digits_needed_is_per_dimension: deterministic, seed/device-independent unit test guarding against a real bug found during development (a shared digit count across dimensions silently broke equidistribution for every dimension except the one with the smallest base)
  • test_halton_column_independent_of_other_dimensions: exact-equality check that a dimension's column never depends on which other dimensions are requested alongside it
  • test_halton_matches_scipy_when_unscrambled: pure-PyTorch and SciPy backends agree to within float64 machine epsilon (~2e-16) when scrambling is off, validating the digit extraction/reconstruction independently of the scrambling logic
  • test_halton_no_power_of_two_warning: confirms no spurious warning for non-power-of-two N
  • ruff format --check . clean (57 files)

Related Pull Requests

@Samuel-Vangu

Copy link
Copy Markdown
Author

@gomezzz, this one's ready for CI too whenever you get a chance — thanks!

@Samuel-Vangu

Copy link
Copy Markdown
Author

@gomezzz ,

While waiting on Lattice, I checked Halton against everything you flagged
there and fixed what was necessary.

19/19 tests pass.
Happy to have you take a look whenever you're free.

@gomezzz gomezzz mentioned this pull request Aug 23, 2026
39 tasks

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The torch scrambling is truncated to _digits_needed(base, number_of_points), so its claimed unbiased randomisation is not actually uniform: for N=1 in the first dimension, m=1 and the sample can only be 0 or 0.5 across seeds. That biases the QMC estimator for general integrands; add a random tail/continuous shift (or otherwise make the randomisation unbiased) and include an N=1 distribution regression.

@Samuel-Vangu

Copy link
Copy Markdown
Author

@sylvesterkaczmarek

Confirmed and fixed. Added a continuous tail shift after digit
scrambling.

Added the N=1 regression: 200 seeds now span way more than 2 distinct
values, and are no longer confined to {0.0, 0.5}.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scrambled Halton construction now adds continuous tail randomization, and the N=1 multi-seed regression demonstrates that the first coordinate is no longer confined to the two-point set caused by the truncated digit permutation. This resolves the bias issue I raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants