Skip to content

Commit

Permalink
Add reset_each function by analogy with measure_each (#4294)
Browse files Browse the repository at this point in the history
Review: @viathor
  • Loading branch information
maffoo committed Jul 9, 2021
1 parent 418d067 commit c8be206
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions cirq-core/cirq/__init__.py
Expand Up @@ -259,6 +259,7 @@
QubitOrderOrList,
QubitPermutationGate,
reset,
reset_each,
ResetChannel,
riswap,
Rx,
Expand Down
1 change: 1 addition & 0 deletions cirq-core/cirq/ops/__init__.py
Expand Up @@ -45,6 +45,7 @@
PhaseDampingChannel,
PhaseFlipChannel,
reset,
reset_each,
ResetChannel,
)

Expand Down
7 changes: 6 additions & 1 deletion cirq-core/cirq/ops/common_channels.py
Expand Up @@ -15,7 +15,7 @@
"""Quantum channels that are commonly used in the literature."""

import itertools
from typing import Any, Dict, Iterable, Optional, Sequence, Tuple, Union, TYPE_CHECKING
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING

import numpy as np

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


def reset_each(*qubits: 'cirq.Qid') -> List[raw_types.Operation]:
"""Returns a list of `ResetChannel` instances on the given qubits."""
return [ResetChannel(q.dimension).on(q) for q in qubits]


@value.value_equality
class PhaseDampingChannel(gate_features.SingleQubitGate):
"""Dampen qubit phase.
Expand Down
10 changes: 10 additions & 0 deletions cirq-core/cirq/ops/common_channels_test.py
Expand Up @@ -517,6 +517,16 @@ def test_reset_act_on():
)


def test_reset_each():
qubits = cirq.LineQubit.range(8)
for n in range(len(qubits) + 1):
ops = cirq.reset_each(*qubits[:n])
assert len(ops) == n
for i, op in enumerate(ops):
assert isinstance(op.gate, cirq.ResetChannel)
assert op.qubits == (qubits[i],)


def test_phase_damping_channel():
d = cirq.phase_damp(0.3)
np.testing.assert_almost_equal(
Expand Down

0 comments on commit c8be206

Please sign in to comment.