Skip to content

Commit 0e8414b

Browse files
Avoid overhead for synthesized nodes lookup (#13424) (#13425)
After #12550 a hash implementation was added to the implementation of DAGOpNode to be able to have identical instances of dag nodes used be usable in a set or dict. This is because after #12550 changed the DAGCircuit so the DAGOpNode instances were just a python view of the data contained in the nodes of a dag. While prior to #12550 the actual DAGOpNode objects were returned by reference from DAG methods. However, this hash implementation has additional overhead compared to the object identity based version used before. This has caused a regression in some cases for high level synthesis when it's checking for nodes it's already synthesized. This commit addresses this by changing the dict key to be the node id instead of the node object. The integer hashing is significantly faster than the object hashing. (cherry picked from commit 8c6ad02) Co-authored-by: Matthew Treinish <[email protected]>
1 parent 4c494a3 commit 0e8414b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

qiskit/transpiler/passes/synthesis/high_level_synthesis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def _run(
382382

383383
# If the synthesis changed the operation (i.e. it is not None), store the result.
384384
if synthesized is not None:
385-
synthesized_nodes[node] = (synthesized, synthesized_context)
385+
synthesized_nodes[node._node_id] = (synthesized, synthesized_context)
386386

387387
# If the synthesis did not change anything, just update the qubit tracker.
388388
elif not processed:
@@ -407,8 +407,9 @@ def _run(
407407
outer_to_local = context.to_local_mapping()
408408

409409
for node in dag.topological_op_nodes():
410-
if node in synthesized_nodes:
411-
op, op_context = synthesized_nodes[node]
410+
411+
if op_tuple := synthesized_nodes.get(node._node_id, None):
412+
op, op_context = op_tuple
412413

413414
if isinstance(op, Operation):
414415
out.apply_operation_back(op, node.qargs, node.cargs)

0 commit comments

Comments
 (0)