I'm currently trying to make my own TransformationPass to use when compiling a QuantumCircuit for specific hardware, but I'm struggling to get things to work with the DAGCircuit that gets passed to the run(self, dag)
method that gets overridden. My main issue at the moment is trying to figure out which qubits each node in the graph actually operates on. I can access the wire for each node, but accessing the qubit index from there raises a DeprecationWarning.
I can simply ignore the warning, but it gives me the impression that I should be going about this another way.
Is there a formal method for accessing the qubit (either object or simply its index) given the DAG?
For DAGCircuit
right now there isn't a great answer for this. The .index
attribute is deprecated as in the case of standalone bit objects on the circuit if they're in a register it might not yield the result you expect (it'll be the register index not the index on the circuit necessarily).
I typically do this by having something like:
dag_qubit_map = {bit: index for index, bit in enumerate(dag.qubits)}
and then I can get the index with a dict look up, something like:
bit_index = dag_qubit_map[node.qargs[0]]
On the QuantumCircuit
class there is a .find_bit()
method which does this easily: https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.find_bit.html
so you can do:
bit_index = QuantumCircuit(bit).index
But an equivalent API is still needed for the DAGCircuit class.