-
Notifications
You must be signed in to change notification settings - Fork 615
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
Speed up GroverOperator
and add GlobalPhase to its decomposition
#4666
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4666 +/- ##
==========================================
- Coverage 99.65% 99.64% -0.01%
==========================================
Files 383 383
Lines 34559 34311 -248
==========================================
- Hits 34439 34190 -249
- Misses 120 121 +1 ☔ View full report in Codecov by Sentry. |
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.
You may need to tweak "use matrix versus decomposition" threshold in default qubit as well.
It is currently located here:
if op.name == "GroverOperator" and len(op.wires) >= 13: |
But I have an open PR that will be moving it. We can resolve that merge conflict when we get to it.
Good call. I actually removed it now, because it is supposed to address the large wire counts, which is the regime where the dispatched
👍 |
Updated timings for all interfaces (line style gives interface, color gives target wires): As there is an outlier in Tensorflow which leads to |
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.
pretty much good to go, just a few questions
Co-authored-by: Matthew Silverman <[email protected]>
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.
great optimization, thanks for putting this all together! 🎉
**Context:** GlobalPhase is a relatively new operator, and some plugins may not be able to handle it. To be consistent with the pre-GlobalPhase days, I'm making it decompose to nothing so devices will decompose it and make it disappear. **Description of the Change:** Implement `GlobalPhase.compute_decomposition` so it decomposes to nothing **Benefits:** Plugins won't break if they see it. It does have a matrix defined, but maybe some plugins need a whitelist of operators. **Possible Drawbacks:** Maybe plugins should fail if they see it, and maybe that's what we wanted? **Related GitHub Issues:** Good to merge with/before #4666 [sc-50428] --------- Co-authored-by: Tom Bromley <[email protected]> Co-authored-by: Christina Lee <[email protected]>
Context:
GroverOperator
is applied byDefaultQubit
by applying its matrix for up to 12 wires (incl).However,
GroverOperator
has a lot of structure as it is2*P-1
for a projectorP
, and a custom application rule is faster than constructing and applying the matrix.compute_matrix
method ofGroverOperator
in addition uses a rather contrived way to construct the matrixnp.full((dim, dim), normalization_constant)
. Instead, we can simply use the broadcasting behaviour of numpy and donormalization_constant - np.eye(dim)
(timings below).GroverOperator
decomposition is only correct up to a minus sign (or phase ofDescription of the Change:
apply_operation
in/qubit/apply_operation.py
forGroverOperator
that is not based on the matrix representation ofGroverOperator
.compute_matrix
method ofGroverOperator
to skip repetitive calling ofnp.kron
andnp.outer
to construct a trivial matrix.GlobalPhase($\pi$)
gate in the decomposition.Benefits:
Speedups and correct decomposition.
Possible Drawbacks:
N/A
Related GitHub Issues:
Timing code for the matrix construction:
Timings for the different
apply_operation
options, for three scenarios: Number of wires for operation and state is equal, number of wires for state is that for operation +4, and number of wires for state is double of that for operation.Given the results, we could do einsum for
len(op.wires)<8
and the dispatch method for bigger wire counts.