Skip to main content

An efficient python block-sparse tensor and MPS/DMRG library.

Project description

Documentation Status Build Status License: GPL v3 PyPI version

pyblock3

An Efficient python block-sparse tensor and MPS/DMRG Library

Copyright (C) 2020-2021 The pyblock3 developers. All Rights Reserved.

Authors:

  • Huanchen Zhai @hczhai: MPS/MPO/DMRG
  • Yang Gao @yangcal: General fermionic tensor
  • Garnet Kin-Lic Chan @gkc1000: Library design

Please cite this work as:

Huanchen Zhai, Yang Gao, and Garnet K.-L. Chan. pyblock3: an efficient python block-sparse tensor and MPS/DMRG library. 2021; https://github.com/block-hczhai/pyblock3-preview.

Documentation: https://pyblock3.readthedocs.io/en/latest

Tutorial: https://colab.research.google.com/drive/1grQyYP9oTivjqQRZiwU40tF9SdWyrPfV?usp=sharing

Features

  • Block-sparse tensor algebra with quantum number symmetries:
    • U(1) particle number
    • U(1) spin
    • Abelian point group symmetry
  • MPO construction
    • SVD approach for general fermionic Hamiltonian
    • Conventional approach for quantum chemistry Hamiltonian
  • MPO/MPS algebra
    • MPO compression
  • Efficient sweep algorithms for ab initio systems (2-site):
    • Ground-state DMRG with perturbative noise
    • MPS compression
    • Green's function (DDMRG++)
    • Imaginary time evolution (time-step targeting approach)
    • Real time evolution (time-step targeting approach)
    • Finite-temperature DMRG (ancilla approach)

Installation

Using pip:

pip install pyblock3

Or you can compile it manually:

Dependence: python3, psutil, numba, and numpy (version >= 1.17.0). pyblock3 can run in pure python mode, in which no C++ source code is required to be compiled.

For optimal performance, the C++ source code is used and there are some additional dependences:

  • pybind11 (https://github.com/pybind/pybind11)
  • cmake (version >= 3.0)
  • MKL (or blas + lapack)
    • When MKL is available, add cmake option: -DUSE_MKL=ON.
    • If cmake cannot find MKL, one can add environment variable hint MKLROOT.
  • C++ compiler: g++ or clang
    • icpc currently not tested/supported
  • High performance Tensor Transposition library: hptt (https://github.com/springer13/hptt) (optional)
    • For CPU with AVX512 flag, one can use this AVX512 version (https://github.com/hczhai/hptt)
    • HPTT is important for optimal performance
    • When HPTT is available, add cmake option: -DUSE_HPTT=ON.
    • If cmake cannot find HPTT, one can add environment variable hint HPTTHOME.
  • openMP library gomp or iomp5 (optional)
    • This is required for multi-threading parallelization.
    • For openMP disabled: add cmake option: -DOMP_LIB=SEQ.
    • For gnu openMP (gomp): add cmake option: -DOMP_LIB=GNU.
    • For intel openMP (iomp5): add cmake option: -DOMP_LIB=INTEL (default).
    • If cmake cannot find openMP library, one can add the path to libgomp.so or libiomp5.so to environment variable PATH.

To compile the C++ part of the code (for better performance):

mkdir build
cd build
cmake .. -DUSE_MKL=ON -DUSE_HPTT=ON
make

Add package root directory to PYTHONPATH before running the following examples.

If you used directory names other than build for the build directory (which contains the compiled python extension), you also need to add the build directory to PYTHONPATH.

Examples

Ground-state DMRG (H8 STO6G) in pure python (52 seconds):

import numpy as np
from pyblock3.algebra.mpe import MPE
from pyblock3.hamiltonian import Hamiltonian
from pyblock3.fcidump import FCIDUMP

fd = 'data/H8.STO6G.R1.8.FCIDUMP'
bond_dim = 250
hamil = Hamiltonian(FCIDUMP(pg='d2h').read(fd), flat=False)
mpo = hamil.build_qc_mpo()
mpo, _ = mpo.compress(cutoff=1E-9, norm_cutoff=1E-9)
mps = hamil.build_mps(bond_dim)

dmrg = MPE(mps, mpo, mps).dmrg(bdims=[bond_dim], noises=[1E-6, 0],
    dav_thrds=[1E-3], iprint=2, n_sweeps=10)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)

Ground-state DMRG (H8 STO6G) with C++ optimized core functions (0.87 seconds):

import numpy as np
from pyblock3.algebra.mpe import MPE
from pyblock3.hamiltonian import Hamiltonian
from pyblock3.fcidump import FCIDUMP

fd = 'data/H8.STO6G.R1.8.FCIDUMP'
bond_dim = 250
hamil = Hamiltonian(FCIDUMP(pg='d2h').read(fd), flat=True)
mpo = hamil.build_qc_mpo()
mpo, _ = mpo.compress(cutoff=1E-9, norm_cutoff=1E-9)
mps = hamil.build_mps(bond_dim)

dmrg = MPE(mps, mpo, mps).dmrg(bdims=[bond_dim], noises=[1E-6, 0],
    dav_thrds=[1E-3], iprint=2, n_sweeps=10)
ener = dmrg.energies[-1]
print("Energy = %20.12f" % ener)

The printed ground-state energy for this system should be -4.345079402665.

Adding Extra Symmetry Class

  1. Write the C++ definition of the class (named QPN, for example) in src/qpn.hpp, which should be similar to src/sz.hpp.

  2. Add the following in src/symmetry_tmpl.hpp after add other symmetries here line:

     #include "qpn.hpp"
     #define TMPL_Q QPN
     #include NAME_IMPL(TMPL_NAME,_tmpl.hpp)
     #undef TMPL_Q
    

    Note that if multiple symmetry class are defined in the same file src/qpn.hpp, you may only write #include "qpn.hpp" once. The other three lines have to be repeated for each symmetry class. If you do not need the default symmetry class SZ and you want to save compiling time, the four lines for SZ can be removed/commented.

  3. Add the following in src/main.hpp after bind extra symmetry here line:

     py::module m_qpn = m.def_submodule("qpn", "General other symmetry.");
     bind_sparse_tensor<QPN>(m_qpn, m, "QPN");
    

    If you do not need the default symmetry class SZ and you want to save compiling time, the two lines bind_ ... for SZ can be removed/commented.

  4. In python script, use the following to indicate which symmetry class is being used:

     if DEFAULT_SYMMETRY == SZ:
         import block3.sz as block3
     elif DEFAULT_SYMMETRY == QPN:
         import block3.qpn as block3
    

Project details


Download files

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

Source Distribution

pyblock3-0.2.5.tar.gz (197.8 kB view details)

Uploaded Source

Built Distributions

pyblock3-0.2.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pyblock3-0.2.5-cp39-cp39-macosx_11_0_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

pyblock3-0.2.5-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyblock3-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

pyblock3-0.2.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pyblock3-0.2.5-cp37-cp37m-macosx_11_0_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.7m macOS 11.0+ x86-64

File details

Details for the file pyblock3-0.2.5.tar.gz.

File metadata

  • Download URL: pyblock3-0.2.5.tar.gz
  • Upload date:
  • Size: 197.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5.tar.gz
Algorithm Hash digest
SHA256 9d8b3a41b40db1add1af3bda867cf355829e5eb5634a525b2d0c806e95613a29
MD5 8c1cc90117597aca7624e680d6c385b9
BLAKE2b-256 16d6819bf191985146eb13caa3daec07a85f6f7afcbd52face2f367f23f56770

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
  • Upload date:
  • Size: 79.6 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a9c71e9b860726b6e49adc8fad2614be94e2fb8bcc546ae052e131afab2d580e
MD5 d0406742454de1fd6562e78da05c6d75
BLAKE2b-256 8d6f92c4f9056052ec7c87d952c068fc1559fbab155fb18b2691b59e3d80c52b

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 dc570c559e04b692a6496307b0447f10b385d7fe08e1ed3a4680bcc0066e6a78
MD5 f7bd6dcd8b9ad5b5bb3285f0313c1f29
BLAKE2b-256 dd57ab8eea8b085bf9a6b07ddd8182690211cf5f9a5ef06618023beb5e3a83c8

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
  • Upload date:
  • Size: 79.6 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 87518d7c37f47bd4539d87d685373d68a78d37baec64348d95aeeec6961e9f12
MD5 8a1cdb096e2ac499076d0ca4eaa3a97e
BLAKE2b-256 43c96cdc8d26334d4b8c1a3b69f84a6276daf74799d1bf3cf0620e913e444f0e

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c2a63bdc29e87ac0ab3b21c652ac372bb36731273337fd394dfec2c262eeb23d
MD5 d7195e55417c3846847405ee9ed991c1
BLAKE2b-256 67949caf5f1bb62b659c83792829db049243862cec4eb35f21365269776da86b

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
  • Upload date:
  • Size: 79.6 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b39dd50c4ec89e55b501e53a98a1a8fd41d39ca678073725720144810280a860
MD5 22c11d93d8a77bb6aa1ef9ae65bb8ffc
BLAKE2b-256 b7f5293216380591bb9ad71cd290d628c0f56f65a72d18dae9a60e67e92821e0

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.5-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: pyblock3-0.2.5-cp37-cp37m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.7m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pyblock3-0.2.5-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 879f9815e0e498f15c207a03341ace8e913655fce9b78db1686f9b5a9916c6b9
MD5 97b5c80e235ee758bbc5034860d6076c
BLAKE2b-256 4a1507204ae4c5fd0ba925e4beab30d467917c8bde29147aa570b9a7c0c29ad7

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