-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support complex parameters #5192
Conversation
does this also address #5191? |
Yeah, I think so, is that right @eggerdj? You can then do: >> p = Parameter('p')
>>> 1j * p
ParameterExpression(1.0*I*p) |
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.
Thanks @Cryoris for kicking this off. This looks good so far. Some thoughts:
-
IIRC, the initial motivation for
_raise_if_passed_non_real_value
was to ensure all values were real by the time they were sent to the device (so both calculations and inputs were kept real throughout). This is likely not a requirement anymore (and I believe pulse requires complex outputs, @lcapelluto can confirm). Individual instructions can still enforce requirements viavalidate_parameters
as long as it is called at or after binding time. -
This PR introduces complex expressions in three places: as valid binding values, during expression construction, and as resolved output values. Calling these out so they can be sufficiently tested.
-
We should add
ParameterExpression.__complex__
. -
I don't know if we should have a flag for real/complex parameters. There some operations where it would be required, but none are supported at the moment (floor, mod, ordering/comparisons come to mind, maybe there are others?). I looked quickly for sympy's usage of
is_real
, and found a few cases where it is used as an assumption to apply some simplifications (but we in general don't want simplification of expressions). Curious to hear others' thoughts on this.
I think we need a different approach here. Circuit parameters should always be real (they correspond to angles of rotation). But they could be used later in some non-real algebra. e.g. a matrix defining the parameterized gate can have complex entries, or a pulse implementing the parameterized gate can take that real parameter and multiply it by some complex number. However this does not change the fundamental fact that the parameters are real. So can we separate the parameter from what we do to the parameter? We should be able to multiply parameters by complex numbers, but not define complex parameters. |
Is this also true for their usage in pulse ( e.g. #5130 )? |
For pulse, parameters can be real (I hadn't updated my issue lately). As long as I can use the expression
|
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.
Looking good!
Summary
Add support for complex
ParameterExpression
s, closes #5130.Details and comments
This is quite a fundamental change and might require some discussion.
Short demo:
Bound complex rotation angle fails:
Complex parameter bound to complex value:
Open questions
real
flag in the Parameters?