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) (backport #12416) #12477

Closed
wants to merge 1 commit into from

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.
This is an automatic backport of pull request #12416 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 <jake.lishman@ibm.com>
(cherry picked from commit 96607f6)

Co-authored-by: Iyán <me@iyanmv.com>
(cherry picked from commit 0a05ea2)
@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

Pull Request Test Coverage Report for Build 9299004553

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 13 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.08%) to 86.945%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 6 92.11%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9162412942: 0.08%
Covered Lines: 75006
Relevant Lines: 86268

💛 - Coveralls

@1ucian0
Copy link
Member

1ucian0 commented May 30, 2024

closing in favor of #12480

@1ucian0 1ucian0 closed this May 30, 2024
@mergify mergify bot deleted the mergify/bp/stable/0.46/pr-12416 branch May 30, 2024 11:17
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.

3 participants