Currently gates operate on qubits as a (QuantumRegister, int) tuple. To improve code clarity this could be formalized into it's own type.
A simple solution would be just something like,
```from collections import namedtuple
Qubit = namedtuple('Qubit', ['register', 'index'])
qr = QuantumRegister(5)
q1 = Qubit(qr, 1)
qc = QuantumCircuit(qr)
qc.x(q1)
if q1.register == qr and q1.index != 0:
qc.h(q1)
def my_gate(self, q):
assert isinstance(q, Qubit)
```
Something more complex could do type checking.
Yes and I think a QuantumRegister should really be just a list of Qubit. And slicing like qreg[2:5] yields just another list of qubits.
Checking for (QuantumRegister, int) tuples in the DAG and transpiler is a mess and this would clean things up a lot.
Has anyone started to work on this yet? If not, I would like to help. Would this enhancement ideally allow a user to choose whether to use the old syntax or should they be required to use the new style?
Hey @maddy-tod thanks for offering, I already started something along these lines. I'll push a commit and open new issues for follow ups that you're welcome to contribute to.
Most helpful comment
Yes and I think a QuantumRegister should really be just a list of Qubit. And slicing like qreg[2:5] yields just another list of qubits.
Checking for
(QuantumRegister, int)tuples in the DAG and transpiler is a mess and this would clean things up a lot.