-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix sympify() for expressions with vector element .subs() #14641
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit fixes an issue in the .sympify() method when building the Sympy expression for a `ParameterExpression` that was constructed by calling `ParameterExpression.subs()` with a ParameterVectorElement type. The previous implementation of this method was passing the symbols for substitution by string which required sympy to "parse" the input. The square brackets for indexing the vector element in it's string representation was not valid for sympy to parse and this caused the error. To avoid this problem this commit adjusts the usage to pass a sypy expression object instead of a string. This is the intent of the function as string parsing has other issues in sympy and this was an oversight in the implementation that was doing this. By passing a sympy object to sympy it is able to handle the vector's name with square brackets. Fixes Qiskit#14640
One or more of the following people are relevant to this code:
|
jakelishman
approved these changes
Jun 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed it works fine in 2.0.3, so no release note needed because the bug isn't released.
Pull Request Test Coverage Report for Build 15738926859Details
💛 - Coveralls |
joshuasn
approved these changes
Jun 18, 2025
mergify bot
pushed a commit
that referenced
this pull request
Jun 18, 2025
This commit fixes an issue in the .sympify() method when building the Sympy expression for a `ParameterExpression` that was constructed by calling `ParameterExpression.subs()` with a ParameterVectorElement type. The previous implementation of this method was passing the symbols for substitution by string which required sympy to "parse" the input. The square brackets for indexing the vector element in it's string representation was not valid for sympy to parse and this caused the error. To avoid this problem this commit adjusts the usage to pass a sypy expression object instead of a string. This is the intent of the function as string parsing has other issues in sympy and this was an oversight in the implementation that was doing this. By passing a sympy object to sympy it is able to handle the vector's name with square brackets. Fixes #14640 (cherry picked from commit 69d7dbd)
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jun 18, 2025
…14642) This commit fixes an issue in the .sympify() method when building the Sympy expression for a `ParameterExpression` that was constructed by calling `ParameterExpression.subs()` with a ParameterVectorElement type. The previous implementation of this method was passing the symbols for substitution by string which required sympy to "parse" the input. The square brackets for indexing the vector element in it's string representation was not valid for sympy to parse and this caused the error. To avoid this problem this commit adjusts the usage to pass a sypy expression object instead of a string. This is the intent of the function as string parsing has other issues in sympy and this was an oversight in the implementation that was doing this. By passing a sympy object to sympy it is able to handle the vector's name with square brackets. Fixes #14640 (cherry picked from commit 69d7dbd) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
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
priority: high
stable backport potential
The bug might be minimal and/or import enough to be port to stable
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This commit fixes an issue in the .sympify() method when building the Sympy expression for a
ParameterExpression
that was constructed by callingParameterExpression.subs()
with a ParameterVectorElement type. The previous implementation of this method was passing the symbols for substitution by string which required sympy to "parse" the input. The square brackets for indexing the vector element in it's string representation was not valid for sympy to parse and this caused the error. To avoid this problem this commit adjusts the usage to pass a sypy expression object instead of a string. This is the intent of the function as string parsing has other issues in sympy and this was an oversight in the implementation that was doing this. By passing a sympy object to sympy it is able to handle the vector's name with square brackets.Details and comments
Fixes #14640