-
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
Use ParameterReferences
type for ParameterTable
values
#7408
Conversation
Tagging @jakelishman esp. for Python best practice insights :) |
Pull Request Test Coverage Report for Build 2468737188
💛 - 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.
This looks pretty sensible, and looks like it should reduce a potential quadratic complexity in circuit depth when using parameters. Do you have benchmarks for improvement for it to hand?
I don't! I should have some time to get some numbers in the coming week, and will report back. |
@jakelishman, I found at least one place that depends on I'm not really sure if there's a good way to do this if Any ideas on how we should proceed? |
Here are the
|
Is there an asv test for a large number of gates with a large number of parameters? |
@ewinston: Yeah, the same benchmark suite Kevin showed goes up to 131,072 gates x 131,072 parameters, but I'm guessing he just didn't show them here because there wasn't much change (and in total there's ~36 benchmarks in that suite). |
@kevinhartman: sorry, I haven't had chance to look properly, but I feel like that code block there is logically just trying to match up the instructions between circuits, including from a main circuit. I think it might be possible to modify the algorithm in that location a little such that it iterates over a index into the (I get that my proposed solution uses the total ordering of |
Hmm, alright! That's helpful. I'll give it a try.
I agree completely that it'd be nice to eliminate maintaining an arbitrary ordering of parameter references, at the very least. |
Previously, ParameterReferences implemented both Set and MutableSequence. Now, it implements MutableSet, only. Existing seq-like usages throughout Terra have been eliminated.
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.
Overall this looks solid, and the benchmarks you've got above look absolutely 🔥. I have a point worrying about pickle (using id
as a key is basically encoding dangling-pointer risks as a feature, so we need to be very careful), and I think some of the tests still assume the ordered behaviour from a previous iteration of this PR.
Don't forget the release note - we like to trumpet our speed-ups!
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.
Looks good to me, and the speed-ups are great! Thanks!
Summary
Changes
ParameterTable
value type fromList[(Instruction, int)]
to a new collection type,ParameterReferences
, which is set-like, and no longer seq-like.ParameterReferences
:Details and comments
It's not actually necessary to update existing uses of
ParameterTable
or its values, but usage is updated inQuantumCircuit
for performance (mostly to avoid creating lists that are then immediately spooled intoParameterReferences
). SeeParameterReferences
docstring for more information.Fixes #6725.
ParameterReferences
is set-like, so there's no need to perform a linear search in_update_parameter_table
to check existing references for every instruction parameter.