-
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
Port synth_clifford_greedy
to Rust
#12601
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 9564063418Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9567144979Details
💛 - Coveralls |
…rices by significantly cheaper in-place prepend operations
Pull Request Test Coverage Report for Build 9577770854Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9641284102Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9722822853Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9725700405Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9725842348Details
💛 - Coveralls |
This is ready for review (@ShellyGarion, @Cryoris). All suggestions to make the code even faster or more "rusty" are highly welcome. |
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 code looks great! My main comment is that we should think a little bit on the API, since it will be used for other Clifford synthesis methods as well as to port the Clifford class to rust later (#12367)
struct Clifford { | ||
/// Number of qubits. | ||
num_qubits: usize, | ||
/// Matrix with dimensions (2 * num_qubits) x (2 * num_qubits + 1). |
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.
what's the reason to have the phases as the last line of the matrix and not as a separate vector (unlike the current Clifford class)? will it be useful later?
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.
Hmm, this is an interesting suggestion, which has its pros and cons. The current form is consistent with how we store a Clifford tableau in Python, but we can change it of course. It is also easier to perform row operations directly on the (2n) x (2n+1) matrix.
releasenotes/notes/oxidize-synth-clifford-greedy-0739e9688bc4eedd.yaml
Outdated
Show resolved
Hide resolved
Pull Request Test Coverage Report for Build 9741012360Details
💛 - 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 except a minor comment.
The implementation and correctness of the algorithm look good to me.
I would be happy if someone could also look into the rust implementation aspects.
Pull Request Test Coverage Report for Build 9741620005Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9743540137Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
* starting to experiment * porting code * messy code porting * printing statements to enable debugging * fixes * fixing phase * removing some of the printing statements * fixing inaccuracy for cost computation * Moving some of the functionality to SymplecticMatrix class * reducing the number of warnings * formatting * replacing expensive adjoint and compose operations for symplectic matrices by significantly cheaper in-place prepend operations * resolving merge conflicts * cleanup * code cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * using fast lookup * cleanup * clippy * including params in gate_seq to avoid mapping * removing unnecessary inner function * cleanup * renaming * changes on the python side * reno * adding error handling * improved error handling * removing redundant Ok(Some(...)) * using random_clifford in tests * reorganizing clifford code * fixes * formatting * improved error handling * do not panic * formatting * Applying refactoring suggestions d/utils.rs from code review * release notes update * adding comment
Summary
Addresses #12235.
This PR ports the method
synth_clifford_greedy
for synthesizingClifford
operators to Rust. In the process the algorithm was additionally improved by (1) ignoring all (expensive!) clifford phase computations till the very end, thus working on the "symplectic matrix" part of the tableau, (2) completely avoiding (expensive!) cliffordevolve
and cliffordadjoint
operations by pre-composing rather than post-composing the current Clifford with elementary Cliffords (corresponding to CX, SWAP, S, and H gates), (3) almost completely avoiding copying clifford objects, (4) fixing an inefficiency in cost computations.Runtime improvements:
On my laptop, the old python code takes about 400 seconds to synthesize 50 random 50-qubit Cliffords, and the new code takes 0.25 seconds to do the same. So it's at least 1000x improvement in performance.
Quality improvements:
After fixing an inaccuracy in cost computations, the number of SWAPs introduced by the new algorithm is smaller than before; the totals for the 50 random cliffords from before are: