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 overhead for synthesized nodes lookup #13424

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions qiskit/transpiler/passes/synthesis/high_level_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _run(

# If the synthesis changed the operation (i.e. it is not None), store the result.
if synthesized is not None:
synthesized_nodes[node] = (synthesized, synthesized_context)
synthesized_nodes[node._node_id] = (synthesized, synthesized_context)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine in this case since synthesized_nodes is only used with one DAG (and not e.g. shared by the recursive control flow block handling).

But this optimization is something we should be careful when applying in other places, since the semantics of uniqueness in keys shifts from being global to local within a specific DAG (which means that keys will clobber each other if node indices from more than a single DAG are used in the same map). This was responsible for a bug we had in the visualization code after the initial DAG port to Rust.


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

for node in dag.topological_op_nodes():
if node in synthesized_nodes:
op, op_context = synthesized_nodes[node]

if op_tuple := synthesized_nodes.get(node._node_id, None):
op, op_context = op_tuple

if isinstance(op, Operation):
out.apply_operation_back(op, node.qargs, node.cargs)
Expand Down