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

Avoid iterating over nodes in Split2QUnitaries if there are no unitaries #13384

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

mtreinish
Copy link
Member

Summary

This commit adds a check to the start of the split_2q_unitaries rust function that is the core of the Split2QUnitaries transpiler pass to do a lookup if there are any UnitaryGate objects in the dag without iterating over the dag. The pass only will split unitary gates so we can avoid checking the name of each gate individually if we know there aren't any up front.

Details and comments

This commit adds a check to the start of the split_2q_unitaries rust
function that is the core of the Split2QUnitaries transpiler pass to do
a lookup if there are any `UnitaryGate` objects in the dag without
iterating over the dag. The pass only will split unitary gates so we
can avoid checking the name of each gate individually if we know there
aren't any up front.
@mtreinish mtreinish added performance Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository labels Oct 30, 2024
@mtreinish mtreinish requested a review from a team as a code owner October 30, 2024 21:20
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11601844816

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 88.741%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 93.73%
Totals Coverage Status
Change from base Build 11601286937: 0.02%
Covered Lines: 75700
Relevant Lines: 85304

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Getting the op counts also iterates over the DAG though right? Would we get a similar or even better performance if we have the name-check before we get the qubits? I.e.

for node in nodes {
   if let NodeType::Operation(inst) = &dag.dag()[node] { 
       if inst.op.name() != "unitary" { continue };
       // rest as before ...

This way we would keep only one loop over the DAG, no?

@mtreinish
Copy link
Member Author

No, it's an O(1) lookup that doesn't require any iteration. The DAGCircuit maintains the counts mapping as operations are added and removed specifically for this use case. You can just look at the method definition: https://github.com/Qiskit/qiskit/blob/main/crates/circuit/src/dag_circuit.rs#L6634-L6642

@Cryoris Cryoris added this pull request to the merge queue Oct 31, 2024
Merged via the queue into Qiskit:main with commit 4bd2dd8 Oct 31, 2024
17 checks passed
@mtreinish mtreinish deleted the skip-split-unitaries-if-no-unitaries branch October 31, 2024 11:24
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 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.

4 participants