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)
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)
Hmm, nothing in
TranspileLayoutshould be causing this. It’s just a dataclass container and thelayoutproperty set field should get set asTranspileLayout.initial_layoutwhich 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 theLayoutobject 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
Layoutobject 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 movedSabreLayoutto rust so something else changing is probably triggering it. But at least annotating theLayoutobject with registers inSabreLayoutwill fix the reported issue I think.