qiskit: MPL circuit drawer returning qubit[register] names for input

Environment

  • Qiskit Terra version: main
  • Python version:
  • Operating system:

Circuit drawings seem to include the full Qubit[register] label rather than just egq0, which makes the drawings a bit messy looking

qc = EfficientSU2(6, entanglement='circular')
x0 = np.random.random(size=qc.num_parameters)
qc.assign_parameters(x0, inplace=True)
trans_circ = transpile(qc, backend,
                       basis_gates=['rz', 'sx', 'cx'],
                       optimization_level=3)
trans_circ.draw('mpl', idle_wires=False, fold=-1)
Screenshot 2023-10-18 at 11 35 21

What is happening?

see above

How can we reproduce the issue?

see above

What should happen?

The drawer should return simple labels for the input qubits

Any suggestions?

No response

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Hmm, nothing in TranspileLayout should be causing this. It’s just a dataclass container and the layout property set field should get set as TranspileLayout.initial_layout which is what the visualizers access IIRC: https://github.com/Qiskit/qiskit/blob/main/qiskit/transpiler/runningpassmanager.py#L131 What this points to for me is that we’re missing adding a register when we create the Layout object that goes into the property set.

I believe that @SoranaAurelia is correct and I think the bug is actually in SabreLayout. If you look at: https://github.com/Qiskit/qiskit/blob/e49ff9096f9299352487656eb1d8f7022eebfd1a/qiskit/transpiler/passes/layout/sabre_layout.py#L270-L280 we’re setting the layout on the property set but neglecting to add the register information about the registers any of the bits in the layout belong to. It’s easy to fix we just need to ensure we add the registers which is already done in the non-rust path above it:

https://github.com/Qiskit/qiskit/blob/e49ff9096f9299352487656eb1d8f7022eebfd1a/qiskit/transpiler/passes/layout/sabre_layout.py#L250-L252

so we can just add that to after the Layout object creation in the rust sabre code path and it should correctly find the labels. Although, if this is the root cause, it’s been this way for a long time since at least #9116 which moved to creating the layout by just using bit indices, after we moved SabreLayout to rust so something else changing is probably triggering it. But at least annotating the Layout object with registers in SabreLayout will fix the reported issue I think.