Package: rustworkx
rustworkxYou can see the full rendered docs at:https://www.rustworkx.org/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 historyRustworkx was originally called retworkx and was created initially to be
a replacement forqiskit'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 ofqiskit-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 rustworkxrustworkx 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:pipinstallrustworkxThis will install a precompiled version of rustworkx into your python
environment.Installing on a platform without precompiled binariesIf 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
alsocargowhich is normally included with
rust) You can userustup(a cross platform installer for
rust) to make this simpler, or rely onother installation methods.
A source package is also published on pypi, so you still can also run the abovepipcommand to install it. Once you have rust properly installed, running:pipinstallrustworkxwill 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 installedsetuptools-rustprior to runningpip install rustworkx. If you recieve an
error aboutsetuptools-rustnot being found you should upgrade pip withpip install -U pipor manually installsetuptools-rustwithpip install setuptools-rustand try again.Optional dependenciesIf you're planning to use therustworkx.visualizationmodule you will need to
install optional dependencies to use the functions. The matplotlib based drawer
functionrustworkx.visualization.mpl_drawrequires that thematplotliblibrary is installed. This can be
installed withpip install matplotlibor when you're installing rustworkx withpip install 'rustworkx[mpl]'. If you're going to use the graphviz based drawer
functionrustworkx.visualization.graphviz_drawerfirst 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 thepillowPython library.
This can be done either withpip install pillowor when installing rustworkx
withpip install 'rustworkx[graphviz]'.If you would like to install all the optional Python dependencies when you
install rustworkx you can usepip install 'rustworkx[all]'to do this.Using rustworkxOnce 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:importrustworkxgraph=rustworkx.PyGraph()# Each time add node is called, it returns a new node indexa=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 indicesgraph.add_edges_from([(a,b,1.5),(a,c,5.0),(b,c,2.5)])# Returns the path A -> B -> Crustworkx.dijkstra_shortest_paths(graph,a,c,weight_fn=float)Building from sourceThe first step for building rustworkx from source is to clone it locally
with:gitclonehttps://github.com/Qiskit/rustworkx.gitrustworkx usesPyO3andsetuptools-rustto 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 usingpip. 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:pipinstall.Assuming your current working directory is still the root of the repo.
Otherwise you can run:pipinstall$PATH_TO_REPO_ROOTwhich 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 rerunningpip installto have any
changes reflected in your python environment.Develop ModeIf you'd like to build rustworkx in debug mode and use an interactive debugger
while working on a change you can usepython setup.py developto 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 usingpip installand should only be used for debugging/development.It's worth noting thatpip install -edoes 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 usepython setup.py develop.Authors and Citationrustworkx is the work ofmany peoplewho contribute
to the project at different levels. If you use rustworkx in your research, please cite ourpaperas per the includedBibTeX file.CommunityBesides 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 workspacehere. Additionally,
there is an IRC channel#rustworkxon theOFTC IRC network