Skip to content

Commit 0361a81

Browse files
authored
Fix dd issue in calling PauliString.after. (#6943)
1 parent cd9a3ff commit 0361a81

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

cirq-core/cirq/transformers/dynamical_decoupling.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ def _calc_pulled_through(
177177
clifford_ops_in_moment: list[ops.Operation] = [
178178
op for op in moment.operations if _is_clifford_op(op)
179179
]
180-
return input_pauli_ops.after(clifford_ops_in_moment)
180+
# TODO(#6946): directly pass clifford_ops_in_moment to input_pauli_ops.after() after #6946 is
181+
# fixed.
182+
affected_qubits = [q for op in clifford_ops_in_moment for q in op.qubits]
183+
all_cliffords_in_gate: ops.CliffordGate = ops.CliffordGate.from_op_list(
184+
clifford_ops_in_moment, affected_qubits
185+
)
186+
return input_pauli_ops.after(all_cliffords_in_gate.on(*affected_qubits))
181187

182188

183189
def _get_stop_qubits(moment: circuits.Moment) -> set[ops.Qid]:

cirq-core/cirq/transformers/dynamical_decoupling_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,61 @@ def test_cross_clifford_pieces_filling_merge():
774774
6: ───────────────────────────────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───X─────────────────────────@───PhXZ(a=0.8,x=0.8,z=0.5)─────H────────────────────────
775775
""",
776776
)
777+
778+
779+
def test_pull_through_phxz_gate_case1():
780+
"""Test case diagrams.
781+
Input:
782+
a: ───H───────PhXZ(a=0.25,x=-1,z=0)───────@───
783+
784+
b: ───H───H───H───────────────────────H───X───
785+
Output: expected circuit diagram below.
786+
"""
787+
a = cirq.NamedQubit('a')
788+
b = cirq.NamedQubit('b')
789+
790+
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0)
791+
assert_dd(
792+
input_circuit=cirq.Circuit(
793+
cirq.Moment(cirq.H(a), cirq.H(b)),
794+
cirq.Moment(cirq.H(b)),
795+
cirq.Moment(phxz(a), cirq.H(b)),
796+
cirq.Moment(cirq.H(b)),
797+
cirq.Moment(cirq.CNOT(a, b)),
798+
),
799+
expected_circuit="""
800+
a: ───H───X───PhXZ(a=0.25,x=-1,z=0)───X───@───Z───
801+
802+
b: ───H───H───H───────────────────────H───X───────
803+
""",
804+
schema="XX_PAIR",
805+
)
806+
807+
808+
def test_pull_through_phxz_gate_case2():
809+
"""Test case diagrams.
810+
Input:
811+
a: ───H───────PhXZ(a=0.2,x=-1,z=0)───────@───
812+
813+
b: ───H───H───H───────────────────────H───X───
814+
Output: expected circuit diagram below.
815+
"""
816+
a = cirq.NamedQubit('a')
817+
b = cirq.NamedQubit('b')
818+
819+
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.2, x_exponent=-1, z_exponent=0)
820+
assert_dd(
821+
input_circuit=cirq.Circuit(
822+
cirq.Moment(cirq.H(a), cirq.H(b)),
823+
cirq.Moment(cirq.H(b)),
824+
cirq.Moment(phxz(a), cirq.H(b)),
825+
cirq.Moment(cirq.H(b)),
826+
cirq.Moment(cirq.CNOT(a, b)),
827+
),
828+
expected_circuit="""
829+
a: ───H───X───PhXZ(a=0.1,x=0,z=0.4)───X───@───X───
830+
831+
b: ───H───H───H───────────────────────H───X───X───
832+
""",
833+
schema="XX_PAIR",
834+
)

0 commit comments

Comments
 (0)