Qiskit-terra: formalize gate operands as Qubit objects

Created on 4 Jan 2019  路  3Comments  路  Source: Qiskit/qiskit-terra


What is the expected enhancement?

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'])

then you could do

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.

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaygambetta picture jaygambetta  路  5Comments

delapuente picture delapuente  路  5Comments

Zhuravlev-A-E picture Zhuravlev-A-E  路  6Comments

ajavadia picture ajavadia  路  5Comments

Sridhar-Majety-UCD picture Sridhar-Majety-UCD  路  3Comments