Qiskit / rustworkx

A high performance Python graph library implemented in Rust.
https://www.rustworkx.org
Apache License 2.0
1.03k stars 145 forks source link

Add reverse topological ordering #1105

Closed jakelishman closed 6 months ago

jakelishman commented 6 months ago

What is the expected enhancement?

I would like to be able to get a "reverse" topological ordering from lexicographical_topological_sort and TopologicalSorter in the sense of "a topological order if all the edges reversed direction" - it'd be helpful on Qiskit in a few places where we want to find final operations. For our purposes, we don't need topological_sort to offer the same functionality, which might be easier since that one calls out to petgraph within rustworkx at the moment.

The logic is very straightforward - we just swap which of Direction::Outgoing and Direction::Incoming we use in a couple of places in the sorters. I can provide a PR if it's an acceptable feature.