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.28k stars 2.37k forks source link

Fully port FilterOpNodes to Rust #13052

Closed mtreinish closed 2 months ago

mtreinish commented 2 months ago

Summary

This commit ports the FilterOpNodes pass to rust. This pass is exceedingly simple and just runs a filter function over all the op nodes and removes nodes that match the filter. However, the API for the class exposes that filter function interface as a user provided Python callable. So for the current pass we need to retain that python callback. This limits the absolute performance of this pass because we're bottlenecked by calling python.

Looking to the future, this commit adds a rust native method to DAGCircuit to perform this filtering with a rust predicate FnMut. It isn't leveraged by the python implementation because of layer mismatch for the efficient rust interface and Python working with DAGOpNode objects. A function using that interface is added to filter labeled nodes. In the preset pass manager we only use FilterOpNodes to remove nodes with a specific label (which is used to identify temporary barriers created by qiskit). In a follow up we should consider leveraging this new function to build a new pass specifically for this use case.

Details and comments

Fixes #12263 Part of #12208

qiskit-bot commented 2 months ago

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

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10728702589

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/remove_diagonal_gates_before_measure.rs 1 2 50.0%
crates/circuit/src/packed_instruction.rs 0 5 0.0%
crates/accelerate/src/filter_op_nodes.rs 25 34 73.53%
crates/circuit/src/dag_circuit.rs 0 15 0.0%
<!-- Total: 30 60 50.0% -->
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.73%
crates/qasm2/src/parse.rs 6 97.61%
<!-- Total: 10 -->
Totals Coverage Status
Change from base Build 10725151093: -0.03%
Covered Lines: 72623
Relevant Lines: 81484

💛 - Coveralls