Skip to content

Fix ParameterExpression.is_real if symengine is installed#8456

Merged
mergify[bot] merged 3 commits into
Qiskit:mainfrom
Cryoris:fix-paramexpr-isreal
Aug 4, 2022
Merged

Fix ParameterExpression.is_real if symengine is installed#8456
mergify[bot] merged 3 commits into
Qiskit:mainfrom
Cryoris:fix-paramexpr-isreal

Conversation

@Cryoris
Copy link
Copy Markdown
Collaborator

@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 Make Mergify open a backport PR to the most recent stable branch on merge. Changelog: Fixed Add a "Fixed" entry in the GitHub Release 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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 added 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: Fixed Add a "Fixed" entry in the GitHub Release changelog. stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants