Open alexanderivrii opened 3 weeks ago
One or more of the following people are relevant to this code:
@Qiskit/terra-core
@kevinhartman
@mtreinish
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/accelerate/src/elide_permutations.rs | 68 | 70 | 97.14% | ||
<!-- | Total: | 76 | 78 | 97.44% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/qasm2/src/expr.rs | 1 | 94.02% | ||
crates/accelerate/src/two_qubit_decompose.rs | 1 | 91.45% | ||
crates/qasm2/src/parse.rs | 6 | 96.69% | ||
crates/qasm2/src/lex.rs | 7 | 91.48% | ||
<!-- | Total: | 15 | --> |
Totals | |
---|---|
Change from base Build 11126578403: | -0.006% |
Covered Lines: | 74181 |
Relevant Lines: | 83479 |
Summary
Closes #12336.
This PR reimplements most of the logic of the
ElidePermutations
transpiler pass in Rust (the only thing missing is updating the passmanager's property set to account for the new mapping, this is still done in the Python space).The Rust code also corrects a problem in the Python code where the qubit mapping was not updated correctly in the presence of permutation gates over a subset of qubits -- it's really scary how broken it was and that none of our tests were catching this (and I have added an extra python test that would exhibit the bug).
On one simple test with 100,000 CX-gates and 99,800 SWAP-gates (multiple iterating layers of CX-gates and SWAP-gates), the runtime is improved from
1.388
seconds to0.094
seconds -- about 10x speedup; and on another simple quantum-volume-like test (multiple iterating layers of random unitary and permutation gates) the runtime is improved from0.128
seconds to0.020
seconds -- about 5x speedup.Details and comments
I have needed to expose some of the functionality from
DAGCircuit
, ~First, I needed the pure Rust version of the functioncount_ops()
which I have copied from some other PR, most probably from #13013 (thus it's probably best to wait till this merges and rebase the code on top of it).~ Second, I needed to make some of the functions public, namely: ~push_back
,topological_op_nodes
and~copy_empty_like
. ~Third, I needed the setter variantset_qargs
(and we already hadget_qargs
), and I also addedset_cargs
for consistency.~Thanks to @jakelishman and @Cryoris for help and suggestions!