Skip to content
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

'Peephole' optimization - or: collecting and optimizing two-qubit blocks - before routing #12727

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

sbrandhsn
Copy link
Contributor

Summary

Fixes #12562

Details and comments

This PR collects and consolidates two-qubit gates into blocks before routing. Each block is then subsequently analysed to determine whether the two-qubit unitary representing the block equals the identity or is a product of single-qubit gates. In the former case, the gates in the block are removed and in the latter case the block is replaced by single-qubit gates correspondingly.

Points up for debate:

  • Do we want to run the new pass Split2QUnitaries as part of ConsolidatedBlocks?
  • Do the passes for gate direction checks and fixes always play nicely with having two-qubit unitaries before routing? There were no test failures but I'm still wondering.
  • Is the current path of checking for the two-qubit unitaries for being a product of single-qubit unitaries the fastest or should we rely on Weyl-decomposition? If the former is true, we should probably port the corresponding functions to rust as they will touch a lot of two-qubit unitaries. :-)

@sbrandhsn sbrandhsn requested a review from a team as a code owner July 5, 2024 18:53
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Jul 5, 2024

Pull Request Test Coverage Report for Build 9812549561

Details

  • 45 of 45 (100.0%) changed or added relevant lines in 3 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 89.843%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 6 91.6%
Totals Coverage Status
Change from base Build 9807934619: 0.02%
Covered Lines: 65234
Relevant Lines: 72609

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jul 8, 2024

Pull Request Test Coverage Report for Build 9842951029

Warning: 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

  • 45 of 45 (100.0%) changed or added relevant lines in 3 files are covered.
  • 19 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.04%) to 89.861%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 92.62%
qiskit/circuit/library/standard_gates/x.py 1 98.01%
crates/circuit/src/slice.rs 17 83.85%
Totals Coverage Status
Change from base Build 9807934619: 0.04%
Covered Lines: 65268
Relevant Lines: 72632

💛 - Coveralls

mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Jul 8, 2024
This commit migrates the two functions in the private module
`qiskit.synthesis.two_qubit.local_invariance` to primarily be
implemented in rust. Since the two_qubit_local_invariants() function is
being used in Qiskit#12727 premptively porting these functions to rust will
both potentially speed up the new transpiler pass in that PR and also
facilitate a future porting of that pass to rust. The two python space
functions continue to exist as a small wrapper to do input type
checking/conversion and rounding of the result (since the python API for
rounding is simpler). There is no release note included for these
functions as they are internal utilities in Qiskit and not exposed as a
public interface.
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Jul 8, 2024
This commit migrates the two functions in the private module
`qiskit.synthesis.two_qubit.local_invariance` to primarily be
implemented in rust. Since the two_qubit_local_invariants() function is
being used in Qiskit#12727 premptively porting these functions to rust will
both potentially speed up the new transpiler pass in that PR and also
facilitate a future porting of that pass to rust. The two python space
functions continue to exist as a small wrapper to do input type
checking/conversion and rounding of the result (since the python API for
rounding is simpler). There is no release note included for these
functions as they are internal utilities in Qiskit and not exposed as a
public interface.
@mtreinish
Copy link
Member

Is the current path of checking for the two-qubit unitaries for being a product of single-qubit unitaries the fastest or should we rely on Weyl-decomposition? If the former is true, we should probably port the corresponding functions to rust as they will touch a lot of two-qubit unitaries. :-)

I took care of this in: #12739 since it was very simple. From a complexity PoV I would expect the local_invariants() function to be much faster since it's far less complex the the TwoQubitWeylDecomposition class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply Peephole Optimization Before Routing
4 participants