iqm.qrisp_iqm.passes.routing.core.graph_processing_tools.reachability_counts_csr

iqm.qrisp_iqm.passes.routing.core.graph_processing_tools.reachability_counts_csr#

iqm.qrisp_iqm.passes.routing.core.graph_processing_tools.reachability_counts_csr(indptr: ndarray, indices: ndarray, ignore_nodes: ndarray, predecessors: bool = False) → ndarray#

Count how many nodes each node can reach in a CSR-encoded DAG.

By default (predecessors=False) this counts descendants: for every node u it returns the number of nodes reachable by following edges forward. When predecessors=True it counts predecessors (ancestors) instead, i.e. the number of nodes from which u is reachable — equivalent to computing descendant counts on the transposed graph.

Nodes listed in ignore_nodes are excluded from every count (useful for skipping single-qubit gates in a circuit DAG).

Parameters:
  • indptr (ndarray) – CSR row-pointer array of the DAG.

  • indices (ndarray) – CSR column-index array of the DAG.

  • ignore_nodes (ndarray) – Boolean (0/1) mask — nodes where the entry is 1 are excluded from counting.

  • predecessors (bool) – Iff True, count predecessors (ancestors) instead of descendants.

Returns:

Per-node reachability count (self excluded).

Return type:

ndarray