Skip to content

Commit

Permalink
Adding an auxiliary function to return the id of a node.
Browse files Browse the repository at this point in the history
Needed because this field is named differently in DAGOpNode and DAGDepNode.
  • Loading branch information
alexanderivrii committed Nov 24, 2024
1 parent c1fc1dd commit 305d48a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions qiskit/dagcircuit/collect_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _setup_in_degrees(self):
self._in_degree = {}
for node in self._op_nodes():
deg = len(self._direct_preds(node))
self._in_degree[node._node_id] = deg
self._in_degree[self._get_node_id(node)] = deg
if deg == 0:
self._pending_nodes.append(node)

Expand All @@ -91,6 +91,13 @@ def _op_nodes(self) -> Iterable[DAGOpNode | DAGDepNode]:
else:
return self.dag.get_nodes()

def _get_node_id(self, node):
"""Returns the id of the given node."""
if not self.is_dag_dependency:
return node._node_id
else:
return node.node_id

def _direct_preds(self, node):
"""Returns direct predecessors of a node. This function takes into account the
direction of collecting blocks, that is node's predecessors when collecting
Expand Down Expand Up @@ -165,8 +172,8 @@ def collect_matching_block(self, filter_fn: Callable) -> list[DAGOpNode | DAGDep

# update the _in_degree of node's successors
for suc in self._direct_succs(node):
self._in_degree[suc._node_id] -= 1
if self._in_degree[suc._node_id] == 0:
self._in_degree[self._get_node_id(suc)] -= 1
if self._in_degree[self._get_node_id(suc)] == 0:
new_pending_nodes.append(suc)
else:
self._pending_nodes.append(node)
Expand Down

0 comments on commit 305d48a

Please sign in to comment.