circuit¶
Classes representing quantum circuits as a sequence of gates (Operator instances).
Circuits that differ only by permutations of commuting operators are not considered equal.
- class parityos.operators.circuit.CircuitLike¶
Bases:
OperatorLike[QubitT_co],Parameterized,HasFrozenQubits[QubitT_co],HasFrozenCBits,Sequence[Operator[QubitT_co]],ABCInterface for classes representing quantum circuits as ordered sequences of
Operatorinstances.This class does not apply any operator ordering.
Caution
Equivalent circuits (e.g. circuits that only differ by permutations of commuting operators), are not considered equal.
Example
>>> c1 = Circuit([X(get_q(1)), X(get_q(0)), CNOT(get_q(0), get_q(1))]) >>> c2 = Circuit([X(get_q(0)), X(get_q(1)), CNOT(get_q(0), get_q(1))]) >>> assert c1 != c2
- abstract property operators: tuple[Operator[QubitT_co], ...]¶
Ordered sequence of successive operators which make up the circuit.
- __add__(other: Circuit[OtherQubitT_co]) Circuit[QubitT_co | OtherQubitT_co]¶
- __add__(other: CircuitLike[OtherQubitT_co]) FrozenCircuit[QubitT_co | OtherQubitT_co]
- __add__(other: FrozenCircuit[OtherQubitT_co]) FrozenCircuit[QubitT_co | OtherQubitT_co]
Addition operator
+.Append another circuit to this circuit. Appending a circuit means appending
other’s operators toself’s operators.Note
If at least one of
selforotheris aFrozenCircuit, the output is also aFrozenCircuit.- Parameters:
other – Circuit to append.
- Returns:
Concatenation of this and the other circuit.
- __mul__(amount: int) Self¶
Multiplication operator
*.Create a new circuit by concatenating this circuit
amountnumber of times. This is similar in spirit to multiplying alistwith an integer.- Parameters:
amount – number of times.
- Returns:
A copy of
selfwith its operators concatenatedamountnumber of times.
- property name: str¶
Dynamically generated name for this operator.
Where applicable the name must coincide with the OpenQASM standard.
- substitute_parameters(old_to_new: Mapping[Parameter, Symbolic | complex]) Self¶
Substitute symbolic parameters with new symbolic expressions or numeric values.
- Parameters:
old_to_new – Mapping from existing parameter symbols to new values (numeric or symbolic).
- Returns:
Copy of
selfwith replaced parameters.
- __getitem__(index: int) Operator[QubitT_co]¶
- __getitem__(index: slice) tuple[Operator[QubitT_co], ...]
Return a single operator or a range of operators from this circuit.
Operators are indexed by their order in the circuit.
- Parameters:
index – The index of a single operator or a slice of indices for a range of operators.
- Returns:
The operators at position
indexin this circuit.
- class parityos.operators.circuit.Circuit(operator_sequence: T | Iterable[T] = NOTHING)¶
Bases:
CircuitLike[QubitT_co]Mutable circuit, which can be built up by successively adding operators.
A mutable
Circuitcan be turned into an immutableFrozenCircuitby callingfreeze.- operator_sequence: list[Operator[QubitT_co]]¶
Mutable
listof successive operators which make up the circuit.
- property operators: tuple[Operator[QubitT_co], ...]¶
Ordered sequence of successive operators which make up the circuit.
- property ordered_qubits: tuple[QubitT_co, ...]¶
Ordered sequence of qubits this object is defined on.
- property ordered_cbits: tuple[Cbit, ...]¶
An ordered sequence of classical bits this object is defined on.
- __setitem__(index: int, item: Operator[QubitT_co]) None¶
- __setitem__(index: slice, item: Iterable[Operator[QubitT_co]]) None
Set a single operator or a range of operators.
Operators are indexed by their order in the circuit.
- Parameters:
index – The index or slice of operators to be set.
item – The new
Operatorinstance(s) to be set.
- __delitem__(index: int | slice) None¶
Delete a single operator or a range of operators.
Operators are indexed by their order in the circuit.
- Parameters:
index – the index or slice of operators to be deleted
- insert(index: int, value: Operator[QubitT_co]) None¶
Insert an operator into the circuit between
index-1andindex.- Parameters:
index – Where the new operator should be inserted.
value – The new operator to be inserted.
- measure_all() Self¶
Add
Zmeasurement operations (MZ) for all qubits in the circuit.A new classical bit is created and added to the circuit for each qubit in the circuit.
Note
The added classical bits are enumerated in the order of
ordered_qubitswith increasing ids, skipping any ids already taken by existing classical bits.- Returns:
Modified
selfwith measurements for all circuit qubits appended.
- freeze() FrozenCircuit[QubitT_co]¶
Return an immutable copy of this circuit.
- class parityos.operators.circuit.FrozenCircuit(operator_sequence: T | Iterable[T])¶
Bases:
CircuitLike[QubitT_co],HasFrozenUnorderedQubits[QubitT_co],HasFrozenUnorderedCBitsImmutable Circuit, which is also hashable.
No operators can be added or removed. An immutable
FrozenCircuitcan be turned into a mutableCircuitby callingunfreeze.- operator_sequence: tuple[Operator[QubitT_co], ...]¶
Immutable
tupleof successive operators which make up the circuit.