Skip to content

pyo3_runtime.PanicException: index out of bounds in Rust nlayout.rs during Sabre transpilation on disconnected CouplingMap #15841

@YujinSong-hep

Description

@YujinSong-hep

Environment

  • Qiskit version: 2.3.1
  • Python version: 3.13.2
  • Operating system: macOS

What is happening?

When attempting to transpile a quantum circuit using the sabre routing method and optimization level 3, the transpiler crashes with a Rust thread panic if the provided CouplingMap contains disconnected subgraphs (islands) and the circuit contains a 2-qubit gate across these disconnected components.

Instead of gracefully raising a Python-level TranspilerError (e.g., indicating that routing is impossible due to a disconnected coupling map), the underlying Rust implementation panics with an index out of bounds error in crates/circuit/src/nlayout.rs.

How can we reproduce the issue?

import sys
from qiskit import QuantumCircuit, transpile
from qiskit.transpiler import CouplingMap

def generate_poisonous_circuit():
    # 1. Create a disconnected "island" coupling map
    edge_list = [[0, 1], [1, 0], [2, 3], [3, 2]]
    cmap = CouplingMap(edge_list)
    
    # 2. Create a circuit with a gate spanning the disconnected islands
    qc = QuantumCircuit(4)
    qc.h(0)
    qc.h(2)
    qc.cx(0, 2) # Fatal operation across islands
    
    return qc, cmap

if __name__ == "__main__":
    qc, cmap = generate_poisonous_circuit()
    
    # This will trigger the Rust panic
    transpiled_qc = transpile(qc, coupling_map=cmap, routing_method='sabre', optimization_level=3)

What should happen?

The transpiler should catch the invalid routing requirement at the Python/Rust boundary and raise a clear qiskit.transpiler.exceptions.TranspilerError (e.g., "Cannot route circuit: Qubits 0 and 2 are in disconnected components of the coupling map"), rather than panicking the Rust thread.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions