Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyO3 panic during SabreLayout #8635

Closed
jakelishman opened this issue Aug 30, 2022 · 0 comments · Fixed by #8636
Closed

PyO3 panic during SabreLayout #8635

jakelishman opened this issue Aug 30, 2022 · 0 comments · Fixed by #8636
Assignees
Labels
bug Something isn't working Rust This PR or issue is related to Rust code in the repository

Comments

@jakelishman
Copy link
Member

Environment

  • Qiskit Terra version: main @ bab9d45
  • Python version: 3.10/macOS (me) or 3.8/Linux (CI)
  • Operating system:

What is happening?

Randomised testing found a case where PyO3 is panicking and reporting "Graph::add_edge: node indices out of bounds" during SabreSwap (triggered by SabreLayout).

How can we reproduce the issue?

from qiskit import QuantumCircuit, transpile
from qiskit.providers.fake_provider import FakeKolkata
qc = QuantumCircuit.from_qasm_str("""
 OPENQASM 2.0;
include "qelib1.inc";
qreg q4833[1];
qreg q4834[6];
qreg q4835[7];
creg c982[2];
creg c983[2];
creg c984[2];
rzz(0) q4833[0],q4834[4];
cu(0,-6.1035156e-05,0,1e-05) q4834[1],q4835[2];
swap q4834[0],q4834[2];
cu(-1.1920929e-07,0,-0.33333333,0) q4833[0],q4834[2];
ccx q4835[2],q4834[5],q4835[4];
measure q4835[4] -> c984[0];
ccx q4835[2],q4835[5],q4833[0];
measure q4835[5] -> c984[1];
measure q4834[0] -> c982[1];
u(10*pi,0,1.9) q4834[5];
measure q4834[3] -> c984[1];
measure q4835[0] -> c982[0];
rz(0) q4835[1];
""")
transpile(qc, FakeKolkata(), layout_method="sabre")

this produces (exception shortened):

thread '<unnamed>' panicked at 'Graph::add_edge: node indices out of bounds', /Users/jake/.cargo/registry/src/github.com-1ecc6299db9ec823/petgraph-0.6.2/src/graph_impl/mod.rs:573:27
---------------------------------------------------------------------------
PanicException                            Traceback (most recent call last)
<ipython-input-5-55111b87744c> in <module>
     24 rz(0) q4835[1];
     25 """)
---> 26 transpile(qc, FakeKolkata(), layout_method="sabre")

< ... transpile pass-manager setup ... >

~/code/qiskit/terra/qiskit/transpiler/passes/layout/sabre_layout.py in run(self, dag)
     97             for _ in ("forward", "backward"):
     98                 pm = self._layout_and_route_passmanager(initial_layout)
---> 99                 new_circ = pm.run(circ)
    100
    101                 # Update initial layout and reverse the unmapped circuit.

< ... SabreLayout's delegated PM setup ... >

~/code/qiskit/terra/qiskit/transpiler/passes/routing/sabre_swap.py in run(self, dag)
    208             )
    209         front_layer = np.asarray([x._node_id for x in dag.front_layer()], dtype=np.uintp)
--> 210         sabre_dag = SabreDAG(len(dag.qubits), len(dag.clbits), dag_list, front_layer)
    211         swap_map, gate_order = build_swap_map(
    212             len(dag.qubits),

PanicException: Graph::add_edge: node indices out of bounds

What should happen?

Successful transpilation - this looks like a potential bug in the new Rusty Sabre handover (#8388).

Any suggestions?

No response

@jakelishman jakelishman added bug Something isn't working Rust This PR or issue is related to Rust code in the repository labels Aug 30, 2022
@mtreinish mtreinish self-assigned this Aug 30, 2022
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Aug 30, 2022
This commit fixes a bug introduced in SabreSwap that was caught by the
randomized testing in Qiskit#8635. A copy paste error was causing the rusty
sabre code to panic in cases where there were classical bits of a
particular index assigned prior to the qubit with the same index. This
commit fixes the typo so the behavior is corrected in general and the
panic is also fixed.

Fixes Qiskit#8635
@mergify mergify bot closed this as completed in 367ed4e Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants