Seed the RNG in the eight notebooks whose model depends on random draws - #1679
Seed the RNG in the eight notebooks whose model depends on random draws#1679kluger-classiq wants to merge 1 commit into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Heads-up on the red
Fixing it is a workflow change on the base repo, so I cannot do it from a fork. Two options I am aware of: split the workflow so untrusted code runs under If it is easier, push this branch inside |
84801d7 to
fbfa891
Compare
|
Rebased onto The The step is
Either way it is a base-repo change I cannot make from a fork. Still happy for someone to push |
fbfa891 to
c55dafb
Compare
|
CI ran properly this time -- thanks for the Result: 2 failed, 5 passed, 163 skipped -- and both failures are pre-existing on The nightly Both are SDK-API drift rather than anything seed-related: one notebook reads the deprecated Per-notebook outcome for the 8 changed files:
So the five notebooks that have a working test all pass with the new seeds, including |
Eight notebooks build their QMod model from unseeded random draws, so every execution produces a different quantum model. That makes their generated circuits irreproducible run to run, and means the same notebook cannot be recognized as itself across runs. Seed the relevant generator with 1337 in each. Where the notebook draws from a global generator (numpy or stdlib `random`) the seed goes next to the imports; `select_structures_BE` also builds its own `np.random.default_rng()`, which a global seed cannot reach, so that call gets the seed directly. `variational_quantum_imaginary_time_evolution` already seeded its Generator with 42 -- switched to 1337 so one value is used throughout -- and additionally needed the stdlib seed, since both its Newman-Watts-Strogatz topology and its edge weights draw from `random`. Verified by extracting each notebook's model twice with no external seeding: all eight now produce identical models across runs, and each still yields the same number of models as before. Note that the committed cell outputs still reflect the old random draws and will refresh on the next execution. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
c55dafb to
2682c28
Compare
PR Description
Closes #1678.
Eight notebooks build their QMod model from unseeded random draws, so every execution produces a different quantum model and the committed outputs cannot be reproduced. This seeds the relevant generator with
1337in each.Placement follows what each notebook actually draws from:
quantum_volumenp.random.seed(1337)next to thescipy.stats.unitary_groupimport (haar()draws from NumPy's global RNG) andrandom.seed(1337)for the qubit shufflerandomized_benchmarkingrandom.seed(1337)after the imports, for the sampled Clifford sequencestensor_hypercontractionnp.random.seed(1337)before thenp.random.choiceblockset_partitionnp.random.seed(1337)beforenp.random.randintradio_access_network_positioning_antennasnp.random.seed(1337)before the consumption coefficientsWS_iQuHack_2025_finalnp.random.seed(1337)before the amplitude drawselect_structures_BEnp.random.seed(1337)after the imports andnp.random.default_rng(1337)-- the notebook builds its ownGenerator, which a global seed cannot reachvariational_quantum_imaginary_time_evolutionrandom.seed(1337)after the imports (both the Newman-Watts-Strogatz topology and the edge weights draw fromrandom), and its existingdefault_rng(seed=42)switched to1337so one value is used throughoutSource-only change: 31 insertions, 3 deletions, no restructuring.
Verification
Each notebook's model was extracted twice with no external seeding, so the only source of determinism is the notebook itself. All eight now produce identical models across runs, and each still yields the same number of models as before the change (3, 1, 1, 5, 4, 1, 7, 2), confirming nothing downstream broke.
Some notes
rebaseon your branch (no merge commits)main.Only
select_structures_BEtruly required a code change rather than a seed call; the rest are one-liners. Choice of1337is arbitrary but applied consistently.🤖 Generated with Claude Code