Avoid lossing precision when scaling frequencies (backport #12392) #12480
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.
Summary
Classes in
pulse_instruction.py
scale frequency values to GHz by multipliyingParameterExpression
with float1e9
. This can lead to numerical errors on some systems due tosymengine
"rounding" errors. Instead, this scaling can be done multiplying by integer10**9
.Details and comments
In this unit test
qiskit/test/python/qobj/test_pulse_converter.py
Line 343 in 235e581
The
frequency
string"f / 1000"
gets converted toParameterExpression(1000000.0*f)
afterParameterExpression(f/1000)
is multiplied by1e9
. For some unknown reason, when the symbolf
is later substituted with the value3.14
, and theRealDouble
is converted tofloat
, an error is introduced that can't be fixed byqiskit/qiskit/pulse/utils.py
Lines 71 to 74 in 235e581
This fixes: #12359 (comment)
Upstream issue: symengine/symengine.py#476
This is an automatic backport of pull request #12392 done by Mergify.