iqm.qrisp_iqm.passes.routing.core.graph_processing_tools.reverse_dag

Contents

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

iqm.qrisp_iqm.passes.routing.core.graph_processing_tools.reverse_dag(circuit_dag: CircuitDAG) → CircuitDAG#

Build a backward instruction DAG by reversing the topological order.

Given a forward CSR instruction DAG whose rows are in topological order, return a new DAG where:

  • All dependency edges are reversed (transposed).

  • The row ordering is reversed so that the last forward node becomes backward row 0.

Mathematically the backward adjacency matrix is B = P · A^T · P where A is the forward adjacency matrix and P is the order-reversal permutation. This ensures that prune_dag() (which slices the first k rows) peels off gates in backward order.

Parameters:

circuit_dag (CircuitDAG) – CSR instruction DAG.

Returns:

CSR instruction DAG with reversed topological order and reversed edges.

Return type:

CircuitDAG