package contents

Being a small package, perconet exposes only two classes.

PeriodicNetwork

class perconet.PeriodicNetwork(n: int, max_degree=6, verbose=False, dim=3)

Store and analyze the topology of a periodic net.

Periodic nets are graphs embedded in a periodic topology. This class stores the topology of such a graph for the case of a d-dimensional periodic box (a d-torus). The dimensionaly defaults to 3 for use in contexts where the box represents physical space, but the PeriodicNetwork and LoopFinder classes work for arbitrary dimension.

The class stores, for every edge in the graph, a d-dimensional vector indicating the boundary-wrapping properties of that edge. See PeriodicNetwork.add_edge for details. This information is then used by LoopFinder to determine the percolation properties.

Parameters
  • n (int) – The number of nodes of the graph.

  • max_degree (int) – The largest number of edges coming out of any node.

  • verbose (bool, optional) – Print debugging information to stdout. Defaults to False.

  • dim (int, optional) – Spatial dimension. Defaults to 3.

add_edge(node1: int, node2: int, boundary_vector)

Add an edge to the periodic network

Parameters
  • node1 (int) – The index of the first node of the pair that defines this edge. Valid values range from 0 up to (but not including) the number of nodes of the network (node indices are 0-based).

  • node2 (int) – The index of the second node of the pair that defines this edge. Valid values range from 0 up to (but not including) the number of nodes of the network (node indices are 0-based).

  • boundary_vector (List of int) – List (or numpy array) of integers denoting the number of times the edge wraps around each boundary, respectively. The length of this list must be equal to the dimensionality of the network (which defaults to 3 but can be overridden during initialization). The sign indicates the wrapping direction (e.g. (-1,0,0) indicates that the edge goes around the x-boundary in the negative x-direction when going from node1 to node2.

Returns

True if succesful. False if an error occurred.

Return type

(bool)

crosses_boundaries()

Check if the network contains any edges that cross a boundary.

Returns

True if the network has any edges that cross a boundary.

Return type

bool

decompose(internal_only=True)

Obtain the cluster decomposition of the network. This method is used by LoopFinder (using internal bonds only) to reduce the network for faster loop finding, but can also be used for generic cluster analysis.

Parameters

internal_only (bool, optional) – Defaults to True. If true, use only bonds that do not cross any boundary for the cluster decomposition.

Returns

A list with the cluster ID of each node and the number of clusters

Return type

Tuple[List of int, int]

get_boundary_crossing(node, nb_index)

Get the boundary crossing vector of the nb_index’th neighbor of node.

Parameters
  • node (int) – node number

  • nb_index (int) – index of neighbor in neighbor list of node

Returns

The list of integers denoting the number of times each boundary is crossed by this edge. Provided as a numpy array with length equal to the dimensionality of the network and dtype=int.

Return type

numpy.ndarray

get_edge(node, nb_index)

Get the edge number of the nb_index’th edge of node.

Parameters
  • node (int) – node number

  • nb_index (int) – index of neighbor in neighbor list of node

Returns

The edge number of that edge (to be used as an index in arrays of edge properties). A return value of -1 indicates that the edge does not exist.

Return type

int

get_edges(node, padded=True)

Get the list of edges linking to node.

Parameters
  • node (int) – The index of the node for which to return the edge list

  • padded (bool, optional) – If true (the default), the list will be padded with values -1 to the value of maximum_neighbors_per_node passed to the constructor. Otherwise the length will be the number of neighbors of node.

Returns

Numpy array (dtype=int) containing the edge numbers of all edges involving node.

Return type

numpy.ndarray

get_neighbor(node, nb_index)

Get nb_index’th neighbor of node.

Parameters
  • node (int) – node number

  • nb_index (int) – index of neighbor in neighbor list of node

Returns

The index of that neighbor (the value of get_neighbors(i)[nb_index]). A return value of -1 indicates that the edge does not exist.

Return type

int

get_neighbors(node, padded=True)

Get array of neighbor indices of node.

Parameters
  • node (int) – node number

  • padded (bool, optional) – If true (the default), the list will be padded with values -1 to the value of maximum_neighbors_per_node passed to the constructor. Otherwise the length will be the number of neighbors of i.

Returns

Numpy array (dtype=int) containing list of neighbors of node.

Return type

numpy.ndarray

get_number_of_edges()

Get total number of edges in network.

Returns

Total number of edges (bonds) in the network

Return type

int

get_number_of_neighbors(node)

Get the number of bonds of node.

Parameters

node (int) – node number

Returns

The number of edges (bonds) involving this node

Return type

int

get_reduced_network()

Generate the reduced network with identical boundary crossing properties but no internal edges.

Returns

The reduced network

Return type

PeriodicNetwork

needs_reducing()

Determine if the network could be reduced using internal connected component decomposition.

LoopFinder will perform this reduction automatically so there will not usually be a need for the user to call this function themselves.

Returns

True if the network has any edges that do not cross any boundary.

Return type

bool

LoopFinder

class perconet.LoopFinder(network, verbose=True)

Class implementing a depth-first search to determine the percolation directions of the network.

Parameters
  • network (perconet.PeriodicNetwork) – A PeriodicNetwork object representing the graph to analyze.

  • verbose (bool, optional) – Generate verbose output to stdout (to be replaced by Logging in future release)

get_independent_loops()

Generate a list of all linearly independent topologically nontrivial loops.

The list is returned in Hermite normal form. See Loop independence for details.

Returns

(list, int) A tuple containing a list of the independent loops and the length of that list. Each element of the list of loops is itself a list of the number of times each boundary is crossed by that loop.

Return type

Tuple[List of List of int, int]

get_loops()

Generate a raw list of boundary-crossing loops. Most use cases will require get_independent_loops() instead.

If the network contains any internal bonds, this routine performs a cluster reduction of the network before it starts, but this does not alter the PeriodicNetwork object that was used to construct this LoopFinder instance. If the reduced network is needed elsewhere, use PeriodicNetwork.get_reduced_network().

Returns

(list, int) A tuple containing a list of the raw loops and the length of that list. Each element of the list of loops is itself a list of the number of times each boundary is crossed by that loop.

Return type

Tuple[List of List of int, int]