A time-slice of operations within a circuit.
cirq.Moment(
*contents, _flatten_contents: bool = True
) -> None
Used in the notebooks
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.
Args |
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.
|
Raises |
ValueError
|
A qubit appears more than once.
|
Attributes |
operations
|
|
qubits
|
|
Methods
expand_to
View source
expand_to(
qubits: Iterable['cirq.Qid']
) -> 'cirq.Moment'
Returns self expanded to given superset of qubits by making identities explicit.
Args |
qubits
|
Iterable of cirq.Qid s 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
@classmethod
from_ops(
*ops
) -> 'cirq.Moment'
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
operates_on(
qubits: Iterable['cirq.Qid']
) -> bool
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
operates_on_single_qubit(
qubit: 'cirq.Qid'
) -> bool
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
operation_at(
qubit: cirq.Qid
) -> Optional['cirq.Operation']
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
to_text_diagram(
*,
xy_breakdown_func: Callable[['cirq.Qid'], Tuple[Any, Any]] = _default_breakdown,
extra_qubits: Iterable['cirq.Qid'] = (),
use_unicode_characters: bool = True,
precision: Optional[int] = None,
include_tags: bool = True
) -> str
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.
|
View source
transform_qubits(
qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']]
) -> Self
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
with_operation(
operation: 'cirq.Operation'
) -> 'cirq.Moment'
Returns an equal moment, but with the given op added.
Args |
operation
|
The operation to append.
|
Raises |
ValueError
|
If the operation given overlaps a current operation in the moment.
|
with_operations
View source
with_operations(
*contents
) -> 'cirq.Moment'
Returns a new moment with the given contents added.
Args |
*contents
|
New operations to add to this moment.
|
Raises |
ValueError
|
If the contents given overlaps a current operation in the moment.
|
without_operations_touching
View source
without_operations_touching(
qubits: Iterable['cirq.Qid']
) -> 'cirq.Moment'
Returns an equal moment, but without ops on the given qubits.
Args |
qubits
|
Operations that touch these will be removed.
|
__add__
View source
__add__(
other: 'cirq.OP_TREE'
) -> 'cirq.Moment'
__bool__
View source
__bool__() -> bool
__eq__
View source
__eq__(
other
) -> bool
Return self==value.
__getitem__
View source
__getitem__(
key
)
__iter__
View source
__iter__() -> Iterator['cirq.Operation']
__len__
View source
__len__() -> int
__ne__
View source
__ne__(
other
) -> bool
Return self!=value.
__pow__
View source
__pow__(
power
)
__sub__
View source
__sub__(
other: 'cirq.OP_TREE'
) -> 'cirq.Moment'