Skip to content

pyo3_runtime.PanicException: no entry found for key in /project/rustworkx-core/src/token_swapper.rs:141:41 #16269

@lmaltsis

Description

@lmaltsis

Environment

  • Qiskit version: 8acbb04
  • Python version: Python 3.12.3
  • Operating system: Ubuntu 24.04.4 LTS

What is happening?

$ RUST_BACKTRACE=full python /tmp/bug.py

thread '<unnamed>' panicked at /project/rustworkx-core/src/token_swapper.rs:141:41:
no entry found for key
stack backtrace:
   0:     0x747fa43c4af6 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf435e8e9347709a8
   1:     0x747fa4378f13 - core::fmt::write::h0a51fad3804c5e7c
   2:     0x747fa43c456f - std::io::Write::write_fmt::h9759e4151bf4a45e
   3:     0x747fa43c4843 - std::sys::backtrace::BacktraceLock::print::h1ec5ce5bb8ee285e
   4:     0x747fa43c4243 - std::panicking::rust_panic_with_hook::h8b29cbe181d50030
   5:     0x747fa43ef328 - std::panicking::begin_panic_handler::{{closure}}::h9f5b6f6dc6fde83e
   6:     0x747fa43ef289 - std::sys::backtrace::__rust_end_short_backtrace::hd7b0c344383b0b61
   7:     0x747fa43efa8c - __rustc[5224e6b81cd82a8f]::rust_begin_unwind
   8:     0x747fa405adbf - core::panicking::panic_fmt::hc49fc28484033487
   9:     0x747fa405b2ea - core::option::expect_failed::hfe7afbd436ce9c45
  10:     0x747fa435e47d - rustworkx::token_swapper::__pyfunction_graph_token_swapper::h09ea1fd0969a13bd
  11:     0x747fa40f431c - pyo3::impl_::trampoline::trampoline::h013bbb6699fae59b
  12:     0x747fa435b4d1 - rustworkx::token_swapper::<impl rustworkx::token_swapper::graph_token_swapper::MakeDef>::_PYO3_DEF::trampoline::h48cf98b4d8f569ea
  13:           0x5821ef - <unknown>
  14:           0x5492b5 - _PyObject_MakeTpCall
  15:           0x5d7389 - _PyEval_EvalFrameDefault
  16:           0x5d58bb - PyEval_EvalCode
  17:           0x608b52 - <unknown>
  18:           0x6b5263 - <unknown>
  19:           0x6b4fca - _PyRun_SimpleFileObject
  20:           0x6b4dff - _PyRun_AnyFileObject
  21:           0x6bce65 - Py_RunMain
  22:           0x6bc94d - Py_BytesMain
  23:     0x748024e2a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  24:     0x748024e2a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  25:           0x657b05 - _start
  26:                0x0 - <unknown>
Traceback (most recent call last):
  File "/tmp/bug.py", line 15, in <module>
    ltpass.run(dag)
  File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passes/routing/layout_transformation.py", line 115, in run
    perm_circ = self.token_swapper.permutation_circuit(permutation, self.trials)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passes/routing/algorithms/token_swapper.py", line 77, in permutation_circuit
    sequential_swaps = self.map(permutation, trials=trials)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passes/routing/algorithms/token_swapper.py", line 105, in map
    return rx.graph_token_swapper(self.graph, mapping, trials, seed, parallel_threshold)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: no entry found for key

How can we reproduce the issue?

from qiskit import QuantumRegister, QuantumCircuit
from qiskit.converters import circuit_to_dag
from qiskit.transpiler import CouplingMap, Layout, Target
from qiskit.transpiler.passes import LayoutTransformation

v = QuantumRegister(4, "v")
coupling = CouplingMap([[0, 1], [1, 2], [2, 3]])
from_layout = Layout({v[0]: 0, v[1]: 4, v[2]: 2, v[3]: 3})
to_layout = Layout({v[0]: 3, v[1]: 0, v[2]: 1, v[3]: 2})
ltpass = LayoutTransformation(
    coupling_map=coupling, from_layout=from_layout, to_layout=to_layout, seed=42
)
qc = QuantumCircuit(4)
dag = circuit_to_dag(qc)
ltpass.run(dag)

What should happen?

input validation of layout

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions