High-Performance Computing at the NIH
GitHub YouTube @nih_hpc RSS Feed
graph-tool on Biowulf & Helix


From the graphtool documentation:

Graph-tool is an efficient Python module for manipulation and statistical analysis of graphs (a.k.a. networks). Contrary to most other python modules with similar functionality, the core data structures and algorithms are implemented in C++, making extensive use of template metaprogramming, based heavily on the Boost Graph Library. This confers it a level of performance that is comparable (both in memory usage and computation time) to that of a pure C/C++ library.

While graph-tool is essentially a python library it is installed as a separate application due to a number of dependencies. It contains python 3 with ipython and a number of useful python packages and is used through a wrapper called graph-tool

There may be multiple versions of graph-tool available. An easy way of selecting the version is to use modules. To see the modules available, type

module avail graph-tool 

To select a module use

module load graph-tool/[version]

where [version] is the version of choice.

graph-tool is a multithreaded application. Make sure to match the number of cpus requested with the number of threads. This is an OpenMP application and therefore the number of threads is determined by the OMP_NUM_THREADS environment variable.

Environment variables set



Interactive job on Biowulf

Allocate an interactive session with sinteractive and use as described below

biowulf$ sinteractive 
salloc.exe: Pending job allocation 38576483
salloc.exe: Nodes cn2399 are ready for job
node$ module load graph-tool
[+] Loading singularity 2.2.1 on cn2314
[+] Loading graph-tool 2.22

node$ graph-tool
    graph-tool [python|ipython] [options] [args]
    python  - start python interpeter with graph-tools
    ipython - start ipython interpreter with graph-tools
    Use to start up a python session with graph-tools plus some
    other modules

node$ graph-tool ipython
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import graph_tool.all as gt
In [2]: g = gt.price_network(1000)
In [3]: pos = gt.sfdp_layout(g)
In [4]: gt.graph_draw(g, pos=pos, output_size=(600, 600),
   ...: output="graph-tool-ex1.png", bg_color=(0.95, 0.95, 0.95, 1))
Out[4]: ', for Graph 0x2aaadd65f908, at 0x2aaadd5c30f0>

Creates the following graph in png format:

graph-tool example 1

If you have X11 forwarding set up, leaving out 'output' from the graph_draw call will create an interactive window.

Another example continuing the session above:

In [5]: from numpy import sqrt
In [6]: deg = g.degree_property_map("in")
In [7]: deg.a = 4 * (sqrt(deg.a) * 0.5 + 0.4)
In [8]: ebet = gt.betweenness(g)[1]
In [10]: ebet.a /= ebet.a.max() / 10.
In [11]: eorder = ebet.copy()
In [12]: eorder.a *= -1
In [13]: pos = gt.sfdp_layout(g)
In [14]: control = g.new_edge_property("vector<double>")
In [15]: for e in g.edges():
    ...:     d = sqrt(sum((pos[e.source()].a - pos[e.target()].a) ** 2)) / 5
    ...:     control[e] = [0.3, d, 0.7, d]
In [16]: gt.graph_draw(g, pos=pos, vertex_size=deg, vertex_fill_color=deg, vorder=deg,
    ...:               edge_color=ebet, eorder=eorder, edge_pen_width=ebet,
    ...:               edge_control_points=control, # some curvy edges
    ...:               output_size=(600, 600), bg_color=(0.95, 0.95, 0.95, 1),
    ...:               output="graph-tool-ex2.png")
Out[16]: ', for Graph 0x2aaadd65f908, at 0x2aaadd509d68>
graph-tool example 2
Batch job on Biowulf

Create a batch script similar to the following example:

#! /bin/bash
# this file is graph-tool-test.sh

module load graph-tool || exit 1

# note that this is python 3
graph-tool python graph python graph-tool-test.py

Submit to the queue with sbatch:

biowulf$ sbatch graph-tool-test.sh