6.5. operations#
- class ClassicalControl(onoff, qop)[source]#
Bases:
QuantumOperation
This class allows to turn a quantum operation into an operation with additional classical controls. The quantum operation is specified by the argument
`qop`
. The argument`onoff`
is a list of 0’s and 1’s corresponding to bits that control the operations when set to 0 and 1, respectively. This operator acts on classical bits and qubits. The number of classical bits is the length of the argument`onofff`
and the number of qubits is the same as for the quantum operation`qop`
.For instance,
`ClassicalControl([0,1], BasicGate("X", 2))`
defines a controlled version of the gate`BasicGate("X", 2)`
on two qubits. The resulting gate operates on two classical bits and two qubits and the gate is executed when the two bits are set to 0 and 1, respectively.- getEquivalentSequence()[source]#
Return an object of the class
`Sequence`
, which corresponds to the controlled version of the gate. This function replaces a`Sequence`
with control bits into a`Sequence`
of gates with the added control bits.- Returns:
sequence – An object of the class
`Sequence`
with controlled operations and with the appropriate bits and qubits. Note that the number of bits is extended by new bits, which get new names, which are unique in the`Sequence`
object.- Return type:
- getInverse()[source]#
Return an object of the same class, which corresponds to the inverse of the gate. The bit setting is the same, but the operation is inverted, if possible. If no inverse exists, then an exception is raised.
- Returns:
ClassicalControl – A new object of the class, which corresponds to the inverse gate. If no inverse exists, then an exception is raised.
- Return type:
- getNumberClassicalBits()[source]#
Return the number of classical bits that are used by this operation. This is the sum of the classical bits of the provided operation and the control bits.
- Returns:
numberBits – The number of classical bits, which are used by the controlled operation.
- Return type:
int
- getNumberQubits()[source]#
Return the number of qubits that are used by this operation. This is the same number as of the provided operation.
- Returns:
numberQubits – The number of qubits, which are used by the controlled operation.
- Return type:
int
- class DropQubits(numberQubits)[source]#
Bases:
QuantumOperation
This operation allows to specify that a number of qubits are dropped from the system. This means, that the number of qubits of the system is reduced and the resulting state of the smaller system is calculated by tracing out the dropped qubits.
For instance,
`DropQubits(1)`
corresponds to tracing out one qubit.- getEquivalentSequence()[source]#
Return a sequence, which is equivalent to this operation. A
`Sequence`
object is returned with this operation as only component in the list of operations.- Returns:
Sequence – An object of the class```Sequence``` is returned with this operation and the appropriate quantum targets in it.
- Return type:
geqo.core.quantum_circuits.Sequence
- getInverse()[source]#
Calling this method raises an exception because this operation has no inverse.
- 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 operation.
- Returns:
numberQubits – The number of qubits, which are used by this BasicGate.
- Return type:
int
- class Measure(numberQubits)[source]#
Bases:
QuantumOperation
This class allows to define a measurement operation. The argument
`numberQubits`
specifies the number of measured qubits. Besides the specified number of qubits, this operation also acts on the same number of classical bits for storing the measurement result.- getEquivalentSequence()[source]#
Return a sequence, which is equivalent to this operation. A
`Sequence`
object is returned with this operation as only component in the list of operations.- Returns:
Sequence – An object of the class```Sequence``` is returned with this operation and the appropriate quantum and classical targets in it.
- Return type:
geqo.core.quantum_circuits.Sequence
- getInverse()[source]#
Calling this method raises an exception because this operation has no inverse.
- getNumberClassicalBits()[source]#
- 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 BasicGate.
- Return type:
int
- class QuantumControl(onoff, qop)[source]#
Bases:
QuantumOperation
This class allows to turn a quantum operation into an operation with additional quantum controls. The argument
`onoff`
is a list of 0’s and 1’s corresponding to qubits that control the operations when in the state 0 and 1, respectively. The number of qubits of the resulting unitary is the number of qubits of the original gate plus the number of control qubits. The control qubits are ordered before the qubits of the original gate.For instance,
`QuantumControl([0,1],BasicGate("X", 2))`
defines a controlled version of the gate`BasicGate("X", 2)`
on two qubits. The resulting gate operates on four qubits and the gate is executed when the first and second qubit are in the basis states 0 and 1, respectively.- getEquivalentSequence()[source]#
Return an object of the class
`Sequence`
, which corresponds to the controlled version of the gate. This function replaces a`Sequence`
with control qubits into a`Sequence`
of gates with the added control qubits.- Returns:
sequence – An object of the class
`Sequence`
with controlled operations and with the appropriate bits and qubits. Note that the number of qubits is extended by new qubits, which get new names, which are unique in the`Sequence`
object.- Return type:
- getInverse(mustInvert=False)[source]#
Return an object of the same class, which corresponds to the inverse of the gate. The qubit setting is the same, but the operation is inverted, if possible. If no inverse exists, then an exception is raised.
- Returns:
QuantumControl – A new object of the class, which corresponds to the inverse gate. If no inverse exists, then an exception is raised.
- Return type:
- getNumberClassicalBits()[source]#
Return the number of classical bits that are used by this operation. This is the same number as of the provided operation.
- Returns:
numberBits – The number of classical bits, which are used by the controlled operation.
- Return type:
int
- getNumberQubits()[source]#
Return the number of qubits that are used by this operation. Note that this is the sum of the qubits of the provided operation and the number of control qubits.
- Returns:
numberQubits – The number of qubits, which are used by the controlled operation.
- Return type:
int