-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Environment
- Qiskit version: 2.2.3
- Python version: 3.11.3
- Operating system: Windows 10
What is happening?
When one creates a Layout for transpilation, using the __init__ argument input_dict, no matter how many registers there are in the Layout, get_registers() returns an empty list. I don't know if this is an intended behaviour, especially since a layout created with input_dict equals a layout whose registers have been added via add_register. If so, it would be useful to specify it in the documentation. One can understand that you're not specifically asking to "add a register" (to self._regs) when using input_dict, but I don't see the use case for creating a layout which uses the registers in ._v2p and ._p2v but keeps its register data empty. The documentation also says that from_list, which is used by the constructor, "populates the layout", but doesn't mention that it keeps the _regs empty.
This causes issues with transpilation passes on third party backends.
How can we reproduce the issue?
from qiskit.transpiler import Layout
from qiskit.circuit import QuantumRegister
q1 = QuantumRegister(3, "q")
q2 = QuantumRegister(4, "ancilla")
input_dict = {j: q for j, q in enumerate([*q1, *q2])}
layout = Layout(input_dict)
regs = layout.get_registers()
layout2 = Layout()
layout2.add_register(q1)
layout2.add_register(q2)
regs2 = layout2.get_registers()
# True
assert layout == layout2
# False
assert regs == regs2What should happen?
self._regs should contain the QuantumRegisters added by input_dict, or the documentation should warn that there are inequivalent ways to build layouts.
Any suggestions?
No response