Repository navigation
Fix negative sign in circuit extraction strings - #645
thierry-martinez merged 4 commits into
Conversation
Exclude the corrected vertex when absorbing negative Pauli measurement signs, since it remains unprojected in its own extraction string. Add the two-node negative-X regression that implements HZ. Agent: Codex Requested-by: pmitos Co-authored-by: Codex <noreply@openai.com>
Add the Unreleased changelog entry requested by the pull request template. Agent: Codex Requested-by: pmitos Co-authored-by: Codex <noreply@openai.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #645 +/- ##
=======================================
Coverage 89.96% 89.96%
=======================================
Files 49 49
Lines 8462 8462
=======================================
Hits 7613 7613
Misses 849 849 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
matulni
left a comment
There was a problem hiding this comment.
Very nice, thank you very much for the bug-fix @pmitos !
I just made a comment suggesting to extend the test, otherwise it looks good to merge to me (the policy of the repository is two approvals to merge).
I have a question, though. The contribution to the phase was calculated following the formula
defined right after Eq. 35 in Simmons 21. The loop
for n in (c_set | odd_c_set):corresponded to the term - {node}), or is there a mistake in the equation ?
| def test_extract_negative_x_input(self) -> None: | ||
| og = OpenGraph( | ||
| graph=nx.path_graph(2), | ||
| input_nodes=[0], | ||
| output_nodes=[1], | ||
| measurements={0: -Measurement.X}, | ||
| ) | ||
| clifford_map = og.to_pauliflow().extract_circuit().clifford_map | ||
|
|
||
| # The outcome-zero branch implements HZ. | ||
| assert clifford_map.x_map == (PauliString.from_str("-Z"),) | ||
| assert clifford_map.z_map == (PauliString.from_str("+X"),) |
There was a problem hiding this comment.
I suggest adding both previously failing cases -Y and -X. For completeness, I also suggest adding the full round-trip simulation check, that is, comparing the output from simulating OpenGraph -> CausalFlow -> Pattern and OpenGraph -> PauliFlow -> Circuit.
The code below requires
from graphix.random_objects import rand_state_vector (on L19)
and
from graphix.measurements import PauliMeasurement (under the TYPE_CHECKING block, L25)
| def test_extract_negative_x_input(self) -> None: | |
| og = OpenGraph( | |
| graph=nx.path_graph(2), | |
| input_nodes=[0], | |
| output_nodes=[1], | |
| measurements={0: -Measurement.X}, | |
| ) | |
| clifford_map = og.to_pauliflow().extract_circuit().clifford_map | |
| # The outcome-zero branch implements HZ. | |
| assert clifford_map.x_map == (PauliString.from_str("-Z"),) | |
| assert clifford_map.z_map == (PauliString.from_str("+X"),) | |
| @pytest.mark.parametrize( | |
| ("meas", "x_map"), | |
| [ | |
| (-Measurement.X, (PauliString.from_str("-Z"),)), # The outcome-zero branch implements HZ. | |
| (-Measurement.Y, (PauliString.from_str("-Y"),)), # The outcome-zero branch implements HY. | |
| ], | |
| ) | |
| def test_extract_negative_x_input( | |
| self, meas: PauliMeasurement, x_map: tuple[PauliString, ...], fx_rng: Generator | |
| ) -> None: | |
| og = OpenGraph( | |
| graph=nx.path_graph(2), | |
| input_nodes=[0], | |
| output_nodes=[1], | |
| measurements={0: meas}, | |
| ) | |
| clifford_map = og.to_pauliflow().extract_circuit().clifford_map | |
| assert clifford_map.x_map == x_map | |
| assert clifford_map.z_map == (PauliString.from_str("+X"),) | |
| input_state = rand_state_vector(nqubits=1, rng=fx_rng) | |
| state_qc = og.to_circuit().simulate(rng=fx_rng, input_state=input_state).state | |
| state_pattern = og.simulate(rng=fx_rng, input_state=input_state) | |
| assert state_qc.isclose(state_pattern) |
…nput measurements. Agent: Codex Requested-by: pmitos Co-authored-by: Codex <noreply@openai.com>
|
Hello @matulni, and thanks for the review. Yes, the equation for c after (35) in Simmons should instead read: i.e., omitting v itself when counting negative Pauli measurements. This follows from Definition 4.2, which doesn't project v. Updated the code as suggested, with some renaming since we no longer only cover (-X). One small thing: for (-Y), your Pauli images are correct, but they correspond to HS instead of HY. |
thierry-martinez
left a comment
There was a problem hiding this comment.
Thank you very much, @pmitos. I would just suggest adding a comment to document this discussion in the code.
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
Context (if applicable):
For inputs measured as (-X) or (-Y), circuit extraction produces the wrong sign in the extraction string. For example, two connected vertices with a (-X) input and an output produce circuit HY instead of HZ. If the input is instead represented as XY(1), the result is correct.
Description of the change:
Exclude the corrected vertex itself when counting the negative Pauli measurements. Add a small regression test and a changelog entry.
Related issue:
None