From 69a8459ce52b08242f82009477406cddbedcec17 Mon Sep 17 00:00:00 2001 From: Piotr Bartosz Mitosek Date: Thu, 29 Oct 2026 16:38:43 +0100 Subject: [PATCH 1/4] Fix extraction signs for negative Pauli input measurements 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 --- graphix/circ_ext/extraction.py | 3 ++- tests/test_circ_extraction.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/graphix/circ_ext/extraction.py b/graphix/circ_ext/extraction.py index 0282f61ff..62d6202e7 100644 --- a/graphix/circ_ext/extraction.py +++ b/graphix/circ_ext/extraction.py @@ -554,7 +554,8 @@ def extraction_ps_from_corrected_node(flow: PauliFlow[Measurement], node: Node) negative_sign ^= bool(len(inter_c_odd_set) // 2 % 2) # One phase flip per node in the graph state stabilizer that is absorbed from a Pauli measurement with angle π. - for n in c_set | odd_c_set: + # The current vertex remains unprojected in its extraction string. + for n in (c_set | odd_c_set) - {node}: meas = og.measurements.get(n, None) if isinstance(meas, PauliMeasurement): negative_sign ^= meas.sign == Sign.MINUS diff --git a/tests/test_circ_extraction.py b/tests/test_circ_extraction.py index c1d9dd1b0..e7f6e3dc0 100644 --- a/tests/test_circ_extraction.py +++ b/tests/test_circ_extraction.py @@ -437,6 +437,19 @@ def test_cm_berg_pass(self, qc_ref: Circuit, cm: CliffordMap, fx_rng: Generator) class TestExtraction: + 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("jumps", range(1, 11)) def test_extract_rnd_circuit(self, fx_bg: PCG64, jumps: int) -> None: rng = Generator(fx_bg.jumped(jumps)) From 6c31d4468f7d1781048c05a1f4e563c1b40698e2 Mon Sep 17 00:00:00 2001 From: Piotr Bartosz Mitosek Date: Thu, 29 Oct 2026 17:30:55 +0100 Subject: [PATCH 2/4] Document the negative Pauli input extraction fix Add the Unreleased changelog entry requested by the pull request template. Agent: Codex Requested-by: pmitos Co-authored-by: Codex --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1a6133e..a96267b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed incorrect Clifford signs during circuit extraction for input vertices measured in negative Pauli X or Y bases. + - #598, #608: - The order of the attributes of the controlled instructions has been changed to put the control qubits first, to ensure consistency between all controlled instructions, with the matrix description of the gates, and with the `Circuit` methods that add instructions to the circuit. - `CZ` is now a `ControlledSingleTargetInstruction` and takes a `control` and a `target` instead of a pair of `targets`. From ff1a78167f0c6034d6286b5264bc3cbb10cc614f Mon Sep 17 00:00:00 2001 From: Piotr Bartosz Mitosek Date: Mon, 2 Nov 2026 15:08:21 +0100 Subject: [PATCH 3/4] Extend negative Pauli input regression test to cover both -X and -Y input measurements. Agent: Codex Requested-by: pmitos Co-authored-by: Codex --- tests/test_circ_extraction.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/test_circ_extraction.py b/tests/test_circ_extraction.py index e7f6e3dc0..f31c16b88 100644 --- a/tests/test_circ_extraction.py +++ b/tests/test_circ_extraction.py @@ -16,13 +16,15 @@ from graphix.measurements import Measurement from graphix.opengraph import OpenGraph from graphix.parameter import Placeholder -from graphix.random_objects import rand_circuit +from graphix.random_objects import rand_circuit, rand_state_vector from graphix.states import BasicStates from graphix.transpiler import Circuit if TYPE_CHECKING: from numpy.random import PCG64 + from graphix.measurements import PauliMeasurement + class PauliExpTestCase(NamedTuple): pexp_dag: PauliExponentialDAG @@ -437,19 +439,33 @@ def test_cm_berg_pass(self, qc_ref: Circuit, cm: CliffordMap, fx_rng: Generator) class TestExtraction: - def test_extract_negative_x_input(self) -> None: + @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 HS. + ], + ids=["-X", "-Y"], + ) + def test_extract_negative_pauli_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: -Measurement.X}, + measurements={0: meas}, ) 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.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) + @pytest.mark.parametrize("jumps", range(1, 11)) def test_extract_rnd_circuit(self, fx_bg: PCG64, jumps: int) -> None: rng = Generator(fx_bg.jumped(jumps)) From a2a4fadaa6662515a8fa18e6c64c920e169f4c68 Mon Sep 17 00:00:00 2001 From: Piotr Mitosek <49618370+pmitos@users.noreply.github.com> Date: Thu, 5 Nov 2026 01:30:50 +0100 Subject: [PATCH 4/4] formula for c comment Co-authored-by: thierry-martinez --- graphix/circ_ext/extraction.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/graphix/circ_ext/extraction.py b/graphix/circ_ext/extraction.py index 62d6202e7..99d200264 100644 --- a/graphix/circ_ext/extraction.py +++ b/graphix/circ_ext/extraction.py @@ -555,6 +555,13 @@ def extraction_ps_from_corrected_node(flow: PauliFlow[Measurement], node: Node) # One phase flip per node in the graph state stabilizer that is absorbed from a Pauli measurement with angle π. # The current vertex remains unprojected in its extraction string. + # The equation for c after Eq. 35 in [Simmons 21](https://arxiv.org/abs/2109.05654) + # should instead read: + # $$ + # c = b + |(p(v) \cup \text{Odd}[p(v)]) \cap \lbrace u \in \overline{O}\setminus \lbrace v \rbrace + # | \lambda(u) \in \lbrace X, Y, Z\rbrace \land \alpha(u) = \pi \rbrace | + # $$ + # See discussion in #645 for further information. for n in (c_set | odd_c_set) - {node}: meas = og.measurements.get(n, None) if isinstance(meas, PauliMeasurement):