4.1. Name Space Prefixes#
4.1.1. Background#
Several pre-defined gates in geqo are composed of other gates. For instance, the QFT uses internally several Phase
gates, which have the names Ph1
and Ph2
. These names are set with the prepareBackend
function automatically to pre-defined values within a backend.
Setting names to specific values might lead to conflicts if different gates are already using the same names. Note that there is no check if a name is already in use and there is no automatic creation of names, which are guaranteed to be free of conflicts with previously defined gates.
To avoid naming conflicts, the gates in geqo, which make use of internal names, support the definition of a name space prefix. The prefix is automatically prepended to all definitions and this allows to resolve conflicts with names.
4.1.2. Gates with name space prefix support in geqo#
A name space prefix can be provided for the following unitary gates in geqo:
InversePCCM
InverseQFT
PCCM
Toffoli
QFT
4.1.3. Example: QFT#
A QFT gate can be created with QFT(n, prefix)
. Here, n
denotes the number of qubits for the gate and prefix
is a character string that is prepended to all definitions of QFT components.
4.1.3.1. QFT without a name space prefix#
In this example, the QFT is used without name space. The internally used names are then Ph1
and Ph2
.
from geqo.algorithms import QFT
nQubits = 3
qft1 = QFT(nQubits, "")
print(qft1)
print(qft1.getEquivalentSequence())
QFT(3, "")
Sequence([], [0, 1, 2], [(Hadamard(), [0]), (QuantumControl([1], Phase("Ph1")), [1, 0]), (QuantumControl([1], Phase("Ph2")), [2, 0]), (Hadamard(), [1]), (QuantumControl([1], Phase("Ph1")), [2, 1]), (Hadamard(), [2]), (QubitReversal(3), [0, 1, 2])])
4.1.3.2. QFT with a name space prefix#
With the definition of a name space prefix, e.g., “Tester.”, the names Ph1
and Ph2
are prepend by the prefix, i.e. the internally used names are Tester.Ph1
and Tester.Ph2
.
qft2 = QFT(nQubits, "Tester.")
print(qft2)
print(qft2.getEquivalentSequence())
QFT(3, "Tester.")
Sequence([], [0, 1, 2], [(Hadamard(), [0]), (QuantumControl([1], Phase("Tester.Ph1")), [1, 0]), (QuantumControl([1], Phase("Tester.Ph2")), [2, 0]), (Hadamard(), [1]), (QuantumControl([1], Phase("Tester.Ph1")), [2, 1]), (Hadamard(), [2]), (QubitReversal(3), [0, 1, 2])])
4.1.3.3. Simulation of gates with name space prefixes#
As an example, we apply the two QFT’s as defined in the previous examples sequentially with the simulator simulatorUnitarySymPy
. All names Ph1
, Ph2
, Tester.Ph1
and Tester.Ph2
are available after using the function prepareBackend
. The sequential application of both QFT gates leads to the expected bit reversal permutation.
from geqo.simulators.sympy import simulatorUnitarySymPy
sim = simulatorUnitarySymPy(nQubits)
sim.prepareBackend([qft1, qft2])
print(sim.values)
sim.apply(qft1, [0, 1, 2])
sim.apply(qft2, [0, 1, 2])
display(sim.u)
{'Ph1': pi/2, 'Ph2': pi/4, 'Tester.Ph1': pi/2, 'Tester.Ph2': pi/4}