6.2. core#
- class BasicGate(name, numberQubits)[source]#
Bases:
QuantumOperation
This class allows to define a unitary operation with a specified name and a specified number of qubits. For instance, a unitary gate with the name “CNOT” on two qubits is defined with
`BasicGate("CNOT", 2)`
. The inverse can be obtained with`getInverse()`
and it returns an object of type`InverseBasicGate`
.Note that the definition of the corresponding unitary matrix depends on the chosen backend and must be defined with the function
`setValue`
of the backend.- getEquivalentSequence()[source]#
Return a sequence, which is equivalent to this gate. Here, no
`Sequence`
object is returned because a basic gate cannot be decomposed.- Returns:
None – No
`Sequence`
object is returned because this gate cannot be decomposed.- Return type:
None
- getInverse()[source]#
Return an object of the class
`InverseBasicGate`
, which corresponds to the inverse of the gate. The name and the number of qubits are the same.- Returns:
InverseBasicGate – A new object of the class, which corresponds to the inverse gate.
- Return type:
- getNumberClassicalBits()[source]#
- Returns:
0 – The number of classical bits, which are used by PermuteQubits, is zero.
- Return type:
int
- getNumberQubits()[source]#
Return the number of qubits that are used by this BasicGate.
- Returns:
numberQubits – The number of qubits, which are used by this BasicGate.
- Return type:
int
- class InverseBasicGate(name, numberQubits)[source]#
Bases:
QuantumOperation
This class allows to define the inverse of a unitary operation with a specified name and a specified number of qubits. For instance, a unitary gate with the name “CNOT” on two qubits is defined with
`BasicGate("CNOT", 2)`
. The inverse can be obtained with`getInverse()`
and it returns an object of type`BasicGate`
.Note that the definition of the corresponding unitary matrix depends on the chosen backend and must be defined with the function
`setValue`
of the backend.- getEquivalentSequence()[source]#
Return a sequence, which is equivalent to this gate. Here, no
`Sequence`
object is returned because a basic gate cannot be decomposed.- Returns:
None – No
`Sequence`
object is returned because this gate cannot be decomposed.- Return type:
None
- getInverse()[source]#
Return an object of the class
`BasicGate`
, which corresponds to the inverse of the gate. The name and the number of qubits are the same.- Returns:
BasicGate – A new object of the class, which corresponds to the inverse gate.
- Return type:
- getNumberClassicalBits()[source]#
- Returns:
0 – The number of classical bits, which are used by PermuteQubits, is zero.
- Return type:
int
- getNumberQubits()[source]#
Return the number of qubits that are used by this InverseBasicGate.
- Returns:
numberQubits – The number of qubits, which are used by this InverseBasicGate.
- Return type:
int
- class QuantumOperation[source]#
Bases:
object
Abstract base class for all quantum operations. These operations can be unitary and non-unitary and they can act on classical bits and qubits.
- abstract getEquivalentSequence()[source]#
Return an object of the class
`Sequence`
, which corresponds to a sub-class, if a corresponing object is defined.
- abstract getInverse()[source]#
Return the inverse of a sub-class, if the inverse exists. If no inverse exists, then raise an exception.
- abstract getNumberClassicalBits()[source]#
Get the number of classical bits on which the sub-class operations.
- class Sequence(bits, qubits, gatesAndTargets, name=None)[source]#
Bases:
QuantumOperation
This class allows to gather operations together in a single operation. It corresponds to a quantum circuit. A circuit consists of classical bits, qubits and a sequence of operations.
The list of classical bits and qubits are specified by the arguments
`bits`
and`qubits`
, which can be numbers or character strings.The argument
`gatesAndTargets`
is a list of tuples and each element of the list is processed in the given order. A tuple consists of a quantum operation and one or two target specifications. If an operation only affects qubits, then the target specification is the list of corresponding qubits. If an operation affects classical bits as well as qubits, then the first target specification is a list of corresponding classical bits and the second target specification is a list of corresponding qubits.For convenience, the parameter
`name`
can be used to assign a name to the sequence.- getEquivalentSequence()[source]#
Return an object of the class
`Sequence`
which corresponds to this object.- Returns:
sequence – Returns the same object because it is an instantiation of the class
`Sequence`
.- Return type:
- getInverse()[source]#
Return an object of the same class, but each element of the list of operations is replaced by its inverse and the order of operations is reversed. Might raise an exception if an operation is not invertible.
- Returns:
Sequence – A new object of this class, which corresponds to the inverse operations.
- Return type:
- getNumberClassicalBits()[source]#
Return the number of classical bits that are used by this operation.
- Returns:
numberBits – The number of classical bits, which are used by this operation.
- Return type:
int
- getNumberQubits()[source]#
Return the number of qubits that are used by this operation.
- Returns:
numberQubits – The number of qubits, which are used by this operation.
- Return type:
int