hiperwalk.Graph#
- class hiperwalk.Graph(adj_matrix, copy=False)[source]#
Constructs an arbitrary graph.
This class defines the graph structure used for implementing a quantum walk. It encapsulates all necessary properties and functionalities of the graph required for the quantum walk dynamics. This class also supports the creation of graphs with loops.
- Parameters:
- adj_matrix
The adjacency matrix of the graph (any integer Hermitian matrix). Two input types are accepted:
- Any matrix – for instance,
list of lists.
networkx.Graph.The adjacency matrix is extracted from the graph.
- copybool, default=False
If
True, a hard copy ofadj_matrixis stored. IfFalse, the pointer toadj_matrixis stored and theadj_matrix’s data is changed.
- Raises:
- TypeError
If
adj_matrixis not a square matrix.
Notes
The class methods facilitate the construction of a valid quantum walk and can be provided as parameters to plotting functions. For visualizations, the default graph representation will be used. Specific classes are available for well-known graph types, such as hypercubes and lattices.
The adjacency matrix is always stored as a
scipy.sparse.csr_array. Ifadj_matrixis sparse andcopy=False, the argument will be changed for more efficient manipulation.Each vertex has at most one loop.
Warning
To reduce memory usage,
adj_matrix.datais set toNone. This is possible becauseadj_matrix.datashould be an array of ones.If the user wishes to keep the original
adj_matrix, the argumentcopymust be set toTrue.The treatment of the graph depends on the quantum walk model.
The default order of neighbors is the ascending order. A different order of neighbors can be specified using a sparse matrix where
scipy.sparse.csr_array.has_sorted_indicesisFalse. In this case, the neighbors ofuare given byadj_matrix.indices[adj_matrix.indptr[u]:adj_matrix.indptr[u+1]].Examples
Creating a complete graph with loops and the default order of neighbors (ascending order).
>>> num_vert = 4 >>> A = scipy.sparse.csr_array([[1]*num_vert]*num_vert) >>> g = hpw.Graph(A) >>> g.neighbors(0) array([0, 1, 2, 3], dtype=int32) >>> g.neighbors(1) array([0, 1, 2, 3], dtype=int32)
Creating a complete graph with loops and the descending order of neighbors.
>>> data = [1]*(num_vert**2) >>> indices = list(range(num_vert - 1, -1, -1))*num_vert >>> indptr = list(range(0, num_vert*(num_vert + 1), num_vert)) >>> A = scipy.sparse.csr_array((data, indices, indptr)) >>> g = hpw.Graph(A) >>> g.neighbors(0) array([3, 2, 1, 0]) >>> g.neighbors(1) array([3, 2, 1, 0])
Methods
Return the adjacency matrix representation of the graph.
adjacent(u, v)Return True if vertex
uis adjacent tov.degree(vertex)Return the degree of the given vertex.
Return True if the graph has no multiedges or weights.
Return the graph's Laplacian matrix.
neighbors(vertex)Return all neighbors of the given vertex.
Return the total number of edges in the graph.
Return the number of loops in the graph.
Return the total number of vertices in the graph.
vertex_number(vertex)Return the numerical label of a vertex based on its representation.