-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove sort_key attribute from DAGNode (#13736)
* Remove sort_key attribute from DAGNode 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. * Simplify star pre-routing sort_key logic
- Loading branch information
Showing
6 changed files
with
62 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
releasenotes/notes/remove-deprecated-sort-key-8921c52db826c8ba.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
upgrade_transpiler: | ||
- | | ||
Removed the deprecated ``DAGNode.sort_key`` attribute. This attribute was deprecated | ||
in the Qiskit 1.4.0 release. As the lexicographical topological sorting is done internally | ||
and rust and the sort key attribute was unused this was removed to remove the overhead | ||
from DAG node creation. If you were relying on the sort key you can reproduce it from | ||
a given node using something like:: | ||
def get_sort_key(node: DAGNode): | ||
if isinstance(node, (DAGInNode, DAGOutNode)): | ||
return str(node.wire) | ||
return ",".join( | ||
f"{dag.find_bit(q).index:04d}" for q in itertools.chain(node.qargs, node.cargs) | ||
) |