An efficient python block-sparse tensor and MPS/DMRG library.
Project description
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
To install the most recent development version, use:
pip install pyblock3==<version> --extra-index-url=https://block-hczhai.github.io/pyblock3-preview/pypi/
where <version>
can be some development version number like 0.2.7rc5
.
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
(orblas + lapack
)- When
MKL
is available, addcmake
option:-DUSE_MKL=ON
. - If
cmake
cannot findMKL
, one can add environment variable hintMKLROOT
.
- When
- C++ compiler:
g++
orclang
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, addcmake
option:-DUSE_HPTT=ON
. - If
cmake
cannot findHPTT
, one can add environment variable hintHPTTHOME
.
- openMP library
gomp
oriomp5
(optional)- This is required for multi-threading parallelization.
- For openMP disabled: add
cmake
option:-DOMP_LIB=SEQ
. - For gnu openMP (
gomp
): addcmake
option:-DOMP_LIB=GNU
. - For intel openMP (
iomp5
): addcmake
option:-DOMP_LIB=INTEL
(default). - If
cmake
cannot find openMP library, one can add the path tolibgomp.so
orlibiomp5.so
to environment variablePATH
.
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
-
Write the C++ definition of the class (named
QPN
, for example) insrc/qpn.hpp
, which should be similar tosrc/sz.hpp
. -
Add the following in
src/symmetry_tmpl.hpp
afteradd 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 classSZ
and you want to save compiling time, the four lines forSZ
can be removed/commented. -
Add the following in
src/main.hpp
afterbind 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 linesbind_ ...
forSZ
can be removed/commented. -
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pyblock3-0.2.8.tar.gz
.
File metadata
- Download URL: pyblock3-0.2.8.tar.gz
- Upload date:
- Size: 272.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0041f997b5a03d518872eae91b8fa98794fd3c076e43e1b0792e8ebe032e4258 |
|
MD5 | f243d067c991161acd4d888d4c382449 |
|
BLAKE2b-256 | 5469f2897e60209a88913c281bd90c4a1d11029ab3a8735e22d6d4315f8a7d03 |
File details
Details for the file pyblock3-0.2.8-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 80.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e75e31aa402d66265641614338c1c5debf04a49ff3372fd6db2e0b1d099341 |
|
MD5 | 8c0a397dfc7a6be66d0dcb2b6d18d425 |
|
BLAKE2b-256 | bf51449e4b6dbd910456014e1173f3075a2b8bb07a47e9b4c9c7793a00f569b1 |
File details
Details for the file pyblock3-0.2.8-cp310-cp310-macosx_12_0_arm64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp310-cp310-macosx_12_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.10, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b9420b597c2d841cdd744c7280a8a5240faee5928d5a6d171b77c2bbf450ca3 |
|
MD5 | 4d7ae2a8bc17a57e8153345fdb62c8c2 |
|
BLAKE2b-256 | 9bf428915fcdd604a114cc5d8b95cbba4a537c6c37bea3248d06e5f460f2ccd1 |
File details
Details for the file pyblock3-0.2.8-cp310-cp310-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp310-cp310-macosx_11_0_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.10, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 219e2a4170dfd816e00be7342b704c84e7a280317d35f072c5372e8a36730c78 |
|
MD5 | 61b7792644a2472a6d7c143caa30f818 |
|
BLAKE2b-256 | ec60b2e378ce8a2d74575123318820f996ba3172db843751390afaec38d7b7a4 |
File details
Details for the file pyblock3-0.2.8-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 80.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c797b3d9407e871dbaeeff208a2599d3c73485cdc9c1e686a3225832008aeda3 |
|
MD5 | 9afe3316b05b5e4eb1148f1a00b199b8 |
|
BLAKE2b-256 | ba2985af1e7968a59a1c3b7b927f6845a70efc66e5ae4343b050c9f578d1a41b |
File details
Details for the file pyblock3-0.2.8-cp39-cp39-macosx_12_0_arm64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp39-cp39-macosx_12_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.9, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c50ac57f37a2746f6ed51e60e65a06b66b3fa052694e17cf7e3e713a1a1c39a |
|
MD5 | b9a2caaba0f5b2650607857283e0b389 |
|
BLAKE2b-256 | 8b69337744db69ea25a2bbc34d0aaad054922f59089eb8370cedcadfac4fa1f1 |
File details
Details for the file pyblock3-0.2.8-cp39-cp39-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp39-cp39-macosx_11_0_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.9, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a74dddb43f0805314d3709017380729e0f463e05ca79cc3104dd88b9cc2294 |
|
MD5 | d8a494ef3f24d2937ff0500c842b451b |
|
BLAKE2b-256 | 51aeed62e6c7b625b39a317a3d8dc9b985d6a5139c1a5bcaaf17311a46b0abf0 |
File details
Details for the file pyblock3-0.2.8-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 80.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3edec136a89d00cc35c80908ab80e857d2378fb96075cdb0b0357aaf6c02a414 |
|
MD5 | 08ffbd6b3b0de707e5146cc022c2ae0a |
|
BLAKE2b-256 | 19e9b53bb3be1a2839cf00d7088114ed335f4ff602162645c6bd105612696b52 |
File details
Details for the file pyblock3-0.2.8-cp38-cp38-macosx_12_0_arm64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp38-cp38-macosx_12_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.8, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05675d8ca9e6e5dcaf1ee8b1fce72d963c7bd1fada391d64fa1bd2795586483f |
|
MD5 | a086d8d135d6604a964d10574103917a |
|
BLAKE2b-256 | 632dede5163b49d09d7455c232d69f4448e20574a066adf663f2070e6ebe14a7 |
File details
Details for the file pyblock3-0.2.8-cp38-cp38-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp38-cp38-macosx_11_0_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.8, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1a4963e2b1cff730cf04af693acc5dcc9e7f99cfc70f186e5cfab39207b0ab4 |
|
MD5 | 77204b030cfbd1c1622b40a36011b8e6 |
|
BLAKE2b-256 | 94d0288349dfca01a1b1176cbe3b8f51db7028eee5cf8ac0f7caf2f61de95de7 |
File details
Details for the file pyblock3-0.2.8-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 80.1 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6124625443147b1ffe9f258fd7324ee05e46aa0ab175a73a8cbe7bd62fbf6f73 |
|
MD5 | d5c4072b3c08469cc6a64408e60328f0 |
|
BLAKE2b-256 | 85dfd47150af128f8021a39028a4ce25dc97351c21a7aeb4ad7fe9fc9208e63f |
File details
Details for the file pyblock3-0.2.8-cp37-cp37m-macosx_12_0_arm64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp37-cp37m-macosx_12_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.7m, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b64843d6ee57ff3945e46ad79037c7e6ad8b1369d0e920e7c83a5d5f02041315 |
|
MD5 | 25a0d7f724de80786913105a902f2477 |
|
BLAKE2b-256 | 489b61b137ccf64d4c93b8f012f92647e79d71e5ff8bf81dd6f87c59c2ab9c94 |
File details
Details for the file pyblock3-0.2.8-cp37-cp37m-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: pyblock3-0.2.8-cp37-cp37m-macosx_11_0_x86_64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.7m, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a12da7fb673da80587313170008b8ad374d82cd2fa0f0b6c496b7982d832b47e |
|
MD5 | 13a6037d4a0826069711e2e3fcba7db3 |
|
BLAKE2b-256 | a399816d59c385d8c4d8b36a2fa1af9e286010d1a7a02561208258e3f6dff6e9 |