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

Avoid lossing precision when scaling frequencies (backport #12392) #12480

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 30, 2024

Summary

Classes in pulse_instruction.py scale frequency values to GHz by multipliying ParameterExpression with float 1e9. This can lead to numerical errors on some systems due to symengine "rounding" errors. Instead, this scaling can be done multiplying by integer 10**9.

Details and comments

In this unit test

def test_parameterized_shift_frequency(self):

The frequency string "f / 1000" gets converted to ParameterExpression(1000000.0*f) after ParameterExpression(f/1000) is multiplied by 1e9. For some unknown reason, when the symbol f is later substituted with the value 3.14, and the RealDouble is converted to float, an error is introduced that can't be fixed by

# Remove truncation error and convert the result into Python builtin type.
# Value could originally contain a rounding error, e.g. 1.00000000001
# which may occur during the parameter expression evaluation.
evaluated = np.round(operand, decimals=decimal).item()

This fixes: #12359 (comment)

Upstream issue: symengine/symengine.py#476


This is an automatic backport of pull request #12392 done by Mergify.

* Avoid lossing precision when scaling frequencies

Classes in pulse_instruction.py scale frequency values to GHz by
multipliying `ParameterExpression` with float 1e9. This can lead
to numerical errors on some systems using symengine. Instead, this
scaling can be done multiplying by integer 10**9.

See: #12359 (comment)

* Add release note

---------

Co-authored-by: Jake Lishman <[email protected]>
(cherry picked from commit 96607f6)
@mergify mergify bot requested a review from a team as a code owner May 30, 2024 11:12
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @nkanazawa1989

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo affects extended support This issue (also) affects extended support labels May 30, 2024
@coveralls
Copy link

coveralls commented May 30, 2024

Pull Request Test Coverage Report for Build 9365718362

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.001%) to 86.95%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 92.88%
Totals Coverage Status
Change from base Build 9314544782: 0.001%
Covered Lines: 75010
Relevant Lines: 86268

💛 - Coveralls

@1ucian0 1ucian0 added this to the 0.46.2 milestone May 30, 2024
@1ucian0 1ucian0 added this pull request to the merge queue May 31, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 31, 2024
@1ucian0 1ucian0 added this pull request to the merge queue Jun 4, 2024
Merged via the queue into stable/0.46 with commit 8db5490 Jun 4, 2024
11 checks passed
@mergify mergify bot deleted the mergify/bp/stable/0.46/pr-12392 branch June 4, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects extended support This issue (also) affects extended support Changelog: Bugfix Include in the "Fixed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants