0
$\begingroup$

I have the following code

for instruction, qargs, cargs in qc.data:
    qbit: qiskit.circuit.Qubit = qargs[0]
    print(qbit.register)
    print(qbit.index)

the last 2 lines give me a warning:

DeprecationWarning: Back-references to from Bit instances to their containing Registers have been deprecated. Instead, inspect Registers to find their contained Bits.

How can I read them to avoid the warning?

$\endgroup$

1 Answer 1

1
$\begingroup$

The correct way to retrieve the index of a bit within a circuit, and any registers in that circuit the bit is contained within is to call QuantumCircuit.find_bit() as follows:

for instruction, qargs, cargs in qc.data:
    qbit: Qubit = qargs[0]
    bit_location = qc.find_bit(qbit)
    print(bit_location.index)
    print(bit_location.registers[0])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.