Fix bug in exp_pauli qubit concatenation#4064
Merged
sacpis merged 2 commits intoNVIDIA:mainfrom Mar 2, 2026
Merged
Conversation
In `PyKernel.exp_pauli()`, the `+` operator binds tighter than the ternary `if/else`, causing `qubitsList` to be silently dropped when `quantumVal` is not None. Add parentheses to ensure individual qubits are always concatenated with the register. Signed-off-by: huaweil <huaweil@nvidia.com>
f62bfef to
784b17f
Compare
sacpis
approved these changes
Mar 2, 2026
Collaborator
sacpis
left a comment
There was a problem hiding this comment.
LGTM. Thansk @huaweil-nv.
Collaborator
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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.
Description
Fix a Python operator precedence bug in PyKernel.exp_pauli() where individual qubits (RefType) are silently dropped when a quantum register (VeqType) is also provided.
The + operator has higher precedence than the ternary if/else expression in Python, so:
is parsed as:
This means when quantumVal is not None, the result is [quantumVal] alone — qubitsList is discarded entirely. The fix adds parentheses to ensure qubitsList is always concatenated:
How to reproduce:
Before fix: The generated IR shows q_extra allocated but never used. exp_pauli operates on veq<2> (2 qubits) despite the 3-qubit Pauli word "XXX":
After fix: quake.concat correctly merges the register and the individual qubit into veq<3>: