Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.03k stars 2.32k forks source link

Integer overflow when creating circuits from QASM files with large ints #12773

Closed nonhermitian closed 1 month ago

nonhermitian commented 1 month ago

Environment

What is happening?

As reported https://github.com/Qiskit/benchpress/issues/17, qasm imports lead to int overflows when qasm files contain large ints. E.g. this example will fail

OPENQASM 2.0;
include "qelib1.inc";
qreg q0[301];
creg c0[301];
h q0[300];
measure q0[300] -> c0[300];
if(c0==2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376) h q0[0];

with

thread '<unnamed>' panicked at crates/qasm2/src/lex.rs:279:42:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
PanicException: called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }

How can we reproduce the issue?

Run the above QASM file with QuantumCircuit.from_qasm_file

What should happen?

It should be imported

Any suggestions?

The int is larger than int64, which I assume is the root cause.

jakelishman commented 1 month ago

Thanks for the report. That's a pretty gross case. We fixed much of this in #12140, but this exact one implies we might need big-int handling in Rust space, if not now (we can hack around while we're still using Python space) then later just to represent huge classical register conditions.