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:

geqo.core.basic.InverseBasicGate

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

hasDecomposition()[source]#
Returns:

False – A BasicGate is considered to be as a non-decomposable operation.

Return type:

Bool

isUnitary()[source]#
Returns:

True – This is a unitary operation.

Return type:

Bool

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:

geqo.core.basic.BasicGate

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

hasDecomposition()[source]#
Returns:

False – A BasicGate is considered to be as a non-decomposable operation.

Return type:

Bool

isUnitary()[source]#
Returns:

True – This is a unitary operation.

Return type:

Bool

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.

abstract getNumberQubits()[source]#

Get the number of qubits on which the sub-class operations.

abstract hasDecomposition()[source]#

Return True or False depending on whether a replacement `Sequence` object is defined for the method `getEquivalentSequence`.

abstract isUnitary()[source]#

Return True or False depending on the unitary of a sub-class.

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:

geqo.core.Sequence

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:

geqo.core.quantum_circuit.Sequence

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

hasDecomposition()[source]#
Returns:

True – A sequence is its own representation as object of the class `Sequence`.

Return type:

Bool

isUnitary()[source]#
Returns:

  • True (Bool) – If all gates in this `Sequence` are unitary.

  • False (Bool) – Else.