Custom Graphs

In addition to Built-in graphs NetKet provides the freedom to define user’s defined graphs, just specifying either the adjacency matrix or the edges list in the Graph section of the input.

For each and , the adjacency matrix of a graph contains the -th neighbor of node . For example, the adjacency matrix of linear lattice would simply be and (ignoring boundary effects here). The edges list contains instead the list of graph bonds. In the previous example, it would be .

Parameter Possible values Description Default value
AdjacencyList Matrix of Integers The adjacency list of the custom graph None
Automorphisms Matrix of Integers The automorphisms of the graph Identity Automorphism
Edges Matrix of Integers The adjacency list of the custom graph None
EdgeColors Map of integer pair to integers The coloring of each edge of the custom graph 0
IsBipartite Boolean Whether the graph is bipartite False

A powerful way of including graphs beyond the few Built-in ones is to use edge lists generated by NetworkX. An example is given below.

Example

import networkx as nx

#Generating a star graph with 11 nodes
#here 10 nodes are connected to a central node
G=nx.star_graph(10);

pars['Graph']={
    'Edges': G.edges(),
}

Automorphisms

More advanced wave functions make use of symmetries to reduce the number of parameters to be learned. For those, it is crucial to have a graph with symmetries. Symmetries for custom graphs can be specified giving a list of automorphisms, through the parameter Automorphisms. A very convenient way to automatically find all the automorphisms of an arbitrary graph is to use dedicated algorithms (find out more here). A Python package where those tools are implemented is python-igraph.

Example

import igraph as ig

#Generating a 4x4 square lattice with periodic boundaries
G=ig.Graph.Lattice([4,4])

pars['Graph']={
    'Edges': G.get_edgelist(),
    'Automorphisms' : G.get_isomorphisms_vf2(),
    'IsBipartite' : G.is_bipartite()
}

Notice that in the example given above, igraph will automatically find all the symmetries of the square lattice, including translations and reflections.

Coloring

If users want to specify the color of the edges they should create the graph by specifying the ‘Edges’ parameter as described above. If users want to specify more than one color, they can set the ‘EdgeColors’ parameter of the graph as a list of integers. The ordering of these colors should match the ordering of the list of edges.

Example

# Define custom graph
G = nx.Graph()
for i in range(L):
    G.add_edge(i, (i + 1) % L, color=1)
    G.add_edge(i, (i + 2) % L, color=2)

edge_colors = [[u, v, G[u][v]['color']] for u, v in G.edges]

# Specify custom graph
pars['Graph'] = {
    'Edges': list(G.edges),
    'EdgeColors': edge_colors,
}