This page was generated from docs/source/user_guide/graph.ipynb.

Graphs and Graph Routines#

The library only provides a few tools for graphs, related to algorithms for bandwith reduction, such as the calculation of pseudo peripheral nodes and rooted level structures.

The Graph class is a subclass of the Graph class from networkx, with a few additions.

[1]:
from sigmaepsilon.math.graph import Graph
import networkx as nx

grid = nx.grid_2d_graph(5, 5)  # 5x5 grid
G = Graph(grid)

One of these additions is that it is possible to get the adjacency matrix of a graph directly, by calling the adjacency_matrix method of an instance. The method returns a Numba-jittable instance of the csr_matrix class from sigmaepsilon.math.linalg, hence making the graph instance itself sort of Numba-jittable as well.

[2]:
G.adjacency_matrix()
[2]:
<Compressed Sparse Row sparse array of dtype 'int32'
        with 80 stored elements and shape (25, 25)>

The Graph class in sigmaepsilon.math.graph is also equipped with methods for the calculation of pseudo peripheral nodes and rooted level structures.

[3]:
G.pseudo_peripheral_nodes()
[3]:
array([24,  0], dtype=int64)
[4]:
G.rooted_level_structure()
[4]:
DictType[int64,array(int64, 1d, C)]<iv=None>({0: [0], 1: [1 5], 2: [ 2  6 10], 3: [ 3  7 11 15], 4: [ 4  8 12 16 20], 5: [ 9 13 17 21], 6: [14 18 22], 7: [19 23], 8: [24]})