# DMRGObserver

A DMRGObserver is a type of observer which offers certain useful, general purpose capabilities for DMRG calculations such as measuring custom local observables at each step and stopping DMRG early if certain energy convergence conditions are met.

In addition to the example code below, more detailed example code showing sample usage of DMRGObserver is included in the ITensor source, in the file `1d_ising_with_observer.jl`

under the folder `examples/dmrg`

.

## Sample Usage

In the following example, we have already made a Hamiltonian MPO `H`

and initial MPS `psi0`

for a system of spins whose sites have an associated "Sz" operator defined. We construct a `DMRGObserver`

which measures "Sz" on each site at each step of DMRG, and also stops the calculation early if the energy no longer changes to a relative precision of 1E-7.

```
Sz_observer = DMRGObserver(["Sz"],sites,energy_tol=1E-7)
energy, psi = dmrg(H,psi0,sweeps,observer=Sz_observer)
for (sw,Szs) in enumerate(measurements(Sz_observer)["Sz"])
println("Total Sz after sweep $sw = ", sum(Szs)/N)
end
```

## Constructors

`ITensors.DMRGObserver`

— Method```
DMRGObserver(;energy_tol=0.0,
minsweeps=2,
energy_type=Float64)
```

Construct a DMRGObserver by providing the energy tolerance used for early stopping, and minimum number of sweeps that must be done.

Optional keyword arguments:

- energy_tol: if the energy from one sweep to the next no longer changes by more than this amount, stop after the current sweep
- minsweeps: do at least this many sweeps
- energy_type: type to use when storing energies at each step

`ITensors.DMRGObserver`

— Method```
DMRGObserver(ops::Vector{String},
sites::Vector{<:Index};
energy_tol=0.0,
minsweeps=2,
energy_type=Float64)
```

Construct a DMRGObserver, provide an array of `ops`

of operator names which are strings recognized by the `op`

function. Each of these operators will be measured on every site during every step of DMRG and the results recorded inside the DMRGOberver for later analysis. The array `sites`

is the basis of sites used to define the MPS and MPO for the DMRG calculation.

Optionally, one can provide an energy tolerance used for early stopping, and minimum number of sweeps that must be done.

Optional keyword arguments:

- energy_tol: if the energy from one sweep to the next no longer changes by more than this amount, stop after the current sweep
- minsweeps: do at least this many sweeps
- energy_type: type to use when storing energies at each step

## Methods

`ITensors.measurements`

— Method`measurements(o::DMRGObserver)`

After using a DMRGObserver object `o`

within a DMRG calculation, retrieve a dictionary of measurement results, with the keys being operator names and values being DMRGMeasurement objects.

`ITensors.DMRGMeasurement`

— TypeA DMRGMeasurement object is an alias for `Vector{Vector{Float64}}`

, in other words an array of arrays of real numbers.

Given a DMRGMeasurement `M`

,the result for the measurement on sweep `n`

and site `i`

as `M[n][i]`

.

`ITensors.energies`

— Method`energies(o::DMRGObserver)`

After using a DMRGObserver object `o`

within a DMRG calculation, retrieve an array of the energy after each sweep.