-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…10268) * Improve casting and error message for `ParameterExpression` Previously, we assumed that the only reason a cast of `ParameterExpression` to `complex`/`float`/`int` could fail was because of unbound parameters, and emitted an error accordingly. This is not the case; a fully bound complex value will still fail to convert to `float`. This PR improves the error messages in these cases, and works around a difference of Sympy and Symengine, where the latter will fail to convert real-valued expressions that were symbollically complex at some point in their binding history to `float`. Sympy more reliably reduces values down to real-only values when the imaginary part is exactly cancelled, which is a use-case our users tend to expect. * Fix typo in test * Update releasenotes/notes/parameter-float-cast-48f3731fec5e47cd.yaml --------- Co-authored-by: Jake Lishman <[email protected]> Co-authored-by: Kevin Hartman <[email protected]>
- Loading branch information
1 parent
e781147
commit 31f26d2
Showing
4 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
13 changes: 13 additions & 0 deletions
13
releasenotes/notes/parameter-float-cast-48f3731fec5e47cd.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
fixes: | ||
- | | ||
Improved the error messages returned when an attempt to convert a fully bound | ||
:class:`.ParameterExpression` into a concrete ``float`` or ``int`` failed, for example because | ||
the expression was naturally a complex number. | ||
- | | ||
Fixed ``float`` conversions for :class:`.ParameterExpression` values which had, at some point in | ||
their construction history, an imaginary component that had subsequently been cancelled. When | ||
using Sympy as a backend, these conversions would usually already have worked. When using | ||
Symengine as the backend, these conversions would often fail with type errors, despite the | ||
result having been symbolically evaluated to be real, and :meth:`.ParameterExpression.is_real` | ||
being true. |
This file contains 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