Example codes: exact diagonalization
Please look at the readme page if you have not done so already. Here we present an implementation of exact diagonalization for a quantum manybody Hamiltonian composed of a sum of local terms. This code formats the quantum problem in such a way that it can be passed as an input to a standard sparse eigensolver, which then performs the exact diagonalization based on the Lanczos algorithm. Important, however, is that we never form the full Hamiltonian H as a matrix; instead the Hamiltonian is represented as a function that acts on an input state ψ> in order to output Hψ>. If we have a lattice of N sites of local dimension d, then the memory required using this approach scales as O(d^N), i.e. the memory required to represent a state ψ>, as opposed to scaling as O(d^(2N)), which would otherwise be required to represent H as a matrix. This implementation can comfortably handle chains of N = 25 or more spin1/2 sites when run on standard desktop / laptop PC's.

Scaling of memory: O(d^N)

Implemented for a finite chain with open or periodic boundaries
â€‹

Uses the Lanczos algorithm built into the standard 'eigs' function
Code Language:
MATLAB
Julia
Python
Exact diagonalization tutorial
The goal of this code to is to find lowenergy eigenstates of a Hamiltonian H, that is composed as a sum of local couplings `h`. In order to do this efficiently, we first write a function that computes HΨ> for an input quantum state Ψ>, by applying each of the `h` couplings singularly. This function can then be passed to a standard sparse eigensolver such as `eigs`.

applying the local couplings `h` to the state is most easily accomplished by using a tensordot function. This is builtin with numpy, and we provide custom versions for MATLAB and Julia.

the index ordering conventions for the state and the Hamiltonian are presented below.
Wavefunction:
Local Hamiltonian:
Index ordering conventions:
Function for applying the Hamiltonian
Initialization script
'mainExactDiag' benchmark:
â€‹
Method: Exact diagonalization (Lanczos method)
Test problem: 1D quantum XX model (on lattice of N = 18 sites with periodic boundaries)
Running time: approx 10 secs
Quantities computed: ground energy
â€‹
Typical results:
â€‹
Ground energy (exact diag): 23.035081932574503
Ground energy (analytic): 23.035081932574535