brian2/utils/topsort.py
raw| 1 | from graphlib import TopologicalSorter |
| 2 | |
| 3 | __all__ = ["topsort"] |
| 4 | |
| 5 | |
| 6 | def topsort(graph): |
| 7 | """ |
| 8 | Topologically sort a graph |
| 9 | |
| 10 | The graph should be of the form ``{node: [list of nodes], ...}``. |
| 11 | |
| 12 | Uses `graphlib.TopologicalSorter`. |
| 13 | """ |
| 14 | sorter = TopologicalSorter(graph) |
| 15 | return list(sorter.static_order()) |