Skip to main content

A python graph library implemented in Rust

Project description

retworkx

LicenseBuild StatusCoverage Status

retworkx is a rust graph library interface to python3. For right now it's scope is as a replacement for qiskit-terra's previous (and current) networkx usage (hence the name). The scope might grow or change over time, but to start it's just about building a DAG and operating on it with the performance and safety that Rust provides.

Installing retworkx

retworkx is published on pypi so on x86_64, i686, ppc64le, and aarch64 Linux systems, x86_64 on Mac OSX, and 32 and 64 bit Windows installing is as simple as running:

pip install retworkx

This will install a precompiled version of retworkx into your python environment.

However, if there are no precompiled binaries published for your system you'll have to compile the code. The source package is also published on pypi so you can also run the above command to install it. However, there are 2 preconditions for this to work, first you need to have cargo/rustc nightly in your PATH. You can use rustup to make this step simpler. Secondly, you need to have setuptools-rust installed in your python environment. This can can be done by simply running:

pip install setuptools-rust

prior to running:

pip install retworkx

If you have rust nightly properly installed pip will compile retworkx for your local system and it should run just as the prebuilt binaries would.

Building from source

The first step for building retworkx from source is to clone it locally with:

git clone https://github.com/Qiskit/retworkx.git

retworkx uses PyO3 and setuptools-rust to build the python interface. Unfortunately, this means you need to use nightly rust because PyO3 only works with nightly at this point. You can use rustup to install rust nightly.

Once you have nightly rust and cargo installed you can easily install retworkx into your python environment using pip. Once you have a local clone of the repo, change your current working directory to the root of the repo. To set the compiler for retworkx to nightly rust using rustup, run the following from this directory:

rustup override set nightly

(MacOS users shoud instead run rustup default nightly to enable nightly rust globally.)

Then, you can install retworkx into your python env with:

pip install .

Assuming your current working directory is still the root of the repo. Otherwise you can run:

pip install $PATH_TO_REPO_ROOT

which will install it the same way. Then retworkx is installed inyour local python environment. There are 2 things to note when doing this though, first if you try to run python from the repo root using this method it will not work as you expect. There is a name conflict in the repo root because of the local python package shim used in building the package. Simply run your python scripts or programs using retworkx outside of the repo root. The second issue is that any local changes you make to the rust code will not be reflected live in the python you'll need to recompile the source by rerunning pip install to have any changes reflected in your python environment.

Using retworkx

Once you have retworkx installed you can use it by importing retworkx. All the functions and the PyDAG class are off the root of the package. For example, building a DAG and adding 2 nodes with an edge between them would be:

import retworkx

my_dag = retworkx.PyDAG()
# add_node(), add_child(), and add_parent() return the node index
# The sole argument here can be any python object
root_node = my_dag.add_node("MyRoot")
# The second and third arguments can be any python object
my_dag.add_child(root_node, "AChild", ["EdgeData"])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retworkx-0.3.4.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distributions

retworkx-0.3.4-cp38-cp38-win_amd64.whl (179.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

retworkx-0.3.4-cp38-cp38-win32.whl (168.5 kB view hashes)

Uploaded CPython 3.8 Windows x86

retworkx-0.3.4-cp38-cp38-manylinux2014_ppc64le.whl (828.7 kB view hashes)

Uploaded CPython 3.8

retworkx-0.3.4-cp38-cp38-manylinux2014_aarch64.whl (833.7 kB view hashes)

Uploaded CPython 3.8

retworkx-0.3.4-cp38-cp38-manylinux2010_x86_64.whl (763.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

retworkx-0.3.4-cp38-cp38-manylinux2010_i686.whl (804.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

retworkx-0.3.4-cp38-cp38-manylinux1_x86_64.whl (763.0 kB view hashes)

Uploaded CPython 3.8

retworkx-0.3.4-cp38-cp38-manylinux1_i686.whl (804.0 kB view hashes)

Uploaded CPython 3.8

retworkx-0.3.4-cp38-cp38-macosx_10_9_x86_64.whl (230.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

retworkx-0.3.4-cp37-cp37m-win_amd64.whl (179.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

retworkx-0.3.4-cp37-cp37m-win32.whl (168.5 kB view hashes)

Uploaded CPython 3.7m Windows x86

retworkx-0.3.4-cp37-cp37m-manylinux2014_ppc64le.whl (828.8 kB view hashes)

Uploaded CPython 3.7m

retworkx-0.3.4-cp37-cp37m-manylinux2014_aarch64.whl (833.8 kB view hashes)

Uploaded CPython 3.7m

retworkx-0.3.4-cp37-cp37m-manylinux2010_x86_64.whl (763.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

retworkx-0.3.4-cp37-cp37m-manylinux2010_i686.whl (804.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

retworkx-0.3.4-cp37-cp37m-manylinux1_x86_64.whl (762.9 kB view hashes)

Uploaded CPython 3.7m

retworkx-0.3.4-cp37-cp37m-manylinux1_i686.whl (804.0 kB view hashes)

Uploaded CPython 3.7m

retworkx-0.3.4-cp37-cp37m-macosx_10_9_x86_64.whl (230.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

retworkx-0.3.4-cp36-cp36m-win_amd64.whl (180.0 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

retworkx-0.3.4-cp36-cp36m-win32.whl (168.7 kB view hashes)

Uploaded CPython 3.6m Windows x86

retworkx-0.3.4-cp36-cp36m-manylinux2014_ppc64le.whl (828.9 kB view hashes)

Uploaded CPython 3.6m

retworkx-0.3.4-cp36-cp36m-manylinux2014_aarch64.whl (834.2 kB view hashes)

Uploaded CPython 3.6m

retworkx-0.3.4-cp36-cp36m-manylinux2010_x86_64.whl (763.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

retworkx-0.3.4-cp36-cp36m-manylinux2010_i686.whl (804.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

retworkx-0.3.4-cp36-cp36m-manylinux1_x86_64.whl (763.2 kB view hashes)

Uploaded CPython 3.6m

retworkx-0.3.4-cp36-cp36m-manylinux1_i686.whl (804.2 kB view hashes)

Uploaded CPython 3.6m

retworkx-0.3.4-cp36-cp36m-macosx_10_9_x86_64.whl (230.4 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

retworkx-0.3.4-cp35-cp35m-win_amd64.whl (179.9 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

retworkx-0.3.4-cp35-cp35m-win32.whl (168.7 kB view hashes)

Uploaded CPython 3.5m Windows x86

retworkx-0.3.4-cp35-cp35m-manylinux2014_ppc64le.whl (828.7 kB view hashes)

Uploaded CPython 3.5m

retworkx-0.3.4-cp35-cp35m-manylinux2014_aarch64.whl (833.7 kB view hashes)

Uploaded CPython 3.5m

retworkx-0.3.4-cp35-cp35m-manylinux2010_x86_64.whl (763.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

retworkx-0.3.4-cp35-cp35m-manylinux2010_i686.whl (803.9 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

retworkx-0.3.4-cp35-cp35m-manylinux1_x86_64.whl (763.0 kB view hashes)

Uploaded CPython 3.5m

retworkx-0.3.4-cp35-cp35m-manylinux1_i686.whl (803.9 kB view hashes)

Uploaded CPython 3.5m

retworkx-0.3.4-cp35-cp35m-macosx_10_9_x86_64.whl (230.3 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page