fix(quilatom): format complex params with nonzero real and unit imaginary part#1850
Open
devteamaegis wants to merge 1 commit into
Open
fix(quilatom): format complex params with nonzero real and unit imaginary part#1850devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
…real and unit imaginary part format_parameter raised ValueError on complex values like 2+1j (real part nonzero, imaginary part exactly +/-1), e.g. when serializing Kraus operator entries into PRAGMA ADD-KRAUS via _create_kraus_pragmas. Emit <real>+i / <real>-i instead of raising, matching the existing format for other complex values.
5f24a34 to
fc86cbf
Compare
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.
What's broken
format_parameterraisesValueErroron a complex number whose imaginary part is exactly+1/-1while the real part is nonzero (e.g.2+1j). It's reachable through the non-deprecated noise path_create_kraus_pragmas, which serializes Kraus-operator entries into aPRAGMA ADD-KRAUSstring — and Kraus operators commonly have entries like2+1j:Why it happens
The
i == 1/i == -1branches assumed the real part must be ~0 and raised otherwise. Thenp.isclose(r, 0)check is only meant to drop tiny floating residuals; when the real part is genuinely nonzero it should append+i/-ito the real part, like every other complex value.Fix
When the real part is nonzero, append
+i/-iinstead of raising. Output round-trips through pyQuil's own parser (2.0+i).Test
Extended
test_format_parameterwith2+1j,2-1j,-3+1j; the existing1e-15±1j → ±"i"cases still pass, andtest_noise.py(the Kraus path) stays green.