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) #12416

Merged
merged 1 commit into from
May 16, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 16, 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 <jake.lishman@ibm.com>
(cherry picked from commit 96607f6)
@mergify mergify bot requested a review from a team as a code owner May 16, 2024 08:40
@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 the following people are requested to review this:

  • @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 labels May 16, 2024
@github-actions github-actions bot added this to the 1.1.0 milestone May 16, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9109206127

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 22 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.02%) to 89.596%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.86%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 9101517319: -0.02%
Covered Lines: 62238
Relevant Lines: 69465

💛 - Coveralls

@jakelishman jakelishman added this pull request to the merge queue May 16, 2024
Merged via the queue into stable/1.1 with commit 0a05ea2 May 16, 2024
18 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.1/pr-12392 branch May 16, 2024 10:19
@1ucian0
Copy link
Member

1ucian0 commented May 30, 2024

@Mergifyio backport stable/0.46

@1ucian0 1ucian0 added the affects extended support This issue (also) affects extended support label May 30, 2024
Copy link
Contributor Author

mergify bot commented May 30, 2024

backport stable/0.46

✅ Backports have been created

mergify bot added a commit that referenced this pull request May 30, 2024
* 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)
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.

None yet

5 participants