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

Fully port FilterOpNodes to Rust #13052

Merged
merged 5 commits into from
Sep 5, 2024

Conversation

mtreinish
Copy link
Member

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

@mtreinish mtreinish added performance Rust This PR or issue is related to Rust code in the repository mod: transpiler Issues and PRs related to Transpiler labels Aug 28, 2024
@mtreinish mtreinish added this to the 1.3 beta milestone Aug 28, 2024
@mtreinish mtreinish requested a review from a team as a code owner August 28, 2024 22:08
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

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.

Fixes Qiskit#12263
Part of Qiskit#12208
@mtreinish mtreinish force-pushed the rust-filter-op-nodes branch from 2f737bd to 081c4bc Compare August 28, 2024 22:32
@coveralls
Copy link

coveralls commented Aug 28, 2024

Pull Request Test Coverage Report for Build 10728702589

Details

  • 30 of 60 (50.0%) changed or added relevant lines in 7 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 89.125%

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%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.73%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 10725151093: -0.03%
Covered Lines: 72623
Relevant Lines: 81484

💛 - Coveralls

Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few minor comments.

crates/circuit/src/dag_circuit.rs Outdated Show resolved Hide resolved
crates/accelerate/src/filter_op_nodes.rs Outdated Show resolved Hide resolved
crates/circuit/src/dag_circuit.rs Outdated Show resolved Hide resolved
The filter_op_nodes() method originally returned a Result<()> to handle
a predicate that was fallible. This was because the original intent for
the method was to use it with Python callbacks in the predicate. But
because of differences between the rust API and the Python API this
wasn't feasible as was originally planned. So this Result<()> return
wasn't used anymore. This commit reworks it to make the
filter_op_nodes() infallible and the predicate a user provides also only
returns `bool` and not `Result<bool>`.
@kevinhartman kevinhartman self-assigned this Sep 4, 2024
Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for the changes!

@kevinhartman kevinhartman added this pull request to the merge queue Sep 5, 2024
Merged via the queue into Qiskit:main with commit 8982dbd Sep 5, 2024
15 checks passed
@mtreinish mtreinish deleted the rust-filter-op-nodes branch September 5, 2024 23:52
@raynelfss raynelfss added the Changelog: None Do not include in changelog label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: transpiler Issues and PRs related to Transpiler performance Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port FilterOpNodes to Rust
6 participants