Skip to content

Circuit.get_q_register seems to assume the register is zero indexed #2096

@CalMacCQ

Description

@CalMacCQ

I've encountered some confusing behaviour with Circuit.get_q_register when the register we're "getting" has qubits which are not indexed starting from 0.

Consider the following example where I create an eight qubit circuit with two registers. I'll then add some CX gates to the circuit in such a way as to leave some the first three qubits without a quantum gate acting upon them.

circ = Circuit()
control_reg = circ.add_q_register("q", 1)
block = circ.add_q_register("b", 7)

for t in (3, 4, 5, 6):
    circ.CX(control_reg[0], block[t])

I can then remove the three blank qubits b[0], b[1], b[2]

circ.remove_blank_wires()

Now what happens if we list the remaining qubits in circ?

Using circ.qubits gives the expected answer

print(circ.qubits)

Output:

[b[3], b[4], b[5], b[6], q[0]] 

However if we use circ_get_q_register to list the qubits in the "b" register we get a stange answer.

print(list(circ.get_q_register("b")))

Output:

[b[0], b[1], b[2], b[3]]

This seems strange. The register has the right number of qubits but I was expecting to see the list

 [b[3], b[4], b[5], b[6]]

It seems that the get_q_register methods is reindexing the qubits to be indexed from b[0]-b[3].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions