cirq.Moment

A time-slice of operations within a circuit.

Used in the notebooks

Used in the tutorials

Grouping operations into moments is intended to be a strong suggestion to whatever is scheduling operations on real hardware. Operations in the same moment should execute at the same time (to the extent possible; not all operations have the same duration) and it is expected that all operations in a moment should be completed before beginning the next moment.

Moment can be indexed by qubit or list of qubits:

  • moment[qubit] returns the Operation in the moment which touches the given qubit, or throws KeyError if there is no such operation.
  • moment[qubits] returns another Moment which consists only of those operations which touch at least one of the given qubits. If there are no such operations, returns an empty Moment.

contents The operations applied within the moment. Will be flattened and frozen into a tuple before storing.
_flatten_contents If True, use flatten_to_ops to convert the OP_TREE of contents into a tuple of Operation. If False, we skip flattening and assume that contents already consists of individual operations. This is used internally by helper methods to avoid unnecessary validation.

ValueError A qubit appears more than once.

operations

qubits

Methods

expand_to

View source

Returns self expanded to given superset of qubits by making identities explicit.

Args
qubits Iterable of cirq.Qids to expand this moment to.

Returns
A new cirq.Moment with identity operations on the new qubits not currently found in the moment.

Raises
ValueError if this moments' qubits are not a subset of qubits.

from_ops

View source

Construct a Moment from the given operations.

This avoids calling flatten_to_ops in the moment constructor, which results in better performance in cases where the contents of the moment are already in the form of a sequence of operations rather than an arbitrary OP_TREE.

Args
*ops Operations to include in the Moment.

operates_on

View source

Determines if the moment has operations touching the given qubits.

Args
qubits The qubits that may or may not be touched by operations.

Returns
Whether this moment has operations involving the qubits.

operates_on_single_qubit

View source

Determines if the moment has operations touching the given qubit.

Args
qubit The qubit that may or may not be touched by operations.

Returns
Whether this moment has operations involving the qubit.

operation_at

View source

Returns the operation on a certain qubit for the moment.

Args
qubit The qubit on which the returned Operation operates on.

Returns
The operation that operates on the qubit for that moment.

to_text_diagram

View source

Create a text diagram for the moment.

Args
xy_breakdown_func A function to split qubits/qudits into x and y components. For example, the default breakdown turns cirq.GridQubit(row, col) into the tuple (col, row) and cirq.LineQubit(x) into (x, 0).
extra_qubits Extra qubits/qudits to include in the diagram, even if they don't have any operations applied in the moment.
use_unicode_characters Whether or not the output should use fancy unicode characters or stick to plain ASCII. Unicode characters look nicer, but some environments don't draw them with the same width as ascii characters (which ruins the diagrams).
precision How precise numbers, such as angles, should be. Use None for infinite precision, or an integer for a certain number of digits of precision.
include_tags Whether or not to include operation tags in the diagram.

Returns
The text diagram rendered into text.

transform_qubits

View source

Returns the same moment, but with different qubits.

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

Returns
The receiving moment but with qubits transformed by the given function.

with_operation

View source

Returns an equal moment, but with the given op added.

Args
operation The operation to append.

Returns
The new moment.

Raises
ValueError If the operation given overlaps a current operation in the moment.

with_operations

View source

Returns a new moment with the given contents added.

Args
*contents New operations to add to this moment.

Returns
The new moment.

Raises
ValueError If the contents given overlaps a current operation in the moment.

without_operations_touching

View source

Returns an equal moment, but without ops on the given qubits.

Args
qubits Operations that touch these will be removed.

Returns
The new moment.

__add__

View source

__bool__

View source

__eq__

View source

Return self==value.

__getitem__

View source

__iter__

View source

__len__

View source

__ne__

View source

Return self!=value.

__pow__

View source

__sub__

View source