Using Qubit Placeholders

In PyQuil, we typically use integers to identify qubits

H 0
CNOT 0 1

However, when running on real, near-term QPUs we care about what particular physical qubits our program will run on. In fact, we may want to run the same program on an assortment of different qubits. This is where using QubitPlaceholders comes in.

H <QubitPlaceholder 4590706304>
CNOT <QubitPlaceholder 4590706304> <QubitPlaceholder 4590705912>

If you try to use this program directly, it will not work

---------------------------------------------------------------------------

RuntimeError                              Traceback (most recent call last)

<ipython-input-4-da474d3af403> in <module>()
----> 1 print(prog.out())

...

pyquil/pyquil/quilatom.py in out(self)
     53 class QubitPlaceholder(QuilAtom):
     54     def out(self):
---> 55         raise RuntimeError("Qubit {} has not been assigned an index".format(self))
     56
     57     def __str__(self):


RuntimeError: Qubit <QubitPlaceholder 4590706304> has not been assigned an index

Instead, you must explicitly map the placeholders to physical qubits. By default, the function address_qubits will address qubits from 0 to N.

H 0
CNOT 0 1

The real power comes into play when you provide an explicit mapping

H 14
CNOT 14 19

Register

Usually, your algorithm will use an assortment of qubits. You can use the convenience function QubitPlaceholder.register() to request a list of qubits to build your program.

H 0
H 2
H 4
H 6
H 8
H 10
H 12
H 14