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

Fix ParameterExpression.is_real if symengine is installed #8456

Merged
merged 3 commits into from
Aug 4, 2022

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Aug 4, 2022

Summary

Fixes #8417.

Details and comments

This PR works around a case in symengine where an expression is not identified as real or imaginary if it is multiplied by a constant. This led to the unexpected behavior in Qiskit that e.g. 2 * I was not being identified as imaginary:

from qiskit.circuit import Parameter
x = Parameter("x")
expr = 1j * x
bound = expr.bind({x: 2})
print(bound.is_real())  # used to be True, but is now False

@Cryoris Cryoris added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Aug 4, 2022
@Cryoris Cryoris requested a review from a team as a code owner August 4, 2022 16:47
@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

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this seems reasonable to fix the bug while we wait for symengine. Hopefully they fix it soon and we can remove the extra eval call.

@coveralls
Copy link

coveralls commented Aug 4, 2022

Pull Request Test Coverage Report for Build 2799810266

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 84.037%

Totals Coverage Status
Change from base Build 2799807450: 0.004%
Covered Lines: 56089
Relevant Lines: 66743

💛 - Coveralls

@mergify mergify bot merged commit 2bab09c into Qiskit:main Aug 4, 2022
mergify bot pushed a commit that referenced this pull request Aug 4, 2022
)

* Fix is_real on ParameterExpression

* typo in reno

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2bab09c)
@Cryoris Cryoris deleted the fix-paramexpr-isreal branch August 5, 2022 08:25
mergify bot added a commit that referenced this pull request Aug 5, 2022
) (#8462)

* Fix is_real on ParameterExpression

* typo in reno

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2bab09c)

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParameterExpression.is_real() inconsistent between Linux/MacOS and Windows
4 participants