-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add fast path to Parameter.assign
#10549
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
Conversation
This specialises `Parameter.assign` to more efficiently handle parameter assignment via `QuantumCircuit.assign_parameters`. The assignment can either be of `self`, and therefore should just return the value lifted to a `ParameterExpression`, or it's not of `self`, in which case we need to raise an error to match the superclass implementation. The overhead of all the checks that go on during the regular `ParameterExpression.assign` (delegating to `subs` or `bind`) are a sizeable chunk of the cost of assignment in PEC-style circuits.
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 5742085677
💛 - Coveralls |
# This is the `super().bind` case, where we're required to return a `ParameterExpression`, | ||
# so we need to lift the given value to a symbolic 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.
Why do we need to lift the value to a symbolic expression? In the final circuit keeping only the float would be even better than having the parameter expression, but I expect there's some type requirement I'm missing...
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.
In this PR at least, because that would be a different logical change. I think there's a few issues discussing your topic elsewhere on the Terra repo, though.
Pull Request Test Coverage Report for Build 6036367887
💛 - Coveralls |
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.
LGTM
Summary
This specialises
Parameter.assign
to more efficiently handle parameter assignment viaQuantumCircuit.assign_parameters
. The assignment can either be ofself
, and therefore should just return the value lifted to aParameterExpression
, or it's not ofself
, in which case we need to raise an error to match the superclass implementation.The overhead of all the checks that go on during the regular
ParameterExpression.assign
(delegating tosubs
orbind
) are a sizeable chunk of the cost of assignment in PEC-style circuits.Details and comments
For the example in #10548 (and building on that branch), this PR takes the runtime from 3.51(6)s down to 2.66(2)s, which is better than the looped private-method performance of Terra 0.24.2.
For the case of inplace binding the whole set of parameters in one go, given in array form, this takes the runtime down from 2.86(2)s down to 1.79(2)s.
cc: @chriseclectic (again).