-
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
Name-ordered circuit parameters #5759
Conversation
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.
Haven't had a chance to review the set methods in depth, but looks good so far.
* use deprecate_arguments * add deprecation section in reno * add more tests
dest._update_parameter_table(instr) | ||
if front: | ||
# rebuild parameter table | ||
dest._parameter_table.clear() |
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.
Are parameter tables usually small enough that rebuilding won't be too expensive?
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.
The tables themselves should be reasonably small, maybe a few hundred elements at max right now. But you've got a point, it would be better to avoid iterating over all gates again (including the unparameterized ones) so I changed the logic to make it more efficient and only work on the parameter tables.
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.
Actually it seems we have to rebuild it since instructions are copied and we cannot use the parameter table from the input other
. Maybe @kdk has another idea to make it without rebuild 😄
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.
We do something similar in QuantumCircuit.copy
:
We make the instruction copies ahead of time so that we can build a map from the old to new instances. Then we can use that map to rebuild the parameter table without having to scan and isinstance all the parameters in the circuit. Maybe a similar approach could be useful here.
…-terra into sorted-circuit-parameters
…-terra into sorted-circuit-parameters
Summary
Return the circuit parameters sorted by name and allow binding parameters by list of values. Closes #5557 and #5614.
Details and comments
Details are discussed in https://gist.github.com/Cryoris/1bc894e684f381e07a131196bf86a4da.
In a nutshell:
x[0] x[1] x[2] ... x[10]
and notx[0] x[1] x[10] x[2] ...
)ParameterView
object acts as intermediary object between the current return type, which is a set, and a list-like new return type. It implements all set methods but raises a deprecation warning if any is used.{assign, bind}_parameters
methods accept iterables to bind all parameters at once, additionally to the{param: value}
dictionaries.In future we can remove the
ordered_parameters
property of the n-local circuits and let the variational algorithms use the inherent order of circuits instead of explicitly sorting them by name.