qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Parameterize Commutation Checker

Open MarcDrudis opened this issue 1 year ago • 2 comments

Summary

Add support for basic parameterized gates in the commutation checker (props to @Cryoris). This is currently only done for rotation gates that have a single generator (e.g. done for RXX but not for XXPlusYY). This has the power to improve compiler quality, but also speeds up the CommutationChecker in cases where we have to check if gates are parameterized a lot.

Details and Comments

This works by replacing a parameterized gate by it's generator. For example, RZ(theta) commutes with a gate exactly if Z commutes with that gate. The special cases of theta mod 2pi = 0 are also handled. For compiling a 100-qubit QFT circuit (which has loads of CPhase gates), the runtime on my laptop was reduced as:

(main) Took 2.1887816429138183 +- 0.3050131081682874s
(this PR) Took 1.8230558633804321 +- 0.19875805494141444s

which is more than I expected given the small substitution.

MarcDrudis avatar Oct 09 '24 14:10 MarcDrudis

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

qiskit-bot avatar Oct 09 '24 14:10 qiskit-bot

Pull Request Test Coverage Report for Build 11594925663

Details

  • 63 of 64 (98.44%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.03%) to 88.726%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/commutation_checker.rs 62 63 98.41%
<!-- Total: 63 64
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 92.09%
crates/accelerate/src/commutation_checker.rs 1 97.09%
crates/qasm2/src/lex.rs 5 92.23%
<!-- Total: 7
Totals Coverage Status
Change from base Build 11592501902: 0.03%
Covered Lines: 75579
Relevant Lines: 85182

💛 - Coveralls

coveralls avatar Oct 09 '24 14:10 coveralls

I ran the utility scale benchmarks in test/benchmarks and this improves the performance for the QFT benchmarks by ~22% leaving the others unchanged. The depths also don't change so this is consistent with the current behavior.

Average over 10 runs with CX as basis gate
main:
-- Times:
QFT: 1.3684054851531982 +- 0.024621658803924102
Heisen: 0.19565179347991943 +- 0.014674726792643892
QAOA: 0.5207660913467407 +- 0.021566247367379065
QV: 1.3223005056381225 +- 0.021189671640295876
SU2: 3.677972507476807 +- 0.031693344070161326
BV: 0.1491406202316284 +- 0.011247038996003447
BV-like: 0.006857585906982422 +- 0.00033202630149019145
Total: 7.241094589233399

-- Depths:
QFT: 1954
Heisen: 462
QAOA: 1607
QV: 2709
SU2: 300
BV: 395
BV-like: 0

this PR:
-- Times:
QFT: 1.0807523250579834 +- 0.01748851782021482
Heisen: 0.19395751953125 +- 0.015540161362770638
QAOA: 0.4986311912536621 +- 0.017146640364266583
QV: 1.313275194168091 +- 0.014704899418210503
SU2: 3.694802403450012 +- 0.028206125743678666
BV: 0.1501666784286499 +- 0.009483460690998797
BV-like: 0.007105302810668945 +- 0.0003282014217839353
Total: 6.938690614700318

-- Depths:
QFT: 1954
Heisen: 462
QAOA: 1607
QV: 2709
SU2: 300
BV: 395
BV-like: 0

Cryoris avatar Oct 30 '24 09:10 Cryoris