Move QuantumCircuit.assign_parameters
to Rust (backport #12794)
#12878
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is (as far as I could tell), the last really major performance regression in our asv suite compared to 1.1.0, so with this commit, we should be at not worse for important utility-scale benchmarks.
This largely rewrites
ParamTable
(renamed back toParameterTable
because I kept getting confused withParam
) to have more Rust-friendly interfaces available, so thatassign_parameters
can then use them.This represents a 2-3x speedup in
assign_parameters
performance over 1.1.0, when binding simpleParameter
instances. Approximately 75% of the time is now spent in Python-spaceParameter.assign
andParameterExpression.numeric
calls; almost all of this could be removed were we to moveParameter
andParameterExpression
to have their data exposed directly to Rust space. The percentage of time spent in Python space only increases if the expressions to be bound are actualParameterExpression
s and not justParameter
.Most changes in the test suite are because of the use of internal-only methods that changed with the new
ParameterTable
. The only discrepancy is a bug intest_pauli_feature_map
, which was trying to assign using a set.Details and comments
Built on #12730, so will need rebasing over it.
I think this first commit might accidentally have introduced a small (10%) regression to parametric-circuit construction time over its parent. That's a mistake if so - I should be able to fix that later.edit: on retiming, I couldn't reproduce a problem - if anything, this commit is a minor improvement.Timings for parametric circuit benchmarks compared to 1.1.0 (the different SHA1 is because I hadn't written the commit message when I took the benchmark):