The graph-tool documentation#
graph-tool is an efficient Python module for manipulation and statistical
analysis of graphs (a.k.a.
networks).
The graph_tool module provides a Graph class and
several algorithms that operate on it. The internals of this class, and of most
algorithms, are written in C++ for performance, using template
metaprogramming for
code specialization, and the Boost Graph Library.
graph-tool can be orders of magnitude
faster than Python-only
alternatives, and therefore it is especially suited for large-scale network
analysis.
In addition to its performance, graph-tool contains the following
features, which are currently not available in most other comparable packages:
Feature |
Description |
|---|---|
A framework built upon statistically principled approaches that avoid overfitting and are interpretable (see here and [1] for the reasons to avoid off-the-shelf methods available in other software packages). |
|
Support for OpenMP shared memory parallelism for several algorithms. |
|
Static and interactive, supporting animations and matplotlib integration. |
|
Graphs where nodes and edges are temporarily masked. These are first-class citizens in the library, and are accepted by every function. Due to the use of C++ template metaprogramming, this functionality comes at no performance cost when filtering is not being used. |
|
An efficient and fully documented format for network files. |
|
Integration with the Netzschleuder network data repository, enabling the loading of network data. |
|
Support for writing custom extensions in C++. |
Installing graph-tool#
Detailed installation instructions for various platforms are available here.
The simplest way to install it is to use conda:
conda create --name gt -c conda-forge graph-tool
conda activate gt
On HPC systems, graph_tool can also be used with
Apptainer/Singularity.
Getting started#
We recommend first reading the quick start guide, then the cookbook guides, and the examples in the submodules. Commonly asked questions are answered in the FAQ.
Asking questions and reporting bugs#
Questions about graph-tool can be asked in the discussion
forum.
Problems can be reported as issues in the git repository.
Before asking, please check whether the question has been asked before, or
whether a similar issue is open. When asking questions or reporting problems,
it is important to include 1. the exact graph-tool version; 2. the operating
system; and 3. a minimal working example that shows the problem.
The third item is essential, since with only the part of the code that is believed to cause the problem it is not possible to understand the context that may have contributed to it.
How to use the documentation#
Documentation is available in two forms: docstrings provided
with the code, and the full documentation available on
the graph-tool homepage.
We recommend exploring the docstrings using IPython, an advanced Python shell with TAB-completion and introspection capabilities.
The docstring examples assume that graph_tool.all has been imported as
gt:
>>> import graph_tool.all as gt
Code snippets are indicated by three greater-than signs:
>>> x = x + 1
Use the built-in help function to view a function’s docstring:
>>> help(gt.Graph)
Contents#
- Quick start guide
- Parallel algorithms
- Cookbook guides
- Inferring modular network structure
- Background: Nonparametric statistical inference
- The stochastic block model (SBM)
- Inferring the best partition
- Model selection
- Sampling from the posterior distribution
- Model class selection
- Edge weights and covariates
- Layered networks
- Assortative community structure
- Ordered community structure
- Constraining the partition
- Dealing with large networks
- References
- Uncertain network reconstruction
- Edge prediction as binary classification
- References
- Network reconstruction from dynamics and behavior
- Drawing graphs with
graph_draw() - References
- Animations with
graph-tool - Integration with matplotlib
- Writing extensions in C++
- Submodules
graph_toolgraph_tool.centralitygraph_tool.clusteringgraph_tool.collectiongraph_tool.correlationsgraph_tool.dynamicsgraph_tool.drawgraph_tool.flowgraph_tool.generationgraph_tool.inferencegraph_tool.searchgraph_tool.spectralgraph_tool.statsgraph_tool.structure- Shortest paths
- Distances, eccentricity, and centers
- Distance-based indices and small-world measures
- Paths, walks, and cycles
- Components and connectivity
- Core decompositions
- Cuts and expansion
- Spanning trees
- Trees
- Directed graphs
- d-separation and graphical models
- Chordal graphs and treewidth
- Cliques
- Matchings, independent sets, and covers
- Coloring
- Combinatorial optimization
- Graph comparison and isomorphism
- Vertex similarity and link prediction
- Planarity
- Graph classes
- Graph polynomials
graph_tool.util
- The
gtfile format - FAQ
References#
Tiago P. Peixoto. Descriptive vs. Inferential Community Detection in Networks: Pitfalls, Myths and Half-Truths. Elements in the Structure and Dynamics of Complex Networks, July 2023. arXiv:2112.00183, doi:10.1017/9781009118897, [sci-hub].