View source on GitHub |
Operation annotated with a set of tags.
Inherits From: Operation
cirq.TaggedOperation(
sub_operation: 'cirq.Operation', *tags
)
These Tags can be used for special processing. TaggedOperations
can be initialized with using Operation.with_tags(tag)
or by using TaggedOperation(op, tag)
.
Tags added can be of any type, but they should be Hashable in order to allow equality checking. If you wish to serialize operations into JSON, you should restrict yourself to only use objects that have a JSON serialization.
See Operation.with_tags()
for more information on intended usage.
Methods
controlled_by
controlled_by(
*control_qubits,
control_values: Optional[Union[cv.AbstractControlValues, Sequence[Union[int, Collection[int]]]]
] = None
) -> 'cirq.Operation'
Returns a controlled version of this operation. If no control_qubits are specified, returns self.
Args | |
---|---|
*control_qubits
|
Qubits to control the operation by. Required. |
control_values
|
For which control qubit values to apply the
operation. A sequence of the same length as control_qubits
where each entry is an integer (or set of integers)
corresponding to the qubit value (or set of possible values)
where that control is enabled. When all controls are enabled,
the operation is applied. If unspecified, control values
default to 1.
|
transform_qubits
transform_qubits(
qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']]
) -> Self
Returns the same operation, but with different qubits.
Args | |
---|---|
qubit_map
|
A function or a dict mapping each current qubit into a desired new qubit. |
Returns | |
---|---|
The receiving operation but with qubits transformed by the given function. |
Raises | |
---|---|
TypeError
|
qubit_map was not a function or dict mapping qubits to qubits. |
validate_args
validate_args(
qubits: Sequence['cirq.Qid']
)
Raises an exception if the qubits
don't match this operation's qid shape.
Call this method from a subclass's with_qubits
method.
Args | |
---|---|
qubits
|
The new qids for the operation. |
Raises | |
---|---|
ValueError
|
The operation had qids that don't match it's qid shape. |
with_classical_controls
with_classical_controls(
*conditions
) -> 'cirq.Operation'
Returns a classically controlled version of this operation.
An operation that is classically controlled is executed iff all
conditions evaluate to True. Conditions can be either a measurement key
or a user-specified cirq.Condition
. A measurement key evaluates to
True iff any qubit in the corresponding measurement operation evaluated
to a non-zero value; cirq.Condition
supports more complex,
user-defined conditions.
If no conditions are specified, returns self.
The classical control will remove any tags on the existing operation, since tags are fragile, and we always opt to get rid of the tags when the underlying operation is changed.
Args | |
---|---|
*conditions
|
A list of measurement keys, strings that can be parsed into measurement keys, or sympy expressions where the free symbols are measurement key strings. |
Returns | |
---|---|
A ClassicallyControlledOperation wrapping the operation. If no conditions
are specified, returns self.
|
with_probability
with_probability(
probability: 'cirq.TParamVal'
) -> 'cirq.Operation'
Creates a probabilistic channel with this operation.
Args | |
---|---|
probability
|
floating point value between 0 and 1, giving the probability this gate is applied. |
Returns | |
---|---|
cirq.RandomGateChannel that applies self with probability
probability and the identity with probability 1-p .
|
Raises | |
---|---|
NotImplementedError
|
if called on an operation that lacks a gate. |
with_qubits
with_qubits(
*new_qubits
)
Returns the same operation, but applied to different qubits.
Args | |
---|---|
*new_qubits
|
The new qubits to apply the operation to. The order must
exactly match the order of qubits returned from the operation's
qubits property.
|
with_tags
with_tags(
*new_tags
) -> 'cirq.TaggedOperation'
Creates a new TaggedOperation with combined tags.
Overloads Operation.with_tags to create a new TaggedOperation that has the tags of this operation combined with the new_tags specified as the parameter.
without_classical_controls
without_classical_controls() -> 'cirq.Operation'
Removes all classical controls from the operation.
This function removes all classical controls gating the operation. It acts recursively, so that all classical control wrappers are always removed from the current operation.
If there are no classical controls on the operation, it will return
self
.
Since tags are fragile, this will also remove any tags from the operation,
when called on TaggedOperation
(unless there are no classical controls on it).
If a TaggedOperation
is under all the classical control layers,
that TaggedOperation
will be returned from this function.
Returns | |
---|---|
The operation with all classical controls removed. |
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool
__mul__
__mul__(
other: Any
) -> Any
__ne__
__ne__(
other: _SupportsValueEquality
) -> bool
__pow__
__pow__(
exponent: Any
) -> 'cirq.Operation'
__rmul__
__rmul__(
other: Any
) -> Any