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. |
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.