Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: variPEPS/variPEPS_Python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.7.1
Choose a base ref
...
head repository: variPEPS/variPEPS_Python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Dec 16, 2024

  1. Copy the full SHA
    3303ff8 View commit details

Commits on Dec 18, 2024

  1. Copy the full SHA
    81f899d View commit details

Commits on Dec 20, 2024

  1. Copy the full SHA
    5a0e189 View commit details

Commits on Jan 15, 2025

  1. Copy the full SHA
    fe18fdc View commit details
  2. Release version 0.7.2

    JanLuca committed Jan 15, 2025
    Copy the full SHA
    d9ab3e3 View commit details

Commits on Jan 16, 2025

  1. Copy the full SHA
    efd914f View commit details
  2. Update documentation

    JanLuca committed Jan 16, 2025
    Copy the full SHA
    2cd40db View commit details
  3. Update poetry env

    JanLuca committed Jan 16, 2025
    Copy the full SHA
    0d33c54 View commit details

Commits on Jan 17, 2025

  1. Copy the full SHA
    fbdaa9c View commit details
  2. Copy the full SHA
    ae617cb View commit details
  3. Release version 0.8.0

    JanLuca committed Jan 17, 2025
    Copy the full SHA
    5bcb408 View commit details

Commits on Jan 20, 2025

  1. Copy the full SHA
    6176525 View commit details

Commits on Feb 21, 2025

  1. Copy the full SHA
    f7cbfc8 View commit details
  2. Release version 0.8.1

    JanLuca committed Feb 21, 2025
    Copy the full SHA
    dbc05f7 View commit details

Commits on Feb 27, 2025

  1. Copy the full SHA
    2630785 View commit details
  2. Copy the full SHA
    fec420d View commit details
  3. Copy the full SHA
    a2e6ff3 View commit details
  4. Copy the full SHA
    e30497b View commit details
  5. Copy the full SHA
    da4d3de View commit details
  6. Copy the full SHA
    34b692a View commit details
  7. Copy the full SHA
    475ad73 View commit details
  8. Copy the full SHA
    df04730 View commit details
  9. Copy the full SHA
    2862b88 View commit details
  10. Copy the full SHA
    832e290 View commit details
  11. Copy the full SHA
    94b1a57 View commit details
  12. Copy the full SHA
    180dfeb View commit details
  13. Copy the full SHA
    904cf17 View commit details
  14. Copy the full SHA
    bbd6683 View commit details
  15. Update documentation

    JanLuca committed Feb 27, 2025
    Copy the full SHA
    5ee30eb View commit details
  16. Copy the full SHA
    c19b3df View commit details
  17. Fix formating of source files

    JanLuca committed Feb 27, 2025
    Copy the full SHA
    4f748a6 View commit details
  18. Remove old code

    JanLuca committed Feb 27, 2025
    Copy the full SHA
    4cf6117 View commit details
  19. Release version 1.0.0

    JanLuca committed Feb 27, 2025
    Copy the full SHA
    01bc80d View commit details
30 changes: 15 additions & 15 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
((python-mode
(eval . (setq flycheck-python-flake8-executable
(expand-file-name "venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el"))))
(expand-file-name ".venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el"))))
(eval . (setq flycheck-python-pylint-executable
(expand-file-name "venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el"))))
(expand-file-name ".venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el"))))
(eval . (setq flycheck-python-mypy-executable
(expand-file-name "venv/bin/mypy" (locate-dominating-file
default-directory
".dir-locals.el"))))
(expand-file-name ".venv/bin/mypy" (locate-dominating-file
default-directory
".dir-locals.el"))))
(eval . (setq flycheck-python-pycompile-executable
(expand-file-name "venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el")))))
(expand-file-name ".venv/bin/python" (locate-dominating-file
default-directory
".dir-locals.el")))))
(rst-mode
(eval . (setq flycheck-rst-sphinx-executable
(expand-file-name "venv/bin/sphinx-build" (locate-dominating-file
default-directory
".dir-locals.el"))))))
(expand-file-name ".venv/bin/sphinx-build" (locate-dominating-file
default-directory
".dir-locals.el"))))))
10 changes: 9 additions & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -61,7 +61,15 @@
}
],

"keywords": ["peps", "tensor-networks", "variational-optimization"],
"keywords": [
"physics",
"automatic-differentiation",
"peps",
"tensor-networks",
"variational-optimization",
"quantum-many-body",
"quantum-many-body-physics"
],

"communities": [
{"identifier": "crc183"}
4 changes: 4 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -37,7 +37,11 @@ abstract: >-
A versatile tensor network library for variational ground
state simulations in two spatial dimensions
keywords:
- physics
- automatic-differentiation
- peps
- tensor-networks
- variational-optimization
- quantum-many-body
- quantum-many-body-physics
license: GPL-3.0-or-later
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

[![DOI](https://zenodo.org/badge/773767511.svg)](https://zenodo.org/doi/10.5281/zenodo.10852390)
[![Documentation Status](https://readthedocs.org/projects/varipeps/badge/?version=latest)](https://varipeps.readthedocs.io/en/stable/?badge=latest)
[![PyPI - Version](https://img.shields.io/pypi/v/varipeps)](https://pypi.org/project/variPEPS/)

variPEPS is the Python variant of the tensor network library developed for
variational ground state simulations in two spatial dimensions applying gradient
@@ -17,19 +18,6 @@ The current version of the variPEPS Python package is available on [PyPI](https:
$ python3 -m pip install variPEPS
```

### Installation using poetry

The dependencies in this project are managed by poetry and the tool can also be used to install the package including a fixed set of dependencies with a specific version. For more details how poetry is operating, please see the [upstream documentation](http://python-poetry.org/docs/).

To install dependencies you can just run in the main folder of the variPEPS project:
```bash
$ poetry install
```
or if you do not need the development packages:
```bash
$ poetry install --no-dev
```

## Usage

For detailed information how to use the package we want to point out to the [documentation of the project](https://varipeps.readthedocs.io/en/stable).
243 changes: 243 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
.. _examples:


Examples
========

We provide several examples in the `examples/ folder of the variPEPS Git repository <https://github.com/variPEPS/variPEPS_Python/tree/main/examples>`_ that demonstrate how to use the code for variational energy optimization in typical 2D many-body problems.

.. In this section we want to elaborately walk through the example for the Heisenberg AFM on the 2d square lattice to explain a typical usage of the library.
Heisenberg antiferromagnet on the square lattice
------------------------------------------------

.. figure:: /images/square_lattice.*
:align: center
:width: 60%
:alt: Two dimensional square lattice with red links indicating horizontal and
blue links indicating vertical interactions.

Two dimensional square lattice

The Hamiltonian for the Heisenberg antiferromagnet with constant exchange
interaction strength :math:`J>0` is defined as:

.. math::
H = J \sum_{\langle i j \rangle} \vec{S}_i \vec{S}_j ,
where :math:`\langle i j \rangle` denotes the sum over all nearest neighbors in
the lattice.

Our aim is now to find the ground state of the model using the variational iPEPS
code of the variPEPS library.

Loading of relevant Python modules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
import varipeps
import jax
import jax.numpy as jnp
First of all we have to load the relevant Python modules for our simulation. The
:obj:`varipeps` module includes the full library to perform the variational
optimization. Internally it is based on the :obj:`jax` framework and its
:obj:`numpy`-like interface to execute the calculations. Since we will need
arrays to define for example the Hamiltonian, we load this numpy
interface as well.

variPEPS config settings
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# Config Setting
## Set maximal steps for the CTMRG routine
varipeps.config.ctmrg_max_steps = 100
## Set convergence threshold for the CTMRG routine
varipeps.config.ctmrg_convergence_eps = 1e-7
## Select the method used to calculate the (full) projectors in the CTMRG routine
varipeps.config.ctmrg_full_projector_method = (
varipeps.config.Projector_Method.FISHMAN
)
## Enable dynamic increase of CTMRG environment bond dimension
varipeps.config.ctmrg_heuristic_increase_chi = True
## Increase CTMRG enviroment bond dimension if truncation error exceeds this value
varipeps.config.ctmrg_heuristic_increase_chi_threshold = 1e-4
## Set maximal steps for the fix point routine in the gradient calculation
varipeps.config.ad_custom_max_steps = 100
## Set convergence threshold for the fix point routine in the gradient calculation
varipeps.config.ad_custom_convergence_eps = 5e-8
## Enable/Disable printing of the convergence of the single CTMRG/gradient fix point steps.
## Useful to enable this during debugging, should be disabled for batch runs
varipeps.config.ctmrg_print_steps = True
varipeps.config.ad_custom_print_steps = False
## Select the method used to calculate the descent direction during optimization
varipeps.config.optimizer_method = varipeps.config.Optimizing_Methods.CG
## Set maximal number of steps for the optimization routine
varipeps.config.optimizer_max_steps = 2000
The :obj:`varipeps` library allows to configure a large number of numerical
parameters to fine-tune the simulation. In this example we include several
options commonly used in an optimization run. For a detailed
description of the configurable options we refer to the API description of the
config class: :obj:`varipeps.config.VariPEPS_Config`.

Model parameters
^^^^^^^^^^^^^^^^

.. code-block:: python
# Set constants for the simulation
modelName = "HeisenbergModel"
# Interaction strength
J = 1
# iPEPS bond dimension
chiB = 2
# Physical dimension
p = 2
# Maximal enviroment bond dimension
maxChi = 36
# Start value for enviroment bond dimension
startChi = chiB**2 if chiB**2 < maxChi else maxChi
In this block we define imporant parameters for the model we want to simulate, such as as the interaction strength, the physical dimension of our tensor network and the iPEPS bond dimension. In the last two lines the initial and the maximal enviroment bond dimension is defined. A feature of the variPEPS library is that it not only supports simulation at a fixed enviroment bond dimension, but also a heurisitic increase/decrease of the dimension up to a maximal value. The dynamic change is controlled by the truncation error in the CTMRG projector calculation (increase if the truncation errror becomes too large, decrease if it becomes insignificant). For example, in the config block above the parameter ``ctmrg_heuristic_increase_chi_threshold`` is set to the threshold at which to increase the refinement parameter. The maximal bond dimension ``maxChi`` ensures that the parameter does now grow unbounded, to the point where the memory and computational resources are exhausted.

Constructing the Hamiltonian
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# define spin-1/2 matrices
Id = jnp.eye(2)
Sx = jnp.array([[0, 1], [1, 0]]) / 2
Sy = jnp.array([[0, -1j], [1j, 0]]) / 2
Sz = jnp.array([[1, 0], [0, -1]]) / 2
# construct Hamiltonian terms
hamiltonianGates = J * (jnp.kron(Sx, Sx) + jnp.kron(Sy, Sy) + jnp.kron(Sz, Sz))
# create function to compute expectation values for the square Heisenberg AFM
exp_func = varipeps.expectation.Two_Sites_Expectation_Value(
horizontal_gates=(hamiltonianGates,),
vertical_gates=(hamiltonianGates,),
)
Here the Hamiltonian is constructed for our model. The Heisenberg AFM on the
square lattice can be described by the sum of the spin-spin interactions on
the horizontal and vertical bonds. Since we assume a constant
interaction strength for all bonds in our example, the expectation value can be calculated by
the same two-site interaction gate applied in all nearest neighbor
directions. The expectation function ``exp_func`` is later used in the
optimization to calculate the energy expectation value, which in turn is used as cost function to obtain
the ground state.

Initial unit cell construction
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# Unit cell structure
structure = [[0, 1], [1, 0]]
Here we define the unit cell structure which is used to simulate our model. In
this example we assume a
:math:`\scriptsize{\begin{matrix}A&B\\B&A\end{matrix}}`-structure, i.e. a two-site antiferromagnetic state.

.. code-block:: python
# Create random initialization for the iPEPS unit cell
unitcell = varipeps.peps.PEPS_Unit_Cell.random(
structure, # Unit cell structure
p, # Physical dimension
chiB, # iPEPS bond dimension
startChi, # Start value for enviroment bond dimension
float, # Data type for the tensors: `float` (real) or `complex` tensors
max_chi=maxChi, # Maximal enviroment bond dimension
)
Using the unit cell structure and the model parameter defined above, we can
generate an initial unit cell. Here we initialize the iPEPS tensors with random
numbers. Other ways to initialize the tensors are provided, for example loading results
from a simple update calculation.

Run the optimization
^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# Run optimization
result = varipeps.optimization.optimize_peps_network(
unitcell,
exp_func,
autosave_filename=f"data/autosave_square_chiB_{chiB:d}.hdf5",
)
This function call executes the main function of the library, the variational energy
optimization to obtain a good ground state candidate. The function offers several options
to customize the optimization for different iPEPS ansätze, such as the spiral iPEPS
approach. In our example, we only need to provide the initial unit cell, the function
for calculating the energy expectation value, and a file path for autosaving the
optimization process, enabling the restoration of interrupted simulations.

Evaluate the results
^^^^^^^^^^^^^^^^^^^^

In this section we show some exemplary evaluation of the result of the optimization.

.. code-block:: python
# Calculate magnetic expectation values
Mag_Gates = [Sx, Sy, Sz]
def calc_magnetic(unitcell):
mag_result = []
for ti, t in enumerate(unitcell.get_unique_tensors()):
r = varipeps.expectation.one_site.calc_one_site_multi_gates(
t.tensor, t, Mag_Gates
)
mag_result += r
return mag_result
magnetic_exp_values = calc_magnetic(result.unitcell)
We assume for our example that we are interested in the single-site spin
expectation values. These could be used to analyse the :math:`z`-magnetization
or the staggered magnetization of our model at/near the ground state.

.. code-block:: python
# Define some auxiliary data which should be stored along the final iPEPS unit cell
auxiliary_data = {
"best_energy": result.fun,
"best_run": result.best_run,
"magnetic_exp_values": magnetic_exp_values,
}
for k in sorted(result.max_trunc_error_list.keys()):
auxiliary_data[f"max_trunc_error_list_{k:d}"] = result.max_trunc_error_list[k]
auxiliary_data[f"step_energies_{k:d}"] = result.step_energies[k]
auxiliary_data[f"step_chi_{k:d}"] = result.step_chi[k]
auxiliary_data[f"step_conv_{k:d}"] = result.step_conv[k]
auxiliary_data[f"step_runtime_{k:d}"] = result.step_runtime[k]
# save full iPEPS state
result.unitcell.save_to_file(
f"data/heisenberg_square_J_{J:d}_chiB_{chiB:d}_chiMax_{chiM:d}.hdf5",
auxiliary_data=auxiliary_data,
)
Finally, we want to save the unit cell with the optimized tensors to a file for
further analysis. The library allows to store the data directly into a
HDF5 file along with user-supplied auxiliary data. Here, for example, we not only
want to store the plain tensors but also the calculated energy, meta information
from the optimization run (e.g. energy per step or the runtime per step) and the
calculated magnetic expectation values. At a later examination of the results,
these data can be easily loaded along with the tensors of the tensor network.
59 changes: 59 additions & 0 deletions docs/source/general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.. _general:


Introduction
============

variPEPS is a Python tensor network library developed for variational ground
state simulations in two spatial dimensions applying gradient optimization using
automatic differentation.

For a detailed report on the method, please see `our open-access publication on
SciPost (doi:10.21468/SciPostPhysLectNotes.86)
<https://doi.org/10.21468/SciPostPhysLectNotes.86>`_.

Installation using pip
======================

The current version of the variPEPS Python package is available on `PyPI
<https://pypi.org/project/variPEPS/>`_. It can be easily installed using the
Python package manager pip:

.. code-block:: console
$ python3 -m pip install variPEPS
Usage
=====

The :obj:`varipeps` module is organized in several submodules corresponding to
the different features. For a variational optimization the most important parts
are (a full overview can be found in the :ref:`_api`):

* :obj:`varipeps.peps`: To define iPEPS unit cell and the tensors on each site,
the library provides in this submodule the abstractions to define such a unit
cell.
* :obj:`varipeps.expectation`: In this submodule the helper functions to define
and calculate common expecation functions on the iPEPS unit
cell. Particularly, the function can be used to define the Hamiltonian terms
of the model of interest.
* :obj:`varipeps.mapping`: If not only interactions on the square lattice are of
interest but also models on other 2d lattices, in this submodule one can find
mappings of other lattices. Also the files there can be a good starting point
to implement even more lattices.
* :obj:`varipeps.optimization`: The submodule providing the optimization
algorithm and interface of the library. In almost all cases, one will interact
with this part by the main function
:obj:`varipeps.optimization.optimize_peps_network`.

All these different modules can be seen in action in the :ref:`_examples`
section of the documentation where exemplary code is discussed in detail.

Citation
========

We are happy if you want to use the framework for your research. To cite our
work we provide a list of our preferred references on the `GitHub page of the
project
<https://github.com/variPEPS/variPEPS_Python?tab=readme-ov-file#citation>`_. Please
check there for a current list.
Binary file added docs/source/images/square_lattice.pdf
Binary file not shown.
Loading