Qiskit / rustworkx

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

Return paths as a generator instead of list #1088

Open sambaPython24 opened 7 months ago

sambaPython24 commented 7 months ago

What is the expected enhancement?

networkx returns a generator from e.g. rx.all_simple_paths. That is useful for very large graphs with many possible paths, since we can loop over the generator without filling the memory and break if other conditions are fulfilled.

Ps.: The documentation for rx.all_simplepaths needs to be fixed: the arguments name is not ```frombutorigin```. (Signature: rx.all_simplepaths(graph, from, to, min_depth=None, cutoff=None)

IvanIsCoding commented 7 months ago

It would be nice but it would require a major redesign in the way we do iterators. Until coroutines are stable we don't really have an equivalent for Python's yield keyword that is trivial to implement.

With regards to the from_ argument, the argument has different names in the type-agnostic all_simple_paths and the type-specific digraph_all_simple_paths. But it is a positional-only argument so it doesn't matter