Skip to main content

A python graph library implemented in Rust

Project description

rustworkx

License Build Status Build Status Coverage Status Minimum rustc 1.70 DOI arXiv Zenodo

A high-performance, general-purpose graph library for Python, written in Rust.

Usage

Once installed, simply import rustworkx. All graph classes and top-level functions are accessible with a single import. To illustrate this, the following example calculates the shortest path between two nodes A and C in an undirected graph.

import rustworkx

# Rustworkx's undirected graph type.
graph = rustworkx.PyGraph()

# Each time add node is called, it returns a new node index
a = graph.add_node("A")
b = graph.add_node("B")
c = graph.add_node("C")

# add_edges_from takes tuples of node indices and weights,
# and returns edge indices
graph.add_edges_from([(a, b, 1.5), (a, c, 5.0), (b, c, 2.5)])

# Returns the path A -> B -> C
rustworkx.dijkstra_shortest_paths(graph, a, c, weight_fn=float)

Installing rustworkx

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

pip install rustworkx

This will install a precompiled version of rustworkx into your Python environment.

Installing on a platform without precompiled binaries

If there are no precompiled binaries published for your system you'll have to build the package from source. However, to be able able to build the package from the published source package you need to have Rust >= 1.70 installed (and also cargo which is normally included with rust) You can use rustup (a cross platform installer for rust) to make this simpler, or rely on other installation methods. A source package is also published on pypi, so you still can also run the above pip command to install it. Once you have rust properly installed, running:

pip install rustworkx

will build rustworkx for your local system from the source package and install it just as it would if there was a prebuilt binary available.

[!NOTE]
To build from source you will need to ensure you have pip >=19.0.0 installed, which supports PEP-517, or that you have manually installed setuptools-rust prior to running pip install rustworkx. If you recieve an error about setuptools-rust not being found you should upgrade pip with pip install -U pip or manually install setuptools-rust with pip install setuptools-rust and try again.

Optional dependencies

If you're planning to use the rustworkx.visualization module you will need to install optional dependencies to use the functions. The matplotlib based drawer function rustworkx.visualization.mpl_draw requires that the matplotlib library is installed. This can be installed with pip install matplotlib or when you're installing rustworkx with pip install 'rustworkx[mpl]'. If you're going to use the graphviz based drawer function rustworkx.visualization.graphviz_drawer first you will need to install graphviz, instructions for this can be found here: https://graphviz.org/download/#executable-packages. Then you will need to install the pillow Python library. This can be done either with pip install pillow or when installing rustworkx with pip install 'rustworkx[graphviz]'.

If you would like to install all the optional Python dependencies when you install rustworkx you can use pip install 'rustworkx[all]' to do this.

Authors and Citation

rustworkx is the work of many people who contribute to the project at different levels. If you use rustworkx in your research, please cite our paper as per the included BibTeX file.

Community

Besides Github interactions (such as opening issues) there are two locations available to talk to other rustworkx users and developers. The first is a public Slack channel in the Qiskit workspace, #rustworkx. You can join the Qiskit Slack workspace here. Additionally, there is an IRC channel #rustworkx on the OFTC IRC network

Building from source

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

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

rustworkx uses PyO3 and setuptools-rust to build the python interface, which enables using standard python tooling to work. So, assuming you have rust installed, you can easily install rustworkx 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. Then, you can install rustworkx 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 rustworkx is installed in your 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 rustworkx 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 your python environment, you'll need to recompile rustworkx by rerunning pip install to have any changes reflected in your python environment.

Develop Mode

If you'd like to build rustworkx in debug mode and use an interactive debugger while working on a change you can use python setup.py develop to build and install rustworkx in develop mode. This will build rustworkx without optimizations and include debuginfo which can be handy for debugging. Do note that installing rustworkx this way will be significantly slower then using pip install and should only be used for debugging/development.

[!TIP] It's worth noting that pip install -e does not work, as it will link the python packaging shim to your python environment but not build the rustworkx binary. If you want to build rustworkx in debug mode you have to use python setup.py develop.

Project history

Rustworkx was originally called retworkx and was created initially to be a replacement for Qiskit's previous (and current) NetworkX usage (hence the original name). The project was originally started to build a faster directed graph to use as the underlying data structure for the DAG at the center of qiskit's transpiler. However, since it's initial introduction the project has grown substantially and now covers all applications that need to work with graphs which includes Qiskit.

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

rustworkx-0.15.1.tar.gz (342.2 kB view details)

Uploaded Source

Built Distributions

rustworkx-0.15.1-cp38-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8+ Windows x86-64

rustworkx-0.15.1-cp38-abi3-win32.whl (1.7 MB view details)

Uploaded CPython 3.8+ Windows x86

rustworkx-0.15.1-cp38-abi3-musllinux_1_1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.1+ x86-64

rustworkx-0.15.1-cp38-abi3-musllinux_1_1_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.1+ ARM64

rustworkx-0.15.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

rustworkx-0.15.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.6 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ s390x

rustworkx-0.15.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ppc64le

rustworkx-0.15.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

rustworkx-0.15.1-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

rustworkx-0.15.1-cp38-abi3-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

rustworkx-0.15.1-cp38-abi3-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file rustworkx-0.15.1.tar.gz.

File metadata

  • Download URL: rustworkx-0.15.1.tar.gz
  • Upload date:
  • Size: 342.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for rustworkx-0.15.1.tar.gz
Algorithm Hash digest
SHA256 0e0cc86599f979285b2ab9c357276f3272f3fcb3b2df5651a6bf9704c570d4c1
MD5 7643606d793f86c3444b654babb6d6b0
BLAKE2b-256 5e071af3ead27f1da113a60dc6735c761da6fc2e2db4cfc414bbcd03a989ccee

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: rustworkx-0.15.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 89077382633e918d2392772f53b9d6d30eee51eb536f8d38ee195c212b2f0427
MD5 893ca6478ebef0f4ec751bfa24a91dbe
BLAKE2b-256 9cc650f5736f5dac1709c6c8b6ac3470f466fd793dd25c081923942caf13051f

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-win32.whl.

File metadata

  • Download URL: rustworkx-0.15.1-cp38-abi3-win32.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 308bc76a01bcae9af4602d8b9ed58021df37dd0bb5a7b2e3831ae53c5e234ff0
MD5 a28bd5da013556b9a79c008e4bf08d8b
BLAKE2b-256 d5ea9cbf42b4d9a2b6ad18736bc2149d2b2439075b70094232ba3494fd14845b

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ce53f173fed16e1d51d9df9f23475a16c981b03bf1a412d991c75a70db6b1dc1
MD5 719f2d57ff6e8902a8000eab1d85f8ca
BLAKE2b-256 6566daf6fffadb749574f78cd70919e598371d40484993ed005ed5efbef28b4e

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 7834ab34748db6214ec3b3836b996b23882dc83184234e6d346d6bb85fd58ae5
MD5 fd79bf838be2ea7a50efef2396095cae
BLAKE2b-256 c6fe1e9a8a29c21080155b7422011a3c472aa45dbb3b8bb6f610958eb906a713

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e5f4156f46fa03177c9b0580450eab87786063495d48b457762a5bdd20c55e2
MD5 1b2f065a0fe1c1cb35525201d6cd98ff
BLAKE2b-256 cba0af448af28514e82f36e7431bc88e933ad043e5a95a7985bd9458a05877c6

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 241c502532e348ba89200823326dba30de4df4b886cb2fd5a140b359ff124bb3
MD5 85934475447f576614296ca64c02fba9
BLAKE2b-256 1588a3710209f647d89358c81b5974aee48b1ab361fd016dcae81824e29ee645

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 a2c97a56ff8a0f6c273a83e26e627c72207442b4252aa550acad0bff42caac40
MD5 946923aca9a61af3ceae64772f2ae114
BLAKE2b-256 b32a03e6ff45cb772d249d4bf2d433a2acd2ec857615b3c1d44f0fa49e13aa63

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8b903edec1d803704b499959f9d6f6119cdda63b9b64194a4b4307e506b112f0
MD5 1477ae2f18bb61297c69b688620482ae
BLAKE2b-256 7f3c23304cf86c4af6014884bde046073105ace6250b6a0914c1090f2643d03c

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6ac68ae2515ece22ba3ef56f3d16ad6bf707955f650d623190b2e7d706c6dc92
MD5 d49044ef8dde92338fafb51f88c1ed40
BLAKE2b-256 2f2b494982ecc4618796aacb8069bc176d895cec4bf1ac8dd0b1d69657d920c4

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb518f5649e62d753e29ca1e57290c8f58adbebcd154dc3159f4a36ebfa1e2b7
MD5 453b53109f8a81938ac772020ef6a93f
BLAKE2b-256 031195350c7eeade2e61a736f1ca956ee04acb920b7b080ff0c058c40cc7bbf3

See more details on using hashes here.

Provenance

File details

Details for the file rustworkx-0.15.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rustworkx-0.15.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6cd4496d3298cd3205c03545e48cc37d21e0455d57752af801d3fb250452d590
MD5 e03f61381b492bc206056966e80886b0
BLAKE2b-256 3706adeed1d166c55920a6a83085e8c8c8b24c8d7708de99f7a814458a3c4529

See more details on using hashes here.

Provenance

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