Skip to content

Not Using NetworkX

Jordan Matelsky edited this page Mar 18, 2021 · 1 revision

GrandIso was written for NetworkX-flavored graphs, but you may want to run the algorithm on a graph that lives in another graph/network toolkit library.

Our library, Grand (pip install grand-graph), is a library that enables you to run one graph algorithm on a graph stored in another library's format. For example, you can run IGraph algorithms on a NetworkX graph.

You should be able to use these libraries seamlessly by using the Grand networkx dialect:

import networkx as nx
import networkit as nk

from grand import Graph
from grand.backends.networkit import NetworkitBackend

from grandiso import find_motifs

# Create a new Erdős–Rényi graph using Networkit:
er = nk.generators.ErdosRenyiGenerator(50, 0.1).generate()

# Load the graph into a Grand backend:
nb = NetworkitBackend(graph=er)
g = Graph(backend=nb)

# Create a motif. This motif is a NetworkX graph (i.e.
# it would usually be incompatible with the `er` variable)
motif = nx.complete_graph(3)

# Using the `Grand.nx` dialect, we can search for motifs
# in the Networkit graph:
results = find_motifs(motif, g.nx)
[{0: 2, 2: 28, 1: 39},
 {0: 2, 2: 39, 1: 40},
 {0: 2, 2: 39, 1: 28},
 {0: 2, 2: 40, 1: 39},
 {0: 4, 2: 9, 1: 45},
 {0: 4, 2: 25, 1: 31},
 {0: 4, 2: 31, 1: 25},
 {0: 4, 2: 45, 1: 9},
 {0: 6, 2: 41, 1: 47},
 {0: 6, 2: 47, 1: 41},
 {0: 8, 2: 12, 1: 32},
 {0: 8, 2: 12, 1: 23},
 ...
]
Clone this wiki locally