-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Environment
- Qiskit Terra version: 0.19.1
- Python version: 3.9
- Operating system: macOS Monterey
What is happening?
Hi, I was playing around with different layout & routing options in the transpiler, and I noticed that the NoiseAdaptiveLayout pass sometime leads to errors in later passes because it adds invalid qubits to the layout.
How can we reproduce the issue?
Here's a minimized version of the example that I saw failing:
from qiskit import QuantumCircuit
from qiskit.test.mock import FakeMelbourne
from qiskit.compiler import transpile
backend = FakeMelbourne()
circuit = QuantumCircuit(12)
circuit.cx(1, 8)
circuit.cx(1, 11)
optimized_0 = transpile(circuit, backend=backend, optimization_level=0, layout_method='noise_adaptive')
What should happen?
On my machine, this code produces an error IndexError: index 14 is out of bounds for axis 1 with size 14
.
After some prodding, it seems that NoiseAdaptiveLayout is producing a layout that uses 15 qubits even though the backend only provides 14. To see this, you can run:
from qiskit import QuantumCircuit
from qiskit.test.mock import FakeMelbourne
from qiskit.transpiler import PassManager, CouplingMap
from qiskit.transpiler.passes import NoiseAdaptiveLayout
from qiskit.transpiler.passes import FullAncillaAllocation, EnlargeWithAncilla, ApplyLayout
backend = FakeMelbourne() # backend provides 14 qubits
coupling_map = CouplingMap(couplinglist=backend.configuration().coupling_map)
circuit = QuantumCircuit(12) # circuit has 12 qubits (and only uses 3)
circuit.cx(1, 8)
circuit.cx(1, 11)
_choose_layout = NoiseAdaptiveLayout(backend.properties())
def _choose_layout_condition(property_set):
return not property_set["layout"]
_embed = [FullAncillaAllocation(coupling_map), EnlargeWithAncilla(), ApplyLayout()]
pm = PassManager()
pm.append(_choose_layout, condition=_choose_layout_condition)
pm.append(_embed)
opt_circuit = pm.run(circuit)
print(opt_circuit) # circuit after layout has 15 qubits
Any suggestions?
Sorry I don't have a more concise example. I tried to reproduce the issue on a smaller backend (like Yorktown) but I couldn't find a circuit that caused this issue. Possibly there is something strange about the Melbourne backend?