Test samplerz()'s output distribution in CI - #9
Merged
Conversation
sampler.c gets its output chi2-tested against the folded PDT (test_sampler_c.py), but that covers only the *base* sampler -- half-Gaussian plus sign bit, no BerExp. samplerz(), the full sampler proposed in [HPRR20] and the artifact's headline deliverable, was covered only by test_sampler_determinism.py, which checks reproducibility and never the output distribution. So the paper's own sampler had no distribution test at all. Add one, over five (mu, sigma) points chosen for the boundaries that matter: centered, the worst-case fractional center for the sign/BerExp recombination, both ends of the permitted sigma range, and a large center. Plus a negative control asserting the battery rejects samples drawn at the wrong sigma, so the test cannot be vacuous. Seeded, hence deterministic: verified bit-identical samples and p-values on Python 3.10 and 3.12, the CI matrix. Observed Fisher p-values run 0.11..0.82 against an alpha of 0.001, so there is ample margin. Cost: ~3.3 s. Scope, honestly: this guards the class "the output distribution is wrong" (table corruption, sign/recombination bugs, sigma/mu scale errors), the same class test_sampler_c.py guards for the C sampler. Measured: it catches a corrupted table entry and a broken sign recombination, and it does NOT catch the two samplerz bugs fixed earlier -- the ccs scaling (a constant factor in z, so the output distribution is unchanged; only the rejection rate moves) nor the berexp p=-1 edge case (mass ~2^-72). It is a regression guard, not a catch-all. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The gap
sampler.cgets its output chi²-tested against the folded PDT (test_sampler_c.py) — but that covers only the base sampler: half-Gaussian plus sign bit, no BerExp.samplerz()— the full sampler proposed in [HPRR20], with the BerExp rejection step, and the artifact's headline deliverable — was covered only bytest_sampler_determinism.py, which checks reproducibility and never the output distribution.So the paper's own sampler had no distribution test at all, while its C base-sampler cousin did.
The test
Five
(mu, sigma)points chosen for the boundaries that matter:Plus a negative control: the battery must reject samples drawn at the wrong σ, so
test_samplerz_passes_batterycannot be vacuous.Seeded, hence deterministic. Verified bit-identical samples and p-values on Python 3.10 and 3.12 (the CI matrix):
Observed Fisher p-values run 0.11 … 0.82 against α = 0.001 — two orders of magnitude of headroom. Cost: ~3.3 s. No workflow change needed;
pytest code/tests/already discovers it.Scope, stated honestly
This guards the class "the output distribution is wrong" — the same class
test_sampler_c.pyguards for the C sampler. Measured against deliberately broken variants:ccsscaling (sf = σ/σ₀)berexpp = -1edge caseNote that means it would not have caught either of the two
samplerzbugs fixed earlier. It is a regression guard on the distribution, not a catch-all. (What would catch theccsbug is a check that the mean iteration count is constant in σ — deliberately out of scope, as isochrony testing was descoped.)Suite: 153 passed, 1 skipped.
🤖 Generated with Claude Code