Augments existing operations to have one or more control qubits.

Inherits From: Operation

This object is typically created via operation.controlled_by(*qubits).

classical_controls The classical controls gating this operation.





tags Returns a tuple of the operation's tags.
untagged Returns the underlying operation without any tags.



View source

Returns a controlled version of this operation. If no control_qubits are specified, returns self.

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.


View source

Returns the same operation, but with different qubits.

qubit_map A function or a dict mapping each current qubit into a desired new qubit.

The receiving operation but with qubits transformed by the given function.

TypeError qubit_map was not a function or dict mapping qubits to qubits.


View source

Raises an exception if the qubits don't match this operation's qid shape.

Call this method from a subclass's with_qubits method.

qubits The new qids for the operation.

ValueError The operation had qids that don't match it's qid shape.


View source

Returns a classically controlled version of this operation.

An operation that is classically controlled is executed iff all conditions evaluate to True. Currently the only condition type is a measurement key. A measurement key evaluates to True iff any qubit in the corresponding measurement operation evaluated to a non-zero value.

The classical control will hide any tags on the existing operation, since tags are considered a local attribute.

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.

A ClassicallyControlledOperation wrapping the operation.


View source


View source

Returns the same operation, but applied to different qubits.

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.


View source

Creates a new TaggedOperation, with this op and the specified tags.

This method can be used to attach meta-data to specific operations without affecting their functionality. The intended usage is to attach classes intended for this purpose or strings to mark operations for specific usage that will be recognized by consumers. Specific examples include ignoring this operation in optimization passes, hardware-specific functionality, or circuit diagram customizability.

Tags can be a list of any type of object that is useful to identify this operation as long as the type is hashable. If you wish the resulting operation to be eventually serialized into JSON, you should also restrict the operation to be JSON serializable.

new_tags The tags to wrap this operation in.


View source

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 considered local, this will also remove any tags from the operation (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.

The operation with all classical controls removed.


View source


View source