API reference

Reading graphs

Reading graph files (read_graph_from_file) and one-time start-up (warm_up).

orbitsi.utils.read_graph_from_file(filepath, build_index=True)[source]

Read a graph file into a NetworkX graph.

The file is parsed in C++ straight into arrays (see Graph file format). The result is an orbitsi.arraygraph.ArrayGraph: a networkx.Graph whose node and adjacency dictionaries are built only when first used.

Parameters:
Returns:

networkx.Graph – The undirected graph, with each node’s label in its 'label' attribute.

Raises:

ValueError – If a v or e line has a missing or non-integer field, or an integer outside 64 bits.

orbitsi.utils.warm_up()[source]

Pay one-time library start-up costs now.

Runs filtering, ordering and counting once on a tiny graph with both backends, so that one-time start-up (NumPy’s first sort sets up its SIMD dispatch, about 50 ms; the first calls of other array routines and of the C++ extensions) is paid at load, not by the first pattern. Does nothing after its first call in a process.

class orbitsi.arraygraph.ArrayGraph(*args, backend=None, **kwargs)[source]

Bases: Graph

A networkx.Graph read into arrays, whose NetworkX dictionaries are built on first use.

orbitsi.utils.read_graph_from_file() returns one. Until its node or adjacency dictionaries are first read, GraphIndex and the C++ core use its arrays directly; number_of_nodes() and len() also work without them. Any other NetworkX use (iterating nodes or edges, copy(), subgraph(), mutation, NetworkX algorithms) builds them, in the order NetworkX would have built them from the same file, and the object then becomes a plain networkx.Graph. Pickling and deep copies keep it unbuilt.

Parameters:
  • incoming_graph_data (optional) – As for networkx.Graph; used only when arrays is None, in which case the result is a plain networkx.Graph.

  • arrays (tuple of numpy.ndarray, optional) – (node_ids, labels, has_label, offsets, nbors) as returned by _orbitsi_core.read_graph: node IDs in node order, each node’s label and whether it has one, and the adjacency in CSR form over node positions (the neighbours of node i are nbors[offsets[i]:offsets[i + 1]]).

  • **attr – Graph attributes, as for networkx.Graph.

number_of_nodes()[source]

The number of nodes, without building the NetworkX dictionaries.

C++ pipeline

OrbitSI’s count pipeline in C++ (the _orbitsi_core extension): the filter of orbitsi.search.FilterEngine, the matching orders of OrderEngine and the counting of SearchEngine.count, with the same semantics (the tests compare them). OrbitSIEngine.count() goes through it by default.

data_graph(G) builds the extension’s copy of a data graph once (cached with its GraphIndex; read_graph_from_file builds it at load); run(G, P, …) filters, orders and counts one pattern.

orbitsi.core.data_graph(G)[source]

The C++ core’s copy of data graph G, built on first use and cached with its GraphIndex.

Parameters:

G (networkx.Graph) – The data graph, with node labels in the 'label' attribute.

Returns:

_orbitsi_core.DataGraph

orbitsi.core.run(G, P, graphlet_size=4, order_method='auto', arc_consistency=False, contraction=True, edge_thinning=True, tail=True, stop='count', limit=0)[source]

Filter, order and count (or enumerate) the embeddings of pattern P in G, in C++.

Parameters:
  • G (networkx.Graph) – The data and pattern graphs, with node labels in the 'label' attribute.

  • P (networkx.Graph) – The data and pattern graphs, with node labels in the 'label' attribute.

  • graphlet_size ({4, 5}, default 4) – Graphlet size of the orbit filter (counted by EVOKE).

  • order_method ({'auto', 'core'}, default 'auto') – Matching order: OrbitSI’s orbit-strength order, or 2-core first (see orbitsi.search.OrderEngine).

  • arc_consistency (bool, default False) – Run arc consistency after NLF and after the orbit filter.

  • contraction (bool, default True) – Repeat NLF inside the candidate subgraph before the orbit filter.

  • edge_thinning (bool, default True) – Count orbits only on the candidate subgraph’s edges that some pattern edge can map onto.

  • tail (bool, default True) – Count the last pattern vertices together instead of searching them.

  • stop ({'count', 'order', 'filter'}, default 'count') – Stop after filtering or ordering instead of searching.

  • limit (int, default 0) – If positive, enumerate the embeddings one at a time (no tail or last-level counting) and stop after limit of them.

Returns:

dict – status (‘ok’, or ‘refuted’ if filtering leaves some pattern vertex without candidates); count (int: the number of embeddings, at most limit if one is set); limit_reached (bool); candidates ({pattern node: [data node IDs]}, empty when refuted); order (pattern nodes in matching order); orbit_subgraph (vertices and edges of the subgraph the orbits were counted on); times (milliseconds per stage).

orbitsi.core.count(G, P, **kwargs)[source]

The number of embeddings of pattern P in data graph G (keyword arguments as run()).

Orbit counting

class orbitsi.orbit.EVOKEOrbitCounter(G, size=4)[source]

Bases: object

Vertex orbit counts of a graph by EVOKE (graphlets of 4 or 5 vertices).

Parameters:
  • G (networkx.Graph) – The graph; self-loops are ignored.

  • size ({4, 5}, default 4) – Graphlet size: 15 orbits for 4, 73 for 5.

property converter

The OrbitMatrixConverter for induced counts, loaded on first use.

count_orbits()[source]

Count the non-induced orbits: {node: list of counts}, also kept in self.counts.

get_orbits(induced=False)[source]

The orbit counts, one row per node in sorted node order.

Parameters:

induced (bool, default False) – Induced counts instead of non-induced ones (EVOKE’s own).

Returns:

numpy.ndarray – An n x 15 (size 4) or n x 73 (size 5) int64 array.

static count_csr(offsets, nbors, size=4, orbits=None)[source]

Non-induced orbit counts of a graph in CSR form.

Parameters:
  • offsets (array_like of int) – The graph over vertices 0..n-1: the neighbours of vertex i are nbors[offsets[i]:offsets[i + 1]].

  • nbors (array_like of int) – The graph over vertices 0..n-1: the neighbours of vertex i are nbors[offsets[i]:offsets[i + 1]].

  • size ({4, 5}, default 4) – Graphlet size.

  • orbits (iterable of int, optional) – The orbits needed (None: all). At size 4, routines counting none of them are skipped, and the orbits only they count are left at 0.

Returns:

numpy.ndarray – An n x 15 or n x 73 int64 array.

class orbitsi.orbit.ORCAOrbitCounter(G, size=4)[source]

Bases: object

Vertex orbit counts of a graph by ORCA (graphlets of 4 vertices only).

Parameters:
  • G (networkx.Graph) – The graph; self-loops are ignored.

  • size ({4}, default 4) – Graphlet size (15 orbits).

count_orbits()[source]

Count the induced orbits: {node: list of counts}, also kept in self.counts.

get_orbits(induced=False)[source]

The orbit counts, one row per node in sorted node order.

Parameters:

induced (bool, default False) – Induced counts (ORCA’s own) instead of non-induced ones.

Returns:

numpy.ndarray – An n x 15 int64 array.

static count_csr(offsets, nbors, size=4, orbits=None)[source]

Non-induced orbit counts of a graph in CSR form.

Parameters:
  • offsets (array_like of int) – The graph over vertices 0..n-1: the neighbours of vertex i are nbors[offsets[i]:offsets[i + 1]].

  • nbors (array_like of int) – The graph over vertices 0..n-1: the neighbours of vertex i are nbors[offsets[i]:offsets[i + 1]].

  • size ({4}, default 4) – Graphlet size.

  • orbits (iterable of int, optional) – Accepted for EVOKEOrbitCounter.count_csr()’s interface; all orbits are counted.

Returns:

numpy.ndarray – An n x 15 int64 array.

class orbitsi.orbit.orbit_converter.OrbitMatrixConverter[source]

Bases: object

Converts vertex orbit counts between induced and non-induced.

Orbits are grouped by graphlet size: orbit 0 (an edge) is the same either way; orbits 1-3, 4-14 and 15-72 are related by the matrices for 3-, 4- and 5-vertex graphlets (non-induced = M @ induced). Each M is unit upper-triangular with integer entries, so its inverse is an integer matrix too, and both directions are exact in int64.

noninduced_to_induced(noninduced_matrix)[source]

Convert non-induced orbit counts (one row per vertex) to induced counts.

induced_to_noninduced(induced_matrix)[source]

Convert induced orbit counts (one row per vertex) to non-induced counts.