Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
10 changes: 9 additions & 1 deletion graphix/circ_ext/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}:
Comment thread
pmitos marked this conversation as resolved.
Resolved
meas = og.measurements.get(n, None)
if isinstance(meas, PauliMeasurement):
negative_sign ^= meas.sign == Sign.MINUS
Expand Down
31 changes: 30 additions & 1 deletion tests/test_circ_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Loading