Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.02k stars 2.32k forks source link

plot_circuit_layout output unexpected with registerless circuits #6616

Open 1ucian0 opened 3 years ago

1ucian0 commented 3 years ago

What is the current behavior?

Consider the following backend:

from qiskit.visualization import plot_gate_map
from qiskit.test.mock import FakeManhattan

backend = FakeManhattan()
plot_gate_map(backend)

image

Let's create a circuit with a layout:

from qiskit import QuantumCircuit
from qiskit.visualization import plot_circuit_layout
from qiskit.transpiler import Layout

circuit = QuantumCircuit(15)
circuit._layout = Layout({ circuit.qubits[im_j]: cm_i for cm_i, im_j in [ (i,j) for i,j in enumerate(range(14, -1, -1)) ]})
plot_circuit_layout(circuit, backend)

image

The drawing is unexpected to me. The layout is non-trivial, for example:

circuit._layout[0]
Qubit(QuantumRegister(15, 'q'), 14)

What is the expected behavior?

I would expect 14 in the top corner, where the 0 appears.

Suggested solutions

This bug is probably related with the recently introduced registerless circuits.

singhsanskar202 commented 3 years ago

I would like to work on this issue.

javabster commented 3 years ago

Hi @singhsanskar202 it looks like there is already a PR open for this issue, feel free to help review the existing PR or pick up another issue 😄

singhsanskar202 commented 3 years ago

ok

Quant02 commented 3 years ago

I'm new here. Can I work on this one? I see no PR's for this or Is this issue solved?

javabster commented 3 years ago

I'm new here. Can I work on this one? I see no PR's for this or Is this issue solved?

Hi @Quant02 it looks like someone is already working on this and has opened a PR already. Please choose another issue to work on or reach out to the the first contributor to see if you can work with them or take over the issue if they are no longer up for it 😄

1ucian0 commented 2 years ago

The PR #6648 was not having a lot of movement. @singhsanskar202 or @Quant02, does any of you would like to take over? If you use the code in #6648, remember to co-author it.

ssawarn commented 2 years ago

I would like to work on it.

javabster commented 2 years ago

Assigned to you @stoicodin, let us know if you have any questions and remember to co-author if you use the code in #6648 😄

HuangJunye commented 2 years ago

@stoicodin Hey, just want to check in to see if you are still working on this issue. Please let us know if you need any help!

ssawarn commented 1 year ago

I need help. As soon as I get free i will reach out and resolve.

On 18-Aug-2022, at 15:47, Junye Huang @.***> wrote:



@stoicodinhttps://github.com/stoicodin Hey, just want to check in to see if you are still working on this issue. Please let us know if you need any help!

— Reply to this email directly, view it on GitHubhttps://github.com/Qiskit/qiskit-terra/issues/6616#issuecomment-1219311211, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AU2SB57323TQZBA4CPMRVULVZYEUTANCNFSM47BYCOHQ. You are receiving this because you were mentioned.Message ID: @.***>

1ucian0 commented 1 year ago

Hi @stoicodin, shall we return this issue to the unassigned pool?

ssawarn commented 1 year ago

yes sir

lmpawan10 commented 1 year ago

Hi, this is my first time here. I would like to work on the issue.

javabster commented 1 year ago

sure thing @lmpawan10 I'll assign to you 😄

As it is your first time here please remember to read the contributing guide. You may also find this youtube series useful for github tips as well

border-b commented 11 months ago

Hi @javabster, is this issue still open? If so, I would like to work in it as my first issue.

border-b commented 10 months ago

I tried to reproduce the issue and got the following error:

AttributeError: 'Layout' object has no attribute 'initial_layout'

It seems to be caused by the following code in gate_map.py

bit_locations = {
        bit: {"register": register, "index": index}
        for register in circuit._layout.initial_layout.get_registers()
        for index, bit in enumerate(register)
    }
    for index, qubit in enumerate(circuit._layout.initial_layout.get_virtual_bits()):
        if qubit not in bit_locations:
            bit_locations[qubit] = {"register": None, "index": index}

    if view == "virtual":
        for key, val in circuit._layout.initial_layout.get_virtual_bits().items():
            bit_register = bit_locations[key]["register"]
            if bit_register is None or bit_register.name != "ancilla":
                qubits.append(val)
                qubit_labels[val] = str(bit_locations[key]["index"])

    elif view == "physical":
        for key, val in circuit._layout.initial_layout.get_physical_bits().items():
            bit_register = bit_locations[val]["register"]
            if bit_register is None or bit_register.name != "ancilla":
                qubits.append(key)
                qubit_labels[key] = str(key)

Removing the initial_layout from this file reproduces the scenario that is described here. But the error persists when trying to use print(circuit). There is probably something wrong with the layout.py file where the initial_layout attribute is not properly defined.