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

Running a program that involves more than isize::MAX gates triggers a panic in circuit builder #2099

Closed
swernli opened this issue Jan 9, 2025 · 2 comments · Fixed by #2113
Labels
bug Something isn't working needs triage

Comments

@swernli
Copy link
Collaborator

swernli commented Jan 9, 2025

Because in compiler/qsc/src/interpret.rs we always create a chained simulator that includes a circuit builder, every intrinsic gate call gets added to a running tally of gates performed. Rust has a limit on the capacity of Vec to isize::MAX so if more than that many gates are used the push of the gate after the max triggers a panic. We can work around this temporarily by having the circuit builder stop tracking when hits a hard coded limit, but we should also consider updates to the interpreter behavior (and the corresponding dump_circuit() exposed in Python) to avoid tracing gates for a circuit if not in a debug mode, which should have additional performance benefits.

Here's a playground repro (screenshot below).

Image
@swernli swernli added bug Something isn't working needs triage labels Jan 9, 2025
@minestarks
Copy link
Member

minestarks commented Jan 21, 2025

While this bug does exist, the playground repro provided above is actually a repro of qir-alliance/qir-runner#211

Key differences being:

  • The playground does not initialize the circuit builder.
  • The simulator panic occurs because too many X operations are queued without measurement.

Updated repro for this bug

In VS Code, have a Q# file with this code:

operation Main() : Unit {
    use q = Qubit();
    for _ in 0..2^24 { // decreased from 2^32 
        M(q);
    }
    Reset(q);
}

Invoke "run Q# file" command.

@minestarks
Copy link
Member

minestarks commented Jan 21, 2025

Also... isize::MAX doesn't quite seem to be the limit here - on my machine hit the panic with a 2^24 iterations of that for loop.

Worth mentioning since once the bug is fixed, the original Q# snippet with 2^32 iterations won't actually terminate.

Or it probably will, but I'm not waiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants