Skip to content

Commit fe946a1

Browse files
authored
Use fixed PauliString.after(). (#7103)
1 parent 22ed25e commit fe946a1

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

cirq-core/cirq/transformers/dynamical_decoupling.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def _pauli_up_to_global_phase(gate: ops.Gate) -> Union[ops.Pauli, None]:
5858
def _validate_dd_sequence(dd_sequence: Tuple[ops.Gate, ...]) -> None:
5959
"""Validates a given dynamical decoupling sequence.
6060
61+
The sequence should only consists of Pauli gates and is essentially an identity gate.
62+
6163
Args:
6264
dd_sequence: Input dynamical sequence to be validated.
6365
@@ -93,7 +95,7 @@ def _parse_dd_sequence(
9395
_validate_dd_sequence(schema)
9496
dd_sequence = schema
9597

96-
# Map Gate to Puali gate. This is necessary as dd sequence might contain gates like X^-1.
98+
# Map gate to Pauli gate. This is necessary as dd sequence might contain gates like X^-1.
9799
pauli_map: Dict[ops.Gate, ops.Pauli] = {}
98100
for gate in dd_sequence:
99101
pauli_gate = _pauli_up_to_global_phase(gate)
@@ -171,19 +173,13 @@ def _try_merge_single_qubit_ops_of_two_moments(
171173
def _calc_pulled_through(
172174
moment: circuits.Moment, input_pauli_ops: ops.PauliString
173175
) -> ops.PauliString:
174-
"""Calculates the pulled_through such that circuit(input_puali_ops, moment.clifford_ops) is
176+
"""Calculates the pulled_through such that circuit(input_pauli_ops, moment.clifford_ops) is
175177
equivalent to circuit(moment.clifford_ops, pulled_through).
176178
"""
177179
clifford_ops_in_moment: list[ops.Operation] = [
178180
op for op in moment.operations if _is_clifford_op(op)
179181
]
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))
182+
return input_pauli_ops.after(clifford_ops_in_moment)
187183

188184

189185
def _get_stop_qubits(moment: circuits.Moment) -> set[ops.Qid]:
@@ -197,7 +193,7 @@ def _get_stop_qubits(moment: circuits.Moment) -> set[ops.Qid]:
197193

198194

199195
def _need_merge_pulled_through(op_at_q: ops.Operation, is_at_last_busy_moment: bool) -> bool:
200-
"""With a pulling through puali gate before op_at_q, need to merge with the
196+
"""With a pulling through pauli gate before op_at_q, need to merge with the
201197
pauli in the conditions below."""
202198
# The op must be mergable and single-qubit
203199
if not (_is_single_qubit_operation(op_at_q) and has_unitary(op_at_q)):
@@ -234,7 +230,7 @@ def add_dynamical_decoupling(
234230

235231
busy_moment_range_by_qubit = _calc_busy_moment_range_of_each_qubit(orig_circuit)
236232

237-
# Stores all the moments of the output circuit chronically
233+
# Stores all the moments of the output circuit chronologically.
238234
transformed_moments: list[circuits.Moment] = []
239235
# A PauliString stores the result of 'pulling' Pauli gates past each operations
240236
# right before the current moment.
@@ -247,7 +243,7 @@ def _update_pulled_through(q: ops.Qid, insert_gate: ops.Gate) -> ops.Operation:
247243
pulled_through *= pauli_map[insert_gate].on(q)
248244
return insert_gate.on(q)
249245

250-
# Insert and pull remaining Puali ops through the whole circuit.
246+
# Insert and pull remaining Pauli ops through the whole circuit.
251247
# General ideas are
252248
# * Pull through Clifford gates.
253249
# * Stop at multi-qubit non-Clifford ops (and other non-mergable ops).

0 commit comments

Comments
 (0)