forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate DAGNode.sort_key attribute
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
- Loading branch information
Showing
4 changed files
with
100 additions
and
8 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
20 changes: 20 additions & 0 deletions
20
releasenotes/notes/deprecate-DAGNode-sort-key-3c6ed71133875872.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,20 @@ | ||
--- | ||
deprecations_transpiler: | ||
- | | ||
The :attr:`.DAGOpNode.sort_key`, :attr:`.DAGOutNode.sort_key`, and | ||
:attr:`.DAGInNode.sort_key` attributes have been deprecated and will be | ||
removed in the Qiskit 2.0.0 release. This attribute was originally used | ||
as a lexicographical key for topological sorting nodes in | ||
a :class:`.DAGCircuit`. However, the key is no longer used for this | ||
as the sorting is done internally in Rust code now. If you're using this | ||
attribute for anything you can recreate the key from the other attributes | ||
of a node. For example, you can use a function 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) | ||
) | ||
which will generate a string like the sort key does. |