Improve commutation checking of Pauli product rotations and measurements#15815
Open
alexanderivrii wants to merge 5 commits intoQiskit:mainfrom
Open
Improve commutation checking of Pauli product rotations and measurements#15815alexanderivrii wants to merge 5 commits intoQiskit:mainfrom
alexanderivrii wants to merge 5 commits intoQiskit:mainfrom
Conversation
For pairs of PPRs/PPMs we can construct generators as Paulis rather than SparseObservables, and we can check commutativity by checking the commutativity of Paulis.
Collaborator
|
One or more of the following people are relevant to this code:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR improves commutation checking of pairs of Pauli-based objects, that is of
PauliProductRotationGateandPauliProductMeasurement. Without this PR, we construct the generators for operations for PPRs and PPMs asSparseObservables and then check if the twoSparseObservables commute. With this PR, we first instead construct the generatoors as Paulis (represented using Z and X components) and check if two Paulis commute. The latter check is quite a bit faster than the former for large gates.Based on top of #15810.
Details and comments
I run this on the 100 representative HamLib benchmarks from
benchpressusing the following scriptHere is the plot showing improvement in runtime (where commutation checker is used within
CommutativeOptimization) .Note that
CommutativeOptimizationdoes not actually improve the quality of any of these HamLib benchmarks, however it tends to make a huge number of commutativity checks.Here is an additional experiment is in the spirit of our FT compiler pipeline (in which case
CommutativeOptimizationcan remove/merge many gates).Without this PR, the average time for
CommutativeOptimizationis3.46seconds, with this PR it's0.29.LLM tools used
Used copilot to suggest various micro-optimization and alternative implementations, but in the end the implementation and all possible bugs are purely mine.
Additional potential optimization
If we could assume that the
qargsforPauliProductRotationGateandPauliProductMeasurementgate are always sorted by qubit index, we could optimize the implementation even more by replacingin_q1by the standard intersection method for two sorted vectors. In theory, we could add an extra pass that sorts PPR and PPM instructions in this way.