# Custom Hamiltonians

NetKet provides the freedom to define user’s defined Hamiltonians, just specifying the relevant operators in the Hamiltonian section of the input. For the moment, this functionality is limited to lattice Hamiltonians which are sums of $k$ -local operators:

where the operators $h_i$ act on an (arbitrary) subset of sites. In order to define your custom Hamiltonian, you need to specify both the local Hilbert space and the operators $h_i$.

## Specifying the local Hilbert space

The Hilbert space here is constructed as the tensor product of $L$ local Hilbert spaces in such a way that the many-body quantum numbers are

where each $s_i$ can take values in the set $n_1 n_2 \dots$.

Parameter Possible values Description Default value
QuantumNumbers List of floats A set of local quantum numbers $n_1 n_2 \dots$. They do not need to be ordered or be consecutive. None
Size Integer The total number of lattice sites $L$ None

### Example

pars['Hilbert']={
'QuantumNumbers' : [1,-1],
'Size'           : L,
}


## Local Operators

The local operators $h_i$ are specified giving their matrix elements, and a list of sites on which they act. For example, to specify a single-site operator acting on site $l$, and with a local Hilbert space of two elements $n_1, n_2$, you must provide a $2 \times 2$ matrix

In general, for a $k$-local operator acting on local Hilbert spaces with $b$ quantum numbers, you must provide a $b^k \times b^k$ matrix

Parameter Possible values Description Default value
ActingOn List of list of integers The sites on which each $h_i$ acts on None
Operators List of floating/complex matrices For each $i$, the matrix elements of $h_i$ in the $k$-local Hilbert space None

### Example

#Transverse-Field Ising model on L site
import numpy as np

sigmax=[[0,1],[1,0]]
sigmaz=[[1,0],[0,-1]]

mszsz=(np.kron(sigmaz,sigmaz)).tolist()

#Now we define the local operators of our hamiltonian
#And the sites on which they act
#Notice that the Transverse-Field Ising model as defined here has sign problem
operators=[]
sites=[]
L=20
for i in range(L):
#\sum_i sigma^x(i)
operators.append(sigmax)
sites.append([i])
#\sum_i sigma^z(i)*sigma^z(i+1)
operators.append(mszsz)
sites.append([i,(i+1)%L])

pars['Hamiltonian']={
'ActingOn'       : sites,
'Operators'      : operators,
}