# 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 -local operators:

where the operators 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 .

## Specifying the local Hilbert space

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

where each can take values in the set .

Parameter | Possible values | Description | Default value |
---|---|---|---|

`QuantumNumbers` |
List of floats | A set of local quantum numbers . They do not need to be ordered or be consecutive. | None |

`Size` |
Integer | The total number of lattice sites | None |

### Example

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

## Local Operators

The local operators 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 , and with a local Hilbert space of two elements , you must provide a matrix

In general, for a -local operator acting on local Hilbert spaces with quantum numbers, you must provide a matrix

Parameter | Possible values | Description | Default value |
---|---|---|---|

`ActingOn` |
List of list of integers | The sites on which each acts on | None |

`Operators` |
List of floating/complex matrices | For each , the matrix elements of in the -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,
}
```

- Previous
- Next