# Speed Improvments on get\_all\_simple\_paths

**URL:** <https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482>\
**Category:** Usage\
**Tags:** Python\
**Created:** [18 October 2020 02:58 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482 "2020-10-18T02:58:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravi\_Bhanabhai](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ravi_bhanabhai/32/384_2.png) [@Ravi\_Bhanabhai](https://igraph.discourse.group/u/Ravi_Bhanabhai)\
**Post date:** [18 October 2020 02:58 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/1 "2020-10-18T02:58:57Z")

</div>

hi There first time poster I am using the function get\_all\_simple\_paths and I notice a significant speed issue with graph and nodes \> 600.

I simplify my graph before usage. I’m using python 3.7 and installed using conda.

Is there a way to get speed improvements? or somehow use the C version with python. BTW is the python or cython code for igraph multi-threaded?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [18 October 2020 14:24 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/2 "2020-10-18T14:24:38Z")

</div>

As stated in the [documentation](https://igraph.org/python/doc/igraph.Graph-class.html#get_all_simple_paths),

> Note that potentially there are exponentially many paths between two vertices of a graph, especially if your graph is lattice-like.

In other words, it is entirely expected that as the size of the graph increases, you will hit a performance wall. A faster implementation is not likely to help much for such problems. “Brute-force” approaches to speedup, such as faster computers or parallelization definitely would not help. It would only make make _slightly_ larger graphs feasible.

I am not familiar with the specific implementation used in igraph, and how much better one can get. Perhaps better implementations are possible. My point is that since the number of results is exponentially large, no algorithm will be better than exponential—all of them will hit a performance wall at some graph size.

* * *

> [@Ravi\_Bhanabhai](#):
>
> or somehow use the C version with python.

The Python interface of igraph exposes the function implemented in the C core. You are already using it.

---

<div class="post-metadata">

**Author:** ![Ravi\_Bhanabhai](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ravi_bhanabhai/32/384_2.png) [@Ravi\_Bhanabhai](https://igraph.discourse.group/u/Ravi_Bhanabhai)\
**Post date:** [19 October 2020 01:38 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/3 "2020-10-19T01:38:27Z")

</div>

Thank you for the reply I see and that does make quiet a bit of sense. I’m not an expert in graphs do you or does anyone (broadcasting request for any passer bys) know of a way to reduce my graph to make it more simpler.

---

<div class="post-metadata">

**Author:** ![Ravi\_Bhanabhai](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ravi_bhanabhai/32/384_2.png) [@Ravi\_Bhanabhai](https://igraph.discourse.group/u/Ravi_Bhanabhai)\
**Post date:** [19 October 2020 20:41 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/4 "2020-10-19T20:41:31Z")

</div>

In the documentation it says it may run out of memory when calculating get\_all\_simple\_paths.

A decent idea might be to use tempfile to push the paths to disk then load back up at the end before returning them. It’ll help to minimize peak memory usage.

---

<div class="post-metadata">

**Author:** ![Ravi\_Bhanabhai](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ravi_bhanabhai/32/384_2.png) [@Ravi\_Bhanabhai](https://igraph.discourse.group/u/Ravi_Bhanabhai)\
**Post date:** [20 October 2020 00:37 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/5 "2020-10-20T00:37:05Z")

</div>

just curious if I wished to make the function multi-threaded can someone provide any insight on that before I look into it

---

<div class="post-metadata">

**Author:** ![iosonofabio](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/iosonofabio/32/16_2.png) [@iosonofabio](https://igraph.discourse.group/u/iosonofabio)\
**Post date:** [5 November 2020 20:56 UTC](https://igraph.discourse.group/t/speed-improvments-on-get-all-simple-paths/482/6 "2020-11-05T20:56:30Z")

</div>

Hi Ravi,

Caching to disk, multicore etc. are all feasible but not interesting for most users, so we can’t easily spend our time on them.

By any means, if you need it and want to code a parallelized version, feel free to get started and ask questions along the way.

Cheers,  
Fabio
