fix: expand user-defined QASM gates inline to prevent simulator panic#33
Merged
fix: expand user-defined QASM gates inline to prevent simulator panic#33
Conversation
Custom gate definitions (e.g. `gate oracle q0, q1 { ... }`) were stored
but never expanded. When invoked, they became opaqueGate objects with
nil Matrix(), causing the statevector simulator to panic on nil slice
indexing. This crashed the WASM instance, producing "undefined is not
valid JSON" on first run and "Go program has already exited" on retry.
Parser: add expandGateCall() that re-parses gate body tokens with qubit
and parameter substitution, inlining the operations. Empty gate bodies
correctly become no-ops (identity).
Simulator: add nil-matrix safety checks in Apply, applyOp, and all
dispatch fallback paths to prevent panics from any remaining opaque
gates (e.g. user-defined gates called with modifiers).
|
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (48.14%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
- Coverage 71.43% 71.34% -0.10%
==========================================
Files 165 165
Lines 17491 17543 +52
==========================================
+ Hits 12495 12516 +21
- Misses 4040 4062 +22
- Partials 956 965 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Custom gate definitions (e.g.
gate oracle q0, q1 { ... }) were stored but never expanded. When invoked, they became opaqueGate objects with nil Matrix(), causing the statevector simulator to panic on nil slice indexing. This crashed the WASM instance, producing "undefined is not valid JSON" on first run and "Go program has already exited" on retry.Parser: add expandGateCall() that re-parses gate body tokens with qubit and parameter substitution, inlining the operations. Empty gate bodies correctly become no-ops (identity).
Simulator: add nil-matrix safety checks in Apply, applyOp, and all dispatch fallback paths to prevent panics from any remaining opaque gates (e.g. user-defined gates called with modifiers).