Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leburgel committed Jun 21, 2022
1 parent 90c3791 commit 677768a
Show file tree
Hide file tree
Showing 137 changed files with 14,365 additions and 1,718 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.ipynb_checkpoints/*
*-checkpoint.ipynb
.ipynb_checkpoints
*~
*.pyc
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# BadHonnefTutorial
# uniformMpsTutorial

This repository contains the files for the tutorial sessions on tangent space methods for uniform matrix product stats, given at the 2020 school on Tensor Network based approaches to Quantum Many-Body Systems, held in Bad Honnef.
This repository contains a tutorial on tangent space methods for uniform matrix product states, originally written to be taught at the [2020 school on Tensor Network based approaches to Quantum Many-Body Systems](http://quantumtensor.pks.mpg.de/index.php/schools/2020-school/) held in Bad Honnef, Germany. The tutorials are based on the lecture notes ['Tangent-space methods for uniform matrix product states'](https://doi.org/10.21468/SciPostPhysLectNotes.7) by Laurens Vanderstraeten, Jutho Haegeman and Frank Verstraete.

## Setup and installation

The tutorial is given in the form of Python notebooks, which provide a detailed guide through the relevant concepts and algorithms, interspersed with checks and demonstrations. Reference implementations are also given in MATLAB.
The tutorial is given in the form of IPython Notebooks, which provide a detailed guide through the relevant concepts and algorithms, interspersed with checks and demonstrations. Reference implementations are also given in MATLAB.

The easiest way to get all of the tools needed to open and run the notebooks is to install Python via the anaconda distribution: https://docs.anaconda.com/anaconda/install/. This automatically comes with all packages needed for this tutorial.

If you already have a python version installed, you may install the jupyter notebook package seperately through <code>pip</code> by running
If you already have a python version installed, you may [install Jupyter](https://jupyter.org/install) seperately via the [Python Package Index](https://pypi.org/) by running
```console
pip install notebook
```
Expand All @@ -18,7 +18,7 @@ Once jupyter notebook is installed, clone this repository to a local folder of y
jupyter notebook
```

For performing contractions of tensor networks, we have opted to use the Python implementation of the <code>ncon</code> contractor (https://arxiv.org/abs/1402.0939), which can be found at https://github.com/mhauru/ncon. There are undoubtedly many contraction tools that work equally well and any of them may of course be used, but this one has a particularly intuituve and handy syntax. To install ncon, you may run
For performing contractions of tensor networks, we have opted to use the Python implementation of the [<code>ncon</code> contractor](https://arxiv.org/abs/1402.0939), which can be found at https://github.com/mhauru/ncon. There are undoubtedly many contraction tools that work equally well and any of them may of course be used, but this one has a particularly intuituve and handy syntax. To install ncon, you may run
```console
pip install ncon
```
Expand All @@ -33,13 +33,11 @@ The tutorial consists of three parts:
This part is concerned with the basics of MPS in the thermodynamic limit: normalization, fixed points, algorithms for gauging an MPS, and computing expectation values.

#### 2. Finding ground states of local Hamiltonians
This part describes how to perform a variational search in the space of MPS to find the ground state of a local Hamiltonian. We start by considering a simple gradient based approach, and then introduce the vumps algorithm. We also briefly touch upon how excited states may be constructed using the result of the vumps ground state search.
This part describes how to perform a variational search in the space of MPS to find the ground state of a local Hamiltonian. We start by considering a simple gradient based approach, and then introduce the [VUMPS algorithm](https://journals.aps.org/prb/abstract/10.1103/PhysRevB.97.045145). We also briefly touch upon how excited states may be constructed using the result of the VUMPS ground state search. The algorithms are demonstrated for the case of the one-dimensional quantum spin-1 Heisenberg model.

#### 3. Transfer matrices and fixed points
In this part the vumps algorithm is extended to matrix product operators (MPOs), and it is then used to compute the partition function and magnetization for the 2d classical Ising model.
In this part the VUMPS algorithm is extended to transfer matrices in the form of matrix product operators (MPOs), which can then be used to contract infinite two-dimensional tensor networks. The algorithm is demonstrated for the case of the classical two-dimensional Ising model, and is for example used to compute its partition function and evaluate the expectation value of the magnetization.


## Use of this tutorial
Each chapter provides a jupyter notebook (.ipynb) file with guided exercices on implementing the algorithms, as well as a solution notebook. Similar files are available for MATLAB.

The approach itself is very basic, where all algorithms are broken down and illustrated in digestible steps. The implementations are very simple: there are no black boxes or fancy tricks involved, everything is built from the ground up. As a result, implementing all these steps from the start would most likely take longer than two tutorial sessions. The contents of the tutorial should therefore not just be seen as a task to complete, but just as much as a reference on how one would go about implementing these concepts. Please feel free to use this in any way you see fit.
Each chapter provides a notebook (.ipynb) file with guided exercices on implementing the algorithms, as well as a solution notebook. Similar files are available for MATLAB. The approach itself is very basic, where all algorithms are broken down and illustrated in digestible steps. The implementations are very simple: there are no black boxes or fancy tricks involved, everything is built from the ground up. While these tutorials were originally intended to be taught at a school on tensor networks, they now serve as a general reference on uniform MPS and how one would go about implementing these concepts.
88 changes: 44 additions & 44 deletions matlab/chapter1.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
assert(~isreal(A), 'MPS tensor should have complex values')


% normalising an MPS through naive diagonalization of the transfer matrix:
A = normaliseMPSNaive(A);
% normalizing an MPS through naive diagonalization of the transfer matrix:
A = normalizeMPSNaive(A);
[l, r] = fixedPointsNaive(A);

assert(ArrayIsEqual(l, l', 1e-12), 'left fixed point should be hermitian!')
assert(ArrayIsEqual(r, r', 1e-12), 'left fixed point should be hermitian!')

assert(ArrayIsEqual(l, ncon({A, l, conj(A)}, {[1, 2, -2], [3, 1], [3, 2, -1]}), 1e-12), 'l should be a left fixed point!')
assert(ArrayIsEqual(r, ncon({A, r, conj(A)}, {[-1, 2, 1], [1, 3], [-2, 2, 3]}), 1e-12), 'r should be a right fixed point!')
assert(abs(trace(l*r) - 1) < 1e-12, 'Left and right fixed points should be trace normalised!')
assert(abs(trace(l*r) - 1) < 1e-12, 'Left and right fixed points should be trace normalized!')


%% 1.2 Gauge fixing

% left and right orthonormalisation through taking square root of fixed points

[L, Al] = leftOrthonormaliseNaive(A, l);
[R, Ar] = rightOrthonormaliseNaive(A, r);
[L, Al] = leftOrthonormalizeNaive(A, l);
[R, Ar] = rightOrthonormalizeNaive(A, r);

assert(ArrayIsEqual(R * R', r, 1e-12), 'Right gauge does not square to r')
assert(ArrayIsEqual(L' * L, l, 1e-12), 'Left gauge does not sqaure to l')
Expand Down Expand Up @@ -77,22 +77,22 @@

A = createMPS(D, d);

% normalising an MPS through action of transfer matrix on a left and right matrix as a function handle:
A = normaliseMPS(A);
% normalizing an MPS through action of transfer matrix on a left and right matrix as a function handle:
A = normalizeMPS(A);
[l, r] = fixedPoints(A);

assert(ArrayIsEqual(l, l', 1e-12), 'left fixed point should be hermitian!')
assert(ArrayIsEqual(r, r', 1e-12), 'left fixed point should be hermitian!')

assert(ArrayIsEqual(l, ncon({A, l, conj(A)}, {[1, 2, -2], [3, 1], [3, 2, -1]}), 1e-12), 'l should be a left fixed point!')
assert(ArrayIsEqual(r, ncon({A, r, conj(A)}, {[-1, 2, 1], [1, 3], [-2, 2, 3]}), 1e-12), 'r should be a right fixed point!')
assert(abs(trace(l*r) - 1) < 1e-12, 'Left and right fixed points should be trace normalised!')
assert(abs(trace(l*r) - 1) < 1e-12, 'Left and right fixed points should be trace normalized!')


% gauging an MPS through iterative QR decompositions:
[Al, Ac, Ar, C] = mixedCanonical(A);
% [R, Ar] = rightOrthonormalise(A);
% [L, Al] = leftOrthonormalise(A);
% [R, Ar] = rightOrthonormalize(A);
% [L, Al] = leftOrthonormalize(A);

assert(ArrayIsEqual(eye(D), ncon({Ar, conj(Ar)}, {[-1 1 2], [-2 1 2]}), 1e-12), 'Ar not in right-orthonormal form')
assert(ArrayIsEqual(eye(D), ncon({Al, conj(Al)}, {[1 2 -2], [1 2 -1]}), 1e-12), 'Al not in left-orthonormal form')
Expand All @@ -103,7 +103,7 @@

%% 1.5 Computing expectation values
A = createMPS(D, d);
A = normaliseMPS(A);
A = normalizeMPS(A);
[l, r] = fixedPoints(A);
[Al, Ac, Ar, C] = mixedCanonical(A);

Expand Down Expand Up @@ -167,8 +167,8 @@
end


function Anew = normaliseMPSNaive(A)
% Normalise an MPS tensor.
function Anew = normalizeMPSNaive(A)
% Normalize an MPS tensor.
%
% Parameters
% ----------
Expand All @@ -185,7 +185,7 @@
% Complexity
% ----------
% O(D ** 6) algorithm,
% directly diagonalising (D ** 2, D ** 2) matrix.
% directly diagonalizing (D ** 2, D ** 2) matrix.

end

Expand All @@ -208,7 +208,7 @@
% Complexity
% ----------
% O(D ** 6) algorithm,
% diagonalising (D ** 2, D ** 2) matrix.
% diagonalizing (D ** 2, D ** 2) matrix.

end

Expand All @@ -231,13 +231,13 @@
% Complexity
% ----------
% O(D ** 6) algorithm,
% diagonalising (D ** 2, D ** 2) matrix.
% diagonalizing (D ** 2, D ** 2) matrix.

end


function [l, r] = fixedPointsNaive(A)
% Find normalised fixed points.
% Find normalized fixed points.
%
% Parameters
% ----------
Expand All @@ -257,15 +257,15 @@
% Complexity
% ----------
% O(D ** 6) algorithm,
% diagonalising (D ** 2, D ** 2) matrix
% diagonalizing (D ** 2, D ** 2) matrix

end


%% 1.2 Gauge fixing


function [L, Al] = leftOrthonormaliseNaive(A, l)
function [L, Al] = leftOrthonormalizeNaive(A, l)
% Transform A to left-orthonormal gauge.
%
% Parameters
Expand All @@ -280,19 +280,19 @@
% left gauge with 2 legs,
% ordered left-right.
% Al : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left orthonormal
%
% Complexity
% ----------
% O(D ** 6) algorithm,
% diagonalising (D ** 2, D ** 2) matrix
% diagonalizing (D ** 2, D ** 2) matrix

end


function [R, Ar] = rightOrthonormaliseNaive(A, r)
function [R, Ar] = rightOrthonormalizeNaive(A, r)
% Transform A to right-orthonormal gauge.
%
% Parameters
Expand All @@ -307,14 +307,14 @@
% right gauge with 2 legs,
% ordered left-right.
% Ar : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left orthonormal
%
% Complexity
% ----------
% O(D ** 6) algorithm,
% diagonalising (D ** 2, D ** 2) dmatrix
% diagonalizing (D ** 2, D ** 2) dmatrix

end

Expand All @@ -331,15 +331,15 @@
% Returns
% -------
% Al : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left orthonormal.
% Ac : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% center gauge.
% Ar : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% right orthonormal.
% C : array(D, D)
Expand Down Expand Up @@ -370,15 +370,15 @@
% Returns
% -------
% AlTilde : array(Dtrunc, d, Dtrunc)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left orthonormal.
% AcTilde : array(Dtrunc, d, Dtrunc)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% center gauge.
% ArTilde : array(Dtrunc, d, Dtrunc)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% right orthonormal.
% CTilde : array(Dtrunc, Dtrunc)
Expand All @@ -392,8 +392,8 @@
%% 1.4 Algorithms for finding canonical forms


function Anew = normaliseMPS(A)
% Normalise an MPS tensor.
function Anew = normalizeMPS(A)
% Normalize an MPS tensor.
%
% Parameters
% ----------
Expand Down Expand Up @@ -462,7 +462,7 @@


function [l, r] = fixedPoints(A)
% Find normalised fixed points.
% Find normalized fixed points.
%
% Parameters
% ----------
Expand Down Expand Up @@ -490,7 +490,7 @@
% rqPos: already implemented as function 'lq' in the folder 'AuxiliaryFunctions'


function [R, Ar] = rightOrthonormalise(A, R0, tol, maxIter)
function [R, Ar] = rightOrthonormalize(A, R0, tol, maxIter)
% Transform A to right-orthonormal gauge.
%
% Parameters
Expand All @@ -513,7 +513,7 @@
% right gauge with 2 legs,
% ordered left-right.
% Ar : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% right-orthonormal

Expand All @@ -523,7 +523,7 @@
% qrPos: already implemented as function 'qrpos' in the folder 'AuxiliaryFunctions'


function [L, Al] = leftOrthonormalise(A, L0, tol, maxIter)
function [L, Al] = leftOrthonormalize(A, L0, tol, maxIter)
% Transform A to left-orthonormal gauge.
%
% Parameters
Expand All @@ -546,7 +546,7 @@
% left gauge with 2 legs,
% ordered left-right.
% Al : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left-orthonormal

Expand All @@ -565,15 +565,15 @@
% Returns
% -------
% Al : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% left orthonormal.
% Ac : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% center gauge.
% Ar : array(D, d, D)
% MPS tensor zith 3 legs,
% MPS tensor with 3 legs,
% ordered left-bottom-right,
% right orthonormal.
% C : array(D, D)
Expand Down Expand Up @@ -602,10 +602,10 @@
% ordered left-bottom-right.
% l : array(D, D), optional
% left fixed point of transfermatrix,
% normalised.
% normalized.
% r : array(D, D), optional
% right fixed point of transfermatrix,
% normalised.
% normalized.
%
% Returns
% -------
Expand Down Expand Up @@ -654,10 +654,10 @@
% ordered left-bottom-right.
% l : array(D, D), optional
% left fixed point of transfermatrix,
% normalised.
% normalized.
% r : array(D, D), optional
% right fixed point of transfermatrix,
% normalised.
% normalized.
%
% Returns
% -------
Expand Down
Loading

0 comments on commit 677768a

Please sign in to comment.