Skip to main content

Tensor Network algorithms implemented in python.

Project description

tnpy

build tests docs license

Documentation |

This project is a python implementation of Tensor Network, a numerical approach to quantum many-body systems.

tnpy is built on top of quimb, along with TensorNetwork for tensor contractions, with optimized support for various backend engines (TensorFlow, JAX, PyTorch, and Numpy). For eigen-solver we adopt primme, an iterative multi-method solver with preconditioning.

Currently, we support Matrix Product State (MPS) algorithms, with more are coming...

  • Finite-sized Density Matrix Renormalization Group (fDMRG)
  • Tree tensor Strong Disorder Renormalization Group (tSDRG)

fDMRG & tSDRG are on alpha-release. For others, please expect edge cases.

Requirments

See pyproject.toml for more details. But these two are essential building blocks.

Regarding any installation problems with Primme, please refer to Primme official. Also, it's required to have lapack and blas installed in prior to Primme.

Installation

  • using Docker

    docker run --rm -it tanlin2013/tnpy
    
  • using pip:

    pip install tnpy
    

    for the latest release, or

    pip install git+https://github.com/tanlin2013/tnpy@main
    

    for the development version.

Documentation

For details about tnpy, see the reference documentation.

Getting started

  1. Defining the Matrix Product Operator of your model as a Callable function with argument site of the type int, e.g. the function _elem(self, site) below. The MPO class then accepts the Callable as an input and constructs a MPO object.

    import numpy as np
    from tnpy.operators import SpinOperators, MPO
    from tnpy.finite_dmrg import FiniteDMRG
    
    class XXZ:
    
        def __init__(self, N: int, delta: float) -> None:
            self.N = N
            self.delta = delta
    
        def _elem(self, site: int) -> np.ndarray:
            Sp, Sm, Sz, I2, O2 = SpinOperators()
            return np.array(
                [[I2, -0.5 * Sp, -0.5 * Sm, -self.delta * Sz, O2],
                 [O2, O2, O2, O2, Sm],
                 [O2, O2, O2, O2, Sp],
                 [O2, O2, O2, O2, Sz],
                 [O2, O2, O2, O2, I2]]
            )
         
        @property
        def mpo(self) -> MPO:
            return MPO(self.N, self._elem)
    
  2. Call the algorithm to optimize the state.

    N = 100  # length of spin chain
    chi = 60  # virtual bond dimension 
    
    model = XXZ(N, delta)
    fdmrg = FiniteDMRG(
        mpo=model.mpo,
        chi=chi
    )
    fdmrg.update(tol=1e-8)
    
  3. Compute any physical quantities whatever you want from the obtained state. The resulting MPS is of the type tensornetwork.FiniteMPS, see here for more details.

    my_mps = fdmrg.mps
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tnpy-0.1.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file tnpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tnpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tnpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9478c8b125c90f4df40cdfe9bff84974b35c30cc9f811ba07bbb84146d942a
MD5 b4a1535e6e9a87aa2a1ce55ce411ab1a
BLAKE2b-256 4d975533639f75b815724a514f69a4856f885a8c8b2b17a0273f61471eabe750

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page