# Retworkx: new, high-performance Python graph library

**URL:** <https://discourse.julialang.org/t/retworkx-new-high-performance-python-graph-library/71109>\
**Category:** Graphs\
**Tags:** graphs\
**Created:** [November 7, 2021, 6:53pm UTC](https://discourse.julialang.org/t/retworkx-new-high-performance-python-graph-library/71109 "2021-11-07T18:53:14Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [November 7, 2021, 6:53pm UTC](https://discourse.julialang.org/t/retworkx-new-high-performance-python-graph-library/71109/1 "2021-11-07T18:53:14Z")

</div>

[retworkx](https://github.com/Qiskit/retworkx) is a python library wrapping the [petgraph](https://github.com/petgraph/petgraph) Rust library. (Actually, retworkx itself has a pure-Rust layer enhancing petgraph). retworkx is a [strong contender for Most Performant Python Graph Library](https://github.com/mtreinish/retworkx-comparison-benchmarks). Development has industry support and volunteers.

This is interesting for Julia, because the library formerly known as LightGraphs usually compares quite favorably in performance to other libraries; in particular those with a Python interface. Based on the benchmarks linked above, it seems retworkx is faster. Another piece of data: I wrote the betweeness centrality function for retworkx (in the Rust layer). It was the first thing I ever wrote in Rust. But, at the Python level, it outperformed LightGraphs by 50% or so in tests I made while developing. I would like to better understand the data structures used by petgraph to see what their role is; I suspect it’s large.

The comparisons above implement solutions to the DIMACS 9 challenge. I started to implement this in Julia. But, I stalled a bit because despite some effort, I was unable to get a Julia implementation that is competitive with any of the entrants in that repo on the first step, which is graph construction. Of course, this is known to be Graphs.jl (former LG) 's weakest point. Also I did some yak shaving regarding the DIMACS file format; i.e. I might as well make a PR to GraphsIO.jl. But, 1) GraphsIO does not currently support reading attributes, so I would have to introduce a new dependency and extend the interface of `loadgraph`. 2) which attribute-bearing Julia structure is best for this is not clear, probably `MetaGraphs`. 3) DIMACS graph file format is apparently widely used in academic research, but it is unfortunately ill-specified and not versioned.

Seth gave an explanation in a Discourse post for why Graphs.jl is slow in reading graphs from files. But, in contrast, I found that, if I built only a `SimpleGraph` and did not use the weights from the DIMACS file, I could outperform all Python libraries except retworkx, and the latter was only 50% faster or so. I could even parse the weights and put them in an Array and be fast. I just could not put them in a graph structure without taking five times longer than (pure-Python) networkx. It seemed that the problem was the very large memory usage due to nested Dicts.

At any rate, I want to give this a bit of visibility because, aside from being an impressive library, retworkx represents a challenge to the Julia community.

---

_[View the full topic](https://discourse.julialang.org/t/retworkx-new-high-performance-python-graph-library/71109)._
