Skip to content

Commit 8788b62

Browse files
authored
Update dd at "pulled-throughs meet non-cliffords" (#7409)
Update dd at "pulled-throughs meet non-cliffords". * Add an extra logic of merge if it is possible as being described in the comment. * Also update the tests with an extra test case that would not generate the desired output with previous code.
1 parent 6bb6661 commit 8788b62

File tree

2 files changed

+227
-199
lines changed

2 files changed

+227
-199
lines changed

cirq-core/cirq/transformers/dynamical_decoupling.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,24 @@ def _update_pulled_through(q: ops.Qid, insert_gate: ops.Gate) -> ops.Operation:
276276
dd_iter_by_qubits[q] = cycle(base_dd_sequence)
277277
# Need to insert a new moment before current moment
278278
if new_moment_ops:
279-
# Fill insertable idle moments in the new moment using dd sequence
280-
for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
281-
if busy_moment_range_by_qubit[q][0] < moment_id <= busy_moment_range_by_qubit[q][1]:
282-
new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
283279
moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
284-
transformed_moments.pop(), circuits.Moment(new_moment_ops)
280+
transformed_moments[-1], circuits.Moment(new_moment_ops)
285281
)
286-
transformed_moments.extend(moments_to_be_appended)
282+
if len(moments_to_be_appended) == 1:
283+
transformed_moments.pop()
284+
transformed_moments.append(moments_to_be_appended[0])
285+
else: # Fill insertable idle moments in the new moment using dd sequence
286+
for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
287+
if (
288+
busy_moment_range_by_qubit[q][0]
289+
< moment_id
290+
<= busy_moment_range_by_qubit[q][1]
291+
):
292+
new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
293+
moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
294+
transformed_moments.pop(), circuits.Moment(new_moment_ops)
295+
)
296+
transformed_moments.extend(moments_to_be_appended)
287297

288298
# Step 2, calc updated_moment with insertions / merges.
289299
updated_moment_ops: set[cirq.Operation] = set()

0 commit comments

Comments
 (0)