Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.1k stars 2.34k forks source link

Port `ElidePermutations` transpiler pass to Rust #13094

Open alexanderivrii opened 3 weeks ago

alexanderivrii commented 3 weeks ago

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 to 0.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 from 0.128 seconds to 0.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 function count_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 variant set_qargs (and we already had get_qargs), and I also added set_cargs for consistency.~

Thanks to @jakelishman and @Cryoris for help and suggestions!

qiskit-bot commented 3 weeks ago

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

coveralls commented 3 weeks ago

Pull Request Test Coverage Report for Build 11128563326

Details


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 Coverage Status
Change from base Build 11126578403: -0.006%
Covered Lines: 74181
Relevant Lines: 83479

💛 - Coveralls