tqec.circuit.moment.Moment#
- class Moment(circuit: Circuit, used_qubits: set[int] | None = None, _avoid_checks: bool = False)[source]#
A collection of instructions that can be executed in parallel.
This class is a collection of stim.CircuitInstruction instances that can all be executed in parallel. That means that it maintains the following invariant:
For each instruction contained in any instance of this class, exactly one of the following assertions is true:
The instruction is an annotation (e.g., QUBIT_COORDS, DETECTOR, …),
- It is the only instruction of the Moment instance to be applied
on its targets. In other words, no other instructions in the Moment instance can be applied on the targets this instruction is applied to.
In practice, that means that this class match closely the definition of [cirq.Moment](https://quantumai.google/reference/python/cirq/Moment). The only minor different is that cirq only uses the second assertion above (meaning that an annotation might push a quantum gate to the next moment, even though the annotation is never executed in hardware).
- __init__(circuit: Circuit, used_qubits: set[int] | None = None, _avoid_checks: bool = False) None [source]#
Initialize a Moment instance.
- Parameters:
circuit – collection of instructions representing the Moment. It should represent a valid moment, see the class documentation for a detailed explanation of the pre-conditions.
used_qubits – a set of qubit indices used in the provided circuit. It is the user responsibility to ensure that this input is correct if it is provided, as any non-None input will not be checked. Defaults to None, which triggers a call to
get_used_qubit_indices()
to initialise the indices._avoid_checks – avoid checking the validity of the provided circuit. This parameter can be used when the user knows that the provided circuit is a valid moment (and so checks the pre-conditions listed in the class documentation). Defaults to False, which triggers a systematic check and might raise if the provided circuit is not a valid moment.
- Raises:
TQECException – if the circuit contains one or more TICK instruction.
TQECException – if the circuit contains at least 2 non-annotation instructions that are applied on the same qubit target.
TQECException – if the circuit contains a REPEAT block instruction.
Methods
__init__
(circuit[, used_qubits, _avoid_checks])Initialize a Moment instance.
append
(name_or_instr[, targets, args])Append an instruction to the
Moment
.append_annotation
(annotation_instruction)Append an annotation instruction to the Moment.
check_is_valid_moment
(circuit)Check if the provided circuit can be considered a valid moment.
contains_instruction
(instruction_name)Return True if self contains at least one operation with the provided name.
filter_by_qubits
(qubits_to_keep)Return a new
Moment
instance containing only the instructions that are applied on the provided qubits.remove_all_instructions_inplace
(...)Remove in-place all the instructions that have their name in the provided instructions_to_remove.
with_mapped_qubit_indices
(qubit_index_map)Map the qubits indices the Moment instance is applied on.
Attributes