netket.operator.GraphOperator
netket.operator.GraphOperator#
- class netket.operator.GraphOperator#
Bases:
netket.operator.LocalOperator
A graph-based quantum operator. In its simplest terms, this is the sum of local operators living on the edge of an arbitrary graph.
- Inheritance
- __init__(hilbert, graph, site_ops=[], bond_ops=[], bond_ops_colors=[], dtype=None, *, acting_on_subspace=None)[source]#
A graph-based quantum operator. In its simplest terms, this is the sum of local operators living on the edge of an arbitrary graph.
A
GraphOperator
is constructed giving a hilbert space and either a list of operators acting on sites or a list acting on the bonds. Users can specify the color of the bond that an operator acts on, if desired. If none are specified, the bond operators act on all edges.- Parameters
hilbert (
AbstractHilbert
) β Hilbert space the operator acts on.graph (
AbstractGraph
) β The graph whose vertices and edges are considered to construct the operatorsite_ops β A list of operators in matrix form that act on the nodes of the graph. The default is an empty list. Note that if no site_ops are specified, the user must give a list of bond operators.
bond_ops β A list of operators that act on the edges of the graph. The default is None. Note that if no bond_ops are specified, the user must give a list of site operators.
bond_ops_colors β A list of edge colors, specifying the color each bond operator acts on. The default is an empty list.
dtype (
Optional
[Any
]) β Data type type of the matrix elements.acting_on_subspace (
Union
[List
[int
],int
,None
]) β Specifies the mapping between nodes of the graph and Hilbert space sites, so that graph nodei β [0, ..., graph.n_nodes]
, corresponds toacting_on_subspace[i] β [0, ..., hilbert.n_sites]
. Must be a list of length graph.n_nodes. Passing a single integerstart
is equivalent to[start, ..., start + graph.n_nodes - 1]
.
Examples
Constructs a
GraphOperator
operator for a 2D system.>>> import netket as nk >>> sigmax = [[0, 1], [1, 0]] >>> mszsz = [[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]] >>> edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], ... [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], ... [15, 16], [16, 17], [17, 18], [18, 19], [19, 0]] >>> g = nk.graph.Graph(edges=edges) >>> hi = nk.hilbert.CustomHilbert(local_states=[-1, 1], N=g.n_nodes) >>> op = nk.operator.GraphOperator( ... hi, site_ops=[sigmax], bond_ops=[mszsz], graph=g) >>> print(op) GraphOperator(dim=20, #acting_on=40 locations, constant=0.0, dtype=float64, graph=Graph(n_nodes=20, n_edges=20))
- Attributes
- H#
Returns the Conjugate-Transposed operator
- Return type
- T#
Returns the transposed operator
- Return type
- acting_on#
List containing the list of the sites on which every operator acts.
Every operator self.operators[i] acts on the sites self.acting_on[i]
- acting_on_subspace#
Mapping between nodes of the graph and Hilbert space sites as given in the constructor.
- graph#
The graph on which this Operator is defined
- Return type
- hilbert#
The hilbert space associated to this operator.
- Return type
- mel_cutoff#
The cutoff for matrix elements. Only matrix elements such that abs(O(i,i))>mel_cutoff are considered
- operators#
List of the matrices of the operators encoded in this Local Operator. Returns a copy.
- Methods
- __call__(v)#
Call self as a function.
- Return type
- Parameters
v (numpy.ndarray) β
- apply(v)#
- Return type
- Parameters
v (numpy.ndarray) β
- collect()#
Returns a guaranteed concrete instance of an operator.
As some operations on operators return lazy wrappers (such as transpose, hermitian conjugateβ¦), this is used to obtain a guaranteed non-lazy operator.
- Return type
- conj(*, concrete=False)#
- Return type
- conjugate(*, concrete=False)#
LocalOperator: Returns the complex conjugate of this operator.
- copy(*, dtype=None)#
Returns a copy of the operator, while optionally changing the dtype of the operator.
- get_conn(x)#
Finds the connected elements of the Operator. Starting from a given quantum number x, it finds all other quantum numbers xβ such that the matrix element \(O(x,x')\) is different from zero. In general there will be several different connected states xβ satisfying this condition, and they are denoted here \(x'(k)\), for \(k=0,1...N_{\mathrm{connected}}\). :type x:
ndarray
:param x: An array of shape (hilbert.size) containing the quantum numbers x. :type x:array
- Returns
The connected states xβ of shape (N_connected,hilbert.size) array: An array containing the matrix elements \(O(x,x')\) associated to each xβ.
- Return type
matrix
- Raises
ValueError β If the given quantum number is not compatible with the hilbert space.
- Parameters
x (numpy.ndarray) β
- get_conn_filtered(x, sections, filters)#
Finds the connected elements of the Operator using only a subset of operators. Starting from a given quantum number x, it finds all other quantum numbers xβ such that the matrix element \(O(x,x')\) is different from zero. In general there will be several different connected states xβ satisfying this condition, and they are denoted here \(x'(k)\), for \(k=0,1...N_{\mathrm{connected}}\).
This is a batched version, where x is a matrix of shape (batch_size,hilbert.size).
- Parameters
x (
matrix
) β A matrix of shape (batch_size,hilbert.size) containing the batch of quantum numbers x.sections (
array
) β An array of size (batch_size) useful to unflatten the output of this function. See numpy.split for the meaning of sections.filters (
array
) β Only operators op(filters[i]) are used to find the connected elements of x[i].
- Returns
The connected states xβ, flattened together in a single matrix. array: An array containing the matrix elements \(O(x,x')\) associated to each xβ.
- Return type
matrix
- get_conn_flattened(x, sections, pad=False)#
Finds the connected elements of the Operator. Starting from a given quantum number x, it finds all other quantum numbers xβ such that the matrix element \(O(x,x')\) is different from zero. In general there will be several different connected states xβ satisfying this condition, and they are denoted here \(x'(k)\), for \(k=0,1...N_{\mathrm{connected}}\).
This is a batched version, where x is a matrix of shape (batch_size,hilbert.size).
- Parameters
x (
matrix
) β A matrix of shape (batch_size,hilbert.size) containing the batch of quantum numbers x.sections (
array
) β An array of size (batch_size) useful to unflatten the output of this function. See numpy.split for the meaning of sections.pad (
bool
) β Whether to use zero-valued matrix elements in order to return all equal sections.
- Returns
The connected states xβ, flattened together in a single matrix. array: An array containing the matrix elements \(O(x,x')\) associated to each xβ.
- Return type
matrix
- get_conn_padded(x)#
Finds the connected elements of the Operator.
Starting from a batch of quantum numbers \(x={x_1, ... x_n}\) of size \(B \times M\) where \(B\) size of the batch and \(M\) size of the hilbert space, finds all states \(y_i^1, ..., y_i^K\) connected to every \(x_i\).
Returns a matrix of size \(B \times K_{max} \times M\) where \(K_{max}\) is the maximum number of connections for every \(y_i\).
- Parameters
x (
ndarray
) β A N-tensor of shape \((...,hilbert.size)\) containing the batch/batches of quantum numbers \(x\).- Returns
The connected states xβ, in a N+1-tensor and an N-tensor containing the matrix elements \(O(x,x')\) associated to each xβ for every batch.
- Return type
(x_primes, mels)
- n_conn(x, out=None)#
Return the number of states connected to x.
- Parameters
x (
matrix
) β A matrix of shape (batch_size,hilbert.size) containing the batch of quantum numbers x.out (
array
) β If None an output array is allocated.
- Returns
The number of connected states xβ for each x[i].
- Return type
array
- to_dense()#
Returns the dense matrix representation of the operator. Note that, in general, the size of the matrix is exponential in the number of quantum numbers, and this operation should thus only be performed for low-dimensional Hilbert spaces or sufficiently sparse operators.
This method requires an indexable Hilbert space.
- Return type
- Returns
The dense matrix representation of the operator as a Numpy array.
- to_linear_operator()#
- to_qobj()#
Convert the operator to a qutipβs Qobj.
- Returns
A
qutip.Qobj
object.
- to_sparse()#
Returns the sparse matrix representation of the operator. Note that, in general, the size of the matrix is exponential in the number of quantum numbers, and this operation should thus only be performed for low-dimensional Hilbert spaces or sufficiently sparse operators.
This method requires an indexable Hilbert space.
- Return type
- Returns
The sparse matrix representation of the operator.
- transpose(*, concrete=False)#
LocalOperator: Returns the transpose of this operator.