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`. diff --git a/graphix/circ_ext/extraction.py b/graphix/circ_ext/extraction.py index 0282f61ff..99d200264 100644 --- a/graphix/circ_ext/extraction.py +++ b/graphix/circ_ext/extraction.py @@ -554,7 +554,15 @@ 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. + # 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): negative_sign ^= meas.sign == Sign.MINUS diff --git a/tests/test_circ_extraction.py b/tests/test_circ_extraction.py index c1d9dd1b0..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,6 +439,33 @@ def test_cm_berg_pass(self, qc_ref: Circuit, cm: CliffordMap, fx_rng: Generator) class TestExtraction: + @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: 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) + @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))