Skip to content

Commit c8be206

Browse files
authored
Add reset_each function by analogy with measure_each (#4294)
Review: @viathor
1 parent 418d067 commit c8be206

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

cirq-core/cirq/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
QubitOrderOrList,
260260
QubitPermutationGate,
261261
reset,
262+
reset_each,
262263
ResetChannel,
263264
riswap,
264265
Rx,

cirq-core/cirq/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
PhaseDampingChannel,
4646
PhaseFlipChannel,
4747
reset,
48+
reset_each,
4849
ResetChannel,
4950
)
5051

cirq-core/cirq/ops/common_channels.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Quantum channels that are commonly used in the literature."""
1616

1717
import itertools
18-
from typing import Any, Dict, Iterable, Optional, Sequence, Tuple, Union, TYPE_CHECKING
18+
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
1919

2020
import numpy as np
2121

@@ -789,6 +789,11 @@ def reset(qubit: 'cirq.Qid') -> raw_types.Operation:
789789
return ResetChannel(qubit.dimension).on(qubit)
790790

791791

792+
def reset_each(*qubits: 'cirq.Qid') -> List[raw_types.Operation]:
793+
"""Returns a list of `ResetChannel` instances on the given qubits."""
794+
return [ResetChannel(q.dimension).on(q) for q in qubits]
795+
796+
792797
@value.value_equality
793798
class PhaseDampingChannel(gate_features.SingleQubitGate):
794799
"""Dampen qubit phase.

cirq-core/cirq/ops/common_channels_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,16 @@ def test_reset_act_on():
517517
)
518518

519519

520+
def test_reset_each():
521+
qubits = cirq.LineQubit.range(8)
522+
for n in range(len(qubits) + 1):
523+
ops = cirq.reset_each(*qubits[:n])
524+
assert len(ops) == n
525+
for i, op in enumerate(ops):
526+
assert isinstance(op.gate, cirq.ResetChannel)
527+
assert op.qubits == (qubits[i],)
528+
529+
520530
def test_phase_damping_channel():
521531
d = cirq.phase_damp(0.3)
522532
np.testing.assert_almost_equal(

0 commit comments

Comments
 (0)