Skip to main content

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

Project description

Documentation Status

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

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

Examples

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.

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-general-0.2.1.tar.gz (184.0 kB view details)

Uploaded Source

Built Distributions

pyblock3_general-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pyblock3_general-0.2.1-cp39-cp39-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyblock3_general-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyblock3_general-0.2.1-cp38-cp38-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyblock3_general-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (79.4 MB view details)

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

pyblock3_general-0.2.1-cp37-cp37m-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

Details for the file pyblock3-general-0.2.1.tar.gz.

File metadata

  • Download URL: pyblock3-general-0.2.1.tar.gz
  • Upload date:
  • Size: 184.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyblock3-general-0.2.1.tar.gz
Algorithm Hash digest
SHA256 93b156b266661900565ad894fdd33e4d22fd5c3211852e7f82a3ef4b9636be78
MD5 086b6ab75c29c2914123b94f3c26378d
BLAKE2b-256 640de7b2118ad590d51201218e93a365b22d9d998107d42d982fa5a51073b22a

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3_general-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 043e4327270bfabe277fec747541d33e9aa5c6e77d7afc0444bf3c364022f0d1
MD5 6ebb8cd54e4034d9352272984846823b
BLAKE2b-256 ae66d53409c98ceb353b6dabe0c8460cf99d410d24be276906095162794222fe

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: pyblock3_general-0.2.1-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyblock3_general-0.2.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8271bbaf639897a86ea234a0043df8ede105467aff4b5ad5d5777be6ad2623ea
MD5 6e208eb946181d553a5730ff79df10b0
BLAKE2b-256 a45e3c13311124780bbf4ce2540b83e6110b6122db95874755f1eb25fbddc998

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3_general-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7b032f531c9f404e473e04edd8f072a4f5901918c831b4a05bd5cbb0e6016241
MD5 d2a689aee1e106c70fcb89b238fc5fc1
BLAKE2b-256 79d34d43bad4dabc996eec439c90972b88cf5a7f76fe91c42ef917152a66b3b2

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: pyblock3_general-0.2.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyblock3_general-0.2.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 872294342658dcc723fb19885cbba79a0b49a45d1341e34886eff24faf685d1d
MD5 10a7f2b1db756f38b83eb5adfad7cc00
BLAKE2b-256 57845d7c55cba0f5460fa00b7208fe2358c07ccdac934fc51f76f0191fb95b52

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3_general-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b40ffeacbc507aee36aa8820e392da8c2451747bf3cdd5ea140bd5d73c3e3134
MD5 8130357f98152ddb0185f9299e994083
BLAKE2b-256 bb057b8c4009129c39867e8150de2dc8a8c4bac03825118d7a72c7a51aaa8302

See more details on using hashes here.

File details

Details for the file pyblock3_general-0.2.1-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: pyblock3_general-0.2.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyblock3_general-0.2.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9cd6fcc676dadb372f92136da917183ffcb75645ee5b7f17e11c6c71b3c366e8
MD5 a4ad044e7651c153d6350411c5a93c16
BLAKE2b-256 fc39b22122b08c95624ff26b87c7e2d0e1d77a841f279ccd27a821a03e0a77cb

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