Code Monkey home page Code Monkey logo

tnpy's Introduction

tnpy: Tensor Network algorithms implemented in python.


PyPI version Downloads codecov Join the chat at https://gitter.im/tanlin2013/tnpy Code style: black Imports: isort License Docker build Test Status Lint Status


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...

  • Exact Diagonalization (ED)
  • 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.

Requirements

Dependencies are listed in pyproject.toml, and they are supposed to be installed together with tnpy. Here we just list the essential building blocks.

Also, it's required to have lapack and blas installed in prior to Primme. They can also be installed through pip with mkl-devel.

Installation

  • Using Docker

    docker run --rm -it tanlin2013/tnpy
    
  • Using pip

    • Latest release:
      pip install tnpy
      
    • Development version:
      pip install git+https://github.com/tanlin2013/tnpy@main
      
  • Optional dependencies

Getting started

  1. We provide built-in models. Though it's also possible to register your own one.

    import numpy as np
    from tnpy.finite_dmrg import FiniteDMRG
    from tnpy.model import XXZ
    
    model = XXZ(n=100, delta=0.5)
    fdmrg = FiniteDMRG(
        mpo=model.mpo,
        chi=60  # virtual bond dimensions
    )
    fdmrg.update(tol=1e-8)
    
  2. Compute any physical quantities whatever you want from the obtained state. The resulting MPS is of the type quimb.tensor.MatrixProductState, see here for more details.

    my_mps = fdmrg.mps
    

License

© Tan Tao-Lin, 2023. Licensed under a MIT license.

tnpy's People

Contributors

renovate[bot] avatar tanlin2013 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

10sornetwork

tnpy's Issues

Build: update dependencies

Some dependencies are already expired.

Blockers

quimb 1.3.0 Quantum information and many-body library.
├── cytoolz >=0.8.0
│   └── toolz >=0.8.0 
├── numba >=0.39
│   ├── llvmlite >=0.38.0rc1,<0.39 
│   └── numpy >=1.18,<1.22 
├── numpy >=1.17
├── psutil >=4.3.1
├── scipy >=1.0.0
│   └── numpy >=1.17.3,<1.25.0 
└── tqdm >=4
    └── colorama * 

TODO

May potentially have conflicts

  • wait for poetry 1.2.0 final release
  • update numba to >=0.54
  • update quimb to 1.4.0

Feature: Schmidt gap

Characterizing the MBLT

The main quantity we compute, new in the context of MBL, is the Schmidt gap. For two chain halves (or as close to for odd L), A and B, as shown in Fig. 1(a), an eigenvector’s reduced density matrix is ρA,k = TrB(|Ek〉 〈Ek|) for a particular sample of the random fields. The disorder-averaged Schmidt gap is then defined as ∆ = 〈λk1 − λk2〉k, where λk1, λk2 refer to the largest eigenvalues of the reduced density matrix ρA,k, 〈·〉k denotes average over eigenstates and · denotes the average over many samples. The Schmidt gap has previously been shown to act as an order parameter for quantum phase transitions [34, 36]. We explore the possibility of using it for characterizing the MBLT. Unlike entanglement entropy, the Schmidt gap ignores most of the spectrum of ρA,k, describing only the relationship between the two dominant states across the A − B cut. This is pertinent in light of the recent finding that while the Schmidt values decay polynomially in the MBL phase [22], finite size corrections are stronger for small Schmidt values. In the ergodic phase we expect strong entanglement to produce multiple, equally likely orthogonal states, thus ∆ ∼ 0. In the MBL phase, however, a single dominant state should appear on either side of the cut, with ∆ rising towards 1 as h → ∞, implying a tensor product. This behaviour is shown in Fig. 2(a) and becomes becomes sharper with increasing L. To see this more vividly, we plot the derivative of ∆ with respect to h in Fig. 2(b). The derivative has a peak at h = ̃ hc, which not only becomes more pronounced but also shifts to the right with L. We infer this to be the finite size precursor to the transition point, which suggests that in the thermodynamic limit, L → ∞, the derivative of the Schmidt gap diverges at the MBLT and ̃ hc asymptotically approaches the transition point hc.

Difficulties

The problem for tsdrg approach is that it's hard to access reduced density matrix in the center of the system.
One may consider to use bipartite fluctuations as a probe to the entanglement.

If it's possible to derive the Schmidt gap in terms of the cumulants of fluctuations.

Reference

http://arxiv.org/abs/1704.00738
https://journals.aps.org/prb/abstract/10.1103/PhysRevB.85.035409

[Bug] supported version of mkl-devel is in-consist on different device

Description

Latest few versions of mkl-devel released in 2022 are in-consist across devices.

On pip, 2022.0.3 seems to be the newest

pip install mkl-devel==2022.0.3

But specifying version 2022.0.0, 2022.0.1, 2022.0.2 or 2022.0.3 does not give consistent result (those after 2021.0.4).

Error Logs

  • Docker (Ubuntu 20.04)
ERROR: Could not find a version that satisfies the requirement mkl-devel==2022.0.3 (from versions: 2018.0.0, 2018.0.3, 2021.1.1, 2021.2.0, 2021.3.0, 2021.4.0, 2022.0.1, 2022.0.2)
  • Conda environment (conda 4.10.3) on mac (Monterey 12.3)
ERROR: Could not find a version that satisfies the requirement mkl-devel==2022.0.3 (from versions: 2018.0.0, 2018.0.3, 2021.1.1, 2021.2.0, 2021.3.0, 2021.4.0, 2022.0.0)

Feature: modified density matrix to overcome local minimum in DMRG

Local minimums are often encountered during the DMRG sweeping, especially for the single-site DMRG. To overcome this issue, it's suggested to bring in the modified density matrix, which considers the small perturbation from the rest of the environment.

References

  1. S. R. White, Density matrix renormalization group algorithms with a single center site, Phys. Rev. B 72, 180403 (2005)
  2. U. Schollwoeck, The density-matrix renormalization group in the age of matrix product states, arXiv:1008.3477 (2011). (p. 71, eq. 217)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency graphviz to v0.20.3
  • fix(deps): update dependency primme to v3.2.2
  • chore(deps): update dependency cruft to v2.15.0
  • chore(deps): update dependency flake8-bugbear to v23.12.2
  • chore(deps): update dependency ipython to v8.27.0
  • chore(deps): update dependency isort to v5.13.2
  • chore(deps): update dependency mypy to v1.11.2
  • chore(deps): update dependency pandoc to v2.4
  • chore(deps): update dependency pep8-naming to ^0.14.0
  • chore(deps): update dependency pre-commit to v3.8.0
  • chore(deps): update dependency pytest-cov to v4.1.0
  • chore(deps): update dependency pytest-mock to v3.14.0
  • chore(deps): update dependency vulture to v2.11
  • fix(deps): update dependency h5py to v3.11.0
  • fix(deps): update dependency llvmlite to ^0.43.0
  • fix(deps): update dependency mkl-devel to v2023.2.2
  • fix(deps): update dependency networkx to v3.3
  • fix(deps): update dependency numba to ^0.60.0
  • fix(deps): update dependency numpy to v1.26.4
  • fix(deps): update dependency scipy to v1.14.1
  • chore(deps): update actions/cache action to v4
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-python action to v5
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update dependency commitizen to v3
  • chore(deps): update dependency flake8-bugbear to v24
  • chore(deps): update dependency pytest to v8
  • chore(deps): update dependency pytest-cov to v5
  • chore(deps): update dependency safety to v3
  • chore(deps): update dependency sphinx to v8
  • chore(deps): update docker/build-push-action action to v6
  • chore(deps): update docker/login-action action to v3
  • chore(deps): update docker/metadata-action action to v5
  • chore(deps): update docker/setup-buildx-action action to v3
  • chore(deps): update docker/setup-qemu-action action to v3
  • chore(deps): update github/codeql-action action to v3
  • chore(deps): update peaceiris/actions-gh-pages action to v4
  • fix(deps): update dependency mkl-devel to v2024
  • fix(deps): update dependency numpy to v2
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • python 3.10.8
github-actions
.github/workflows/build.yml
  • docker/setup-qemu-action v2
  • docker/setup-buildx-action v2
  • docker/metadata-action v4
  • docker/login-action v2
  • docker/build-push-action v4
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/doc.yml
  • actions/checkout v3
  • actions/setup-python v4
  • peaceiris/actions-gh-pages v3
.github/workflows/lint.yml
  • actions/checkout v3
  • actions/cache v3
  • actions/setup-python v4
.github/workflows/release.yml
  • docker/setup-qemu-action v2
  • docker/setup-buildx-action v2
  • docker/metadata-action v4
  • docker/login-action v2
  • docker/build-push-action v4
  • actions/checkout v3
.github/workflows/test.yml
  • actions/checkout v3
  • actions/checkout v3
  • actions/cache v3
  • actions/cache v3
  • actions/cache v3
  • actions/setup-python v4
  • codecov/codecov-action v3
pep621
pyproject.toml
  • poetry-core >=1.0.0
poetry
pyproject.toml
  • python >=3.9, <3.11
  • toml ^0.10.2
  • tqdm ^4.63.0
  • numpy ^1.22
  • scipy >=1.1, <2.0
  • primme 3.2.1
  • h5py >=3.6, <4.0
  • graphviz 0.20.1
  • tensornetwork 0.4.6
  • numba ^0.56.4
  • llvmlite ^0.39.1
  • autoray ^0.6.0
  • quimb 1.4.0
  • mkl-devel 2023.0.0
  • matplotlib ^3.5.2
  • networkx ^3.0
  • pre-commit ^3.0.0
  • commitizen ^2.35.0
  • vulture ^2.4
  • bandit ^1.7.4
  • safety ^2.3.4
  • isort ^5.11.0
  • flake8-bugbear ^23.1.14
  • Flake8-pyproject ^1.2.2
  • black ^23.1.0
  • mypy ^1.0.0
  • ipython ^8.5.0
  • pytest ^7.1.2
  • pytest-cov ^4.0.0
  • pytest-mock ^3.9.0
  • pep8-naming ^0.13.0
  • cruft ^2.12.0
  • sphinx ^4.5.0
  • sphinx-book-theme ^0.3.2
  • nbsphinx ^0.8.8
  • m2r2 ^0.3.2
  • pandoc ^2.3

  • Check this box to trigger a request for Renovate to run again on this repository

bug: tensornetwork.FiniteMPS has no attribute nodes

After version 0.3.x, google/tensornetwork no longer supports the usage of FiniteMPS.nodes. One has to use the method FiniteMPS.get_tensor instead. See the documentation for more details.

Traceback (most recent call last):
  File "/__w/tnpy/tnpy/tests/test_finite_algorithm_base.py", line 20, in test_load
    init_method=f'{Path(__file__).parent}/test.npz'
  File "/__w/tnpy/tnpy/tnpy/finite_algorithm_base.py", line 30, in __init__
    self.reset_mps = init_method
  File "/__w/tnpy/tnpy/tnpy/finite_algorithm_base.py", line 76, in reset_mps
    self._init_envs()
  File "/__w/tnpy/tnpy/tnpy/finite_algorithm_base.py", line 142, in _init_envs
    self._update_left_env(site)
  File "/__w/tnpy/tnpy/tnpy/finite_algorithm_base.py", line 158, in _update_left_env
    M = self._mps.nodes[site-1]
AttributeError: 'list' object has no attribute 'nodes'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.