PML-388: fixed random phase initialization in entangling layer if trainable is False - #284
Conversation
|
@claude review |
|
Claude finished @CassNot's task in 4m 27s —— View job Claude Code Review — PML-388I reviewed the diff against 🟠 1. Test-coverage gap for the g2 fix (the riskiest change)The most complex change ( Recommendation: add a small regression test that pins the augmented extra-photon sector probabilities to the corrected values, so a future refactor can't silently reintroduce the "grow a whole new SLOS graph" behavior. Fix this → 🟠 2. No length validation on user-supplied fixed phase values
🟡 3. Lost de-duplication → likely perf regression vs. the claim
🟡 4. Behavior change / reproducibility semantics
🟢 Minor
Correctness spot-checks (passed)
Tasks: read guidelines · reviewed components.py · circuit_builder.py · noisy_slos.py · tests — all complete. |
|
@claude review |
|
Claude finished @CassNot's task in 1m 56s —— View job Claude Code Review — PML-388 (re-review)Re-reviewed against
The remaining items are unchanged from last time: 🟡 1. Lost per-state de-duplication in
|
LF-Vigneux
left a comment
There was a problem hiding this comment.
Couple of changes in tests, everything else seems sound
|
@LF-Vigneux, I do not think it is possible for all values to be 0 because they are samples from a uniform distribution @claude review |
|
Claude finished @CassNot's task in 4m 23s —— View job Claude Code Review — PML-388 (3rd pass)Re-reviewed against On @LF-Vigneux's "they can technically be 0" — @CassNot is rightBoth of you are partly right, and the distinction matters, so here it is precisely: The reviewer is right that a single value can be exactly But the assertion as written is That is not "unlikely," it's beyond any operational notion of possible. Even the stricter One correction to the phrasing in the added comments ( # random.uniform() can in principle return exactly 0.0 (probability 2**-53),
# but this only fails if ALL 6 shifters do so simultaneously (~1e-96).
# Guards against the old bug where phases were hardcoded to 0.0.One more thing in the same spirit, in @CassNot's favour: the range assertion Optional, if you want the argument to be unnecessary rather than merely correct: pass 🟠 New: two likely CI lint/format failuresI could not execute
Both are auto-fixed by 🟡 New:
|
Summary
Non-trainable entangling layers (
add_entangling_layer(trainable=False, ...)) were silently pinning every inner/outer phase shifter to0.0, collapsing the block into a deterministic swap/identity instead of a random fixed unitary. This broke architectures (e.g. reservoir-computing style circuits) that rely on non-trainable entangling layers to inject a fixed random mix.GenericInterferometernow draws random fixed phases for any non-trainable phase shifters at construction time, optionally seeded for reproducibility.This also fixes a combinatorial bug in
NoisyG2SLOSComputeGraph. g2 extra-photon sectors were computed by growing a whole new SLOS graph per input state instead of reusing the base Orthogonal Bad Bits (OBB) partitions, causing incorrect probabilities/tests to rely on the degenerate zero-phase circuits. This bug was highlighted upon solving the first one (the tests were failing because the circuit was not a swap circuit anymore). This fix is inspired by Perceval management of g2 extra photon.Related Issue
PML-388
Type of change
Proposed changes
merlin/core/components.py:GenericInterferometergainsseed,fixed_inner_values, andfixed_outer_valuesfields.__post_init__now draws random phases (viarandom.Random(seed)) for any non-trainable inner/outer phase shifters instead of hardcoding0.0.merlin/builder/circuit_builder.py:add_entangling_layer(..., seed=None)forwards the seed toGenericInterferometer; the generated Perceval circuit now usesblock.fixed_inner_values/fixed_outer_valuesfor non-trainable phase shifters instead of literal0.0.merlin/pcvl_pytorch/noisy_slos.py: AddedNoisyG2SLOSComputeGraph._augmented_obb_probs, which reuses the cached OBB partitions of the base input state and grows only the coherent cell's Fock state by the g2-emitted photons, replacing the previous approach of running a full new SLOS graph per extra-photon combination. Fixes incorrect probabilities for g2 extra-photon sectors.NoisyG2SLOSComputeGraphfix.How to test / How to run
Performance considerations (optional)
No expected performance regression;
_augmented_obb_probsreuses cached SLOS subgraphs instead of allocating new ones per combination, so it should be at least as efficient as the previous implementation.Documentation
Checklist
SPHINXOPTS="-W --keep-going -n" make -C docs clean htmlthe docs are built without any warning or errors.