• Stars
    star
    1,097
  • Rank 42,257 (Top 0.9 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A high performance Python graph library implemented in Rust.

rustworkx

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

|⚠️| The retworkx project has been renamed to rustworkx. The use of the retworkx package will still work for the time being but starting in the 1.0.0 release retworkx will no longer be supported

rustworkx is a general purpose graph library for Python written in Rust to take advantage of the performance and safety that Rust provides. It is designed to provide a high performance general purpose graph library for any Python application.

Project history

Rustworkx was originally called retworkx and was 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-terra'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.

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.64 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.

Using rustworkx

Once you have rustworkx installed you can use it by importing rustworkx. All the functions and graph classes are off the root of the package. For example, calculating the shortest path between A and C would be:

import rustworkx

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)

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.

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.

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

More Repositories

1

qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
Python
5,189
star
2

qiskit-metapackage

Qiskit is an open-source SDK for working with quantum computers at the level of circuits, algorithms, and application modules.
OpenQASM
3,028
star
3

qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Jupyter Notebook
2,324
star
4

qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
C++
490
star
5

textbook

Source content for the Qiskit Textbook
Jupyter Notebook
349
star
6

qiskit-ibmq-provider

Qiskit Provider for accessing the quantum devices and simulators at IBM Quantum.
Python
242
star
7

qiskit-ibm-runtime

IBM Client for Qiskit Runtime
Python
152
star
8

platypus

Qiskit Textbook (beta)
Jupyter Notebook
134
star
9

ecosystem

The Ecosystem consists of projects, tools, utilities, libraries and tutorials from a broad community of developers and researchers. The goal of the Ecosystem is to recognize, support and accelerate development of quantum technologies using Qiskit.
Python
102
star
10

qiskit.org

The Qiskit official website
TypeScript
101
star
11

qiskit-addon-cutting

Reduce width and depth of quantum circuits by cutting gates and wires.
Python
78
star
12

qiskit-ibm-provider

Qiskit Provider for accessing the IBM Quantum Services: Online Systems and Simulators
Python
77
star
13

qiskit-serverless

A programming model for leveraging quantum and classical resources
Python
67
star
14

feedback

A place to share your feedback on Qiskit; stay up to date with release planning and DemoDays; and find out where to get support
Jupyter Notebook
61
star
15

qiskit-code-assistant-vscode

Simplifying Qiskit to make developing quantum circuits and applications faster
HTML
59
star
16

documentation

The documentation content home for https://docs.quantum.ibm.com.
TypeScript
38
star
17

RFCs

RFCs for changes to Qiskit ecosystem
34
star
18

web-components

Qiskit Web Components
TypeScript
21
star
19

red-queen

Quantum software benchmarking tool
OpenQASM
18
star
20

benchpress

OpenQASM
18
star
21

qiskit-bot

Github bot to automate various aspects of Qiskit development
Python
17
star
22

ibm-quantum-schemas

IBM Quantum API Schemas
Python
16
star
23

qiskit-qasm3-import

Importer from OpenQASM 3 to Qiskit's QuantumCircuit
Python
16
star
24

qiskit-ibm-transpiler

Jupyter Notebook
16
star
25

qiskit_sphinx_theme

A Sphinx theme and documentation guidelines for Qiskit and Qiskit Ecosystem projects
SCSS
15
star
26

openqasm3_parser

Parser and semantic analyzer for the OpenQASM3 language
Rust
11
star
27

qiskit-neko

An integration test suite for Qiskit
Python
10
star
28

saiba

Qiskit Learning
Vue
9
star
29

qiskit-ibm-catalog

Python
6
star
30

gh-actions

Reusable workflows and composite actions
4
star
31

platypus-binder

Repository that handles the binder configuration for platypus
Python
3
star
32

qiskit-addon-dice-solver

2
star
33

qiskit-addon-sqd

2
star
34

qiskit-addon-mpf

2
star
35

qiskit-addon-obp

2
star
36

qiskit-addon-aqc-tensor

Python
1
star
37

qiskit-code-assistant-jupyterlab

1
star
38

qiskit-addon-utils

1
star