Skip to content

Commit

Permalink
Add M and R aliases for cirq.measure and cirq.reset (#5993)
Browse files Browse the repository at this point in the history
Fixes #5992
Review: @pavoljuhas
  • Loading branch information
maffoo committed Jan 31, 2023
1 parent 24a0d2e commit 0c523d4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cirq-core/cirq/__init__.py
Expand Up @@ -236,6 +236,7 @@
LinearCombinationOfOperations,
MatrixGate,
MixedUnitaryChannel,
M,
measure,
measure_each,
measure_paulistring_terms,
Expand Down Expand Up @@ -284,6 +285,7 @@
QubitOrder,
QubitOrderOrList,
QubitPermutationGate,
R,
reset,
reset_each,
ResetChannel,
Expand Down
2 changes: 2 additions & 0 deletions cirq-core/cirq/ops/__init__.py
Expand Up @@ -41,6 +41,7 @@
phase_flip,
PhaseDampingChannel,
PhaseFlipChannel,
R,
reset,
reset_each,
ResetChannel,
Expand Down Expand Up @@ -126,6 +127,7 @@
from cirq.ops.matrix_gates import MatrixGate

from cirq.ops.measure_util import (
M,
measure,
measure_each,
measure_paulistring_terms,
Expand Down
8 changes: 7 additions & 1 deletion cirq-core/cirq/ops/common_channels.py
Expand Up @@ -775,10 +775,16 @@ def _json_dict_(self) -> Dict[str, Any]:


def reset(qubit: 'cirq.Qid') -> raw_types.Operation:
"""Returns a `cirq.ResetChannel` on the given qubit."""
"""Returns a `cirq.ResetChannel` on the given qubit.
This can also be used with the alias `cirq.R`.
"""
return ResetChannel(qubit.dimension).on(qubit)


R = reset


def reset_each(*qubits: 'cirq.Qid') -> List[raw_types.Operation]:
"""Returns a list of `cirq.ResetChannel` instances on the given qubits."""
return [ResetChannel(q.dimension).on(q) for q in qubits]
Expand Down
6 changes: 5 additions & 1 deletion cirq-core/cirq/ops/measure_util.py
Expand Up @@ -115,7 +115,8 @@ def measure(
) -> raw_types.Operation:
"""Returns a single MeasurementGate applied to all the given qubits.
The qubits are measured in the computational basis.
The qubits are measured in the computational basis. This can also be
used with the alias `cirq.M`.
Args:
*target: The qubits that the measurement gate should measure.
Expand Down Expand Up @@ -159,6 +160,9 @@ def measure(
return MeasurementGate(len(targets), key, invert_mask, qid_shape, confusion_map).on(*targets)


M = measure


@overload
def measure_each(
*qubits: raw_types.Qid, key_func: Callable[[raw_types.Qid], str] = str
Expand Down

0 comments on commit 0c523d4

Please sign in to comment.