Implement reproducible event generation#51
Draft
theoheimel wants to merge 18 commits into
Draft
Conversation
Introduce a `seed` field in the mg7 run_card that makes CPU event generation reproducible: the same (seed, thread-pool sizes) reproduces bit-identically and distinct seeds are statistically independent. Seed 0 (the default) keeps the previous non-deterministic behaviour. madspace previously seeded every RNG from std::random_device with no seed input and drew randomness from thread-local generators dispatched to the pool in non-deterministic order, so runs were never reproducible. Plumbing: - run_card `[run] seed` + RunCardMG7 default; per-context seed derivation (splitmix64) in madevent.py and gridpack.py (--seed); Context(seed=) exposed through the Python bindings. - seeded_rng()/mix_seed() helpers in util.hpp; the driver-level random_device sites reseeded from the context seed. Determinism (gated on seed != 0, so the default path is unchanged): - Per-job RNG keyed by logical job identity (channel, sequence, phase) via Runtime::begin/end_job_rng, so a job's randomness no longer depends on which worker thread runs it. - Deterministic commit ordering: survey/generate harvest jobs in job-id order with unweighting folded in synchronously, making cross-section sums, max-weight snapshots, event order and stopping deterministic. Validated end-to-end through the mg7 driver with a dummy matrix element: same seed gives byte-identical events.npy at 4 and 8 threads, a different seed differs, and seed 0 differs run-to-run. Adds a portable unit test (madspace/tests/test_determinism.py) covering the seeding plumbing. For output_format = lhe, bit-identical output also needs combine_thread_pool_size = 1 (the parallel LHE combine is not yet deterministic); compact_npy and lhe_npy are reproducible at any size. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Conflict in madgraph/iolibs/template_files/mg7/gridpack.py: main added a resolve_verbosity() helper at the same spot this branch added derive_seed(); kept both. The other overlapping files (madevent.py, run_card.toml, banner.py, context.hpp) merged automatically. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The --seed argument was parsed but never passed to ms.Context, so reproducible gridpack runs had no effect. Derive a per-context seed from it and update the help text to match the run_card (reproducible at any cpu_thread_pool_size). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…l fractions in rounds
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.
Building on #48, implement reproducible event generation.
Design goals:
Tasks: