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

Remove sort_key attribute from DAGNode #13736

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Jan 26, 2025

Summary

Prior to having the DAGCircuit in rust the sort_key attribute was added as a cache to speed up the lexicographical topological sort. Prior to having this attribute the topological sort method would compute the sort key as a string on the fly which ended up being a large bottleneck in transpilation (see: #4040 for more details). However, since migrating the DAGCircuit implementation to Rust this sort_key attribute isn't needed anymore because we call the rustworkx-core function with a tuple of bit objects instead of a string. The sort_key atribute was left on in place for backwards compatibility (it shouldn't have been public, this was a mistake in #4040) and when we create a python DAGNode object that will be returned to Python the creation of the sort key is unnecessary overhead (it takes roughly 1% of profile time to format the sort_key string during transpilation). Since nothing in DAGCircuit is actually using it this commit removes it to save the CPU cycles creating the string on each dag creation. We will need to add a deprecation to 1.4.0 to mark this removal for 2.0.0 since this was missed in 1.3.0.

Details and comments

Deprecation in: #13744

Prior to having the DAGCircuit in rust the `sort_key` attribute was added
as a cache to speed up the lexicographical topological sort. Prior to
having this attribute the topological sort method would compute the sort
key as a string on the fly which ended up being a large bottleneck in
transpilation (see: Qiskit#4040 for more details). However, since migrating
the DAGCircuit implementation to Rust this sort_key attribute isn't
needed anymore because we call the rustworkx-core function with a tuple
of bit objects instead of a string. The `sort_key` atribute was left on
in place for backwards compatibility (it shouldn't have been public,
this was a mistake in Qiskit#4040) and when we create a python DAGNode object
that will be returned to Python the creation of the sort key is
unnecessary overhead (it takes roughly 1% of profile time to format the
sort_key string during transpilation). Since nothing in DAGCircuit is
actually using it this commit removes it to save the CPU cycles
creating the string on each dag creation. We will need to add a
deprecation to 1.4.0 to mark this removal for 2.0.0 since this was
missed in 1.3.0.
@mtreinish mtreinish added the Changelog: Removal Include in the Removed section of the changelog label Jan 26, 2025
@mtreinish mtreinish added this to the 2.0.0 milestone Jan 26, 2025
@mtreinish mtreinish requested a review from a team as a code owner January 26, 2025 00:56
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Jan 26, 2025

Pull Request Test Coverage Report for Build 12999233331

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 32 of 32 (100.0%) changed or added relevant lines in 4 files are covered.
  • 119 unchanged lines in 7 files lost coverage.
  • Overall coverage decreased (-0.002%) to 88.939%

Files with Coverage Reduction New Missed Lines %
qiskit/synthesis/linear/linear_depth_lnn.py 1 90.91%
crates/circuit/src/dag_node.rs 1 77.46%
crates/accelerate/src/unitary_synthesis.rs 1 92.97%
crates/qasm2/src/lex.rs 5 91.98%
crates/accelerate/src/synthesis/linear/utils.rs 12 92.59%
crates/accelerate/src/synthesis/linear/mod.rs 12 82.8%
crates/accelerate/src/sparse_observable.rs 87 94.34%
Totals Coverage Status
Change from base Build 12951053301: -0.002%
Covered Lines: 79680
Relevant Lines: 89589

💛 - Coveralls

kevinhartman
kevinhartman previously approved these changes Jan 27, 2025
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.

It's nice to see this removed 🙂 (it was a headache for me when we began porting DAGCircuit to Rust, initially).

Can you also link the deprecation PR in the description once it is out?

@@ -114,8 +114,6 @@ impl DAGNode {
#[pyclass(module = "qiskit._accelerate.circuit", extends=DAGNode)]
pub struct DAGOpNode {
pub instruction: CircuitInstruction,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Maybe this should become a tuple struct now. Feel free to leave as is if that's your preference.

Copy link
Member Author

Choose a reason for hiding this comment

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

I kept it this way for simplicity since I just deleted the lines with the previous attribute. I did overlook there is only a single field now. But I think I'd probably rather keep it the same because I feel like there are a few places we do node.instruction/self.instruction and that feels a bit more ergonomic than node.0

qiskit/transpiler/passes/routing/star_prerouting.py Outdated Show resolved Hide resolved
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Jan 27, 2025
Prior to having the DAGCircuit in rust the sort_key attribute was added
as a cache to speed up the lexicographical topological sort. Prior to
having this attribute the topological sort method would compute the sort
key as a string on the fly which ended up being a large bottleneck in
transpilation (see: Qiskit#4040 for more details). However, since migrating the
DAGCircuit implementation to Rust this sort_key attribute isn't needed
anymore because we call the rustworkx-core function with a tuple of bit
objects instead of a string. The sort_key atribute was left on in place
for backwards compatibility (it shouldn't have been public, this was a
mistake in Qiskit#4040) and when we create a python DAGNode object that will
be returned to Python the creation of the sort key is unnecessary
overhead (it takes roughly 1% of profile time to format the sort_key
string during transpilation). Since nothing in DAGCircuit is actually
using it this commit removes it to save the CPU cycles creating the
string on each dag creation.

This attribute is removed in Qiskit 2.0.0 in Qiskit#13736
@kevinhartman kevinhartman added this pull request to the merge queue Jan 27, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 27, 2025
Prior to having the DAGCircuit in rust the sort_key attribute was added
as a cache to speed up the lexicographical topological sort. Prior to
having this attribute the topological sort method would compute the sort
key as a string on the fly which ended up being a large bottleneck in
transpilation (see: #4040 for more details). However, since migrating the
DAGCircuit implementation to Rust this sort_key attribute isn't needed
anymore because we call the rustworkx-core function with a tuple of bit
objects instead of a string. The sort_key atribute was left on in place
for backwards compatibility (it shouldn't have been public, this was a
mistake in #4040) and when we create a python DAGNode object that will
be returned to Python the creation of the sort key is unnecessary
overhead (it takes roughly 1% of profile time to format the sort_key
string during transpilation). Since nothing in DAGCircuit is actually
using it this commit removes it to save the CPU cycles creating the
string on each dag creation.

This attribute is removed in Qiskit 2.0.0 in #13736
Merged via the queue into Qiskit:main with commit 75436a4 Jan 27, 2025
17 checks passed
@mtreinish mtreinish deleted the drop-sort-key branch January 28, 2025 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Removal Include in the Removed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants