Skip to main content

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

Reason this release was yanked:

this version was build for mkl==2019 but the dependence is on mkl==2021.4 which can introduce wrong results.

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

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

Uploaded Source

Built Distributions

pyblock3-0.2.7-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (80.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64

pyblock3-0.2.7-cp310-cp310-macosx_12_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pyblock3-0.2.7-cp310-cp310-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

pyblock3-0.2.7-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (80.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pyblock3-0.2.7-cp39-cp39-macosx_12_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pyblock3-0.2.7-cp39-cp39-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

pyblock3-0.2.7-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (80.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyblock3-0.2.7-cp38-cp38-macosx_12_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.8 macOS 12.0+ ARM64

pyblock3-0.2.7-cp38-cp38-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyblock3-0.2.7-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (80.0 MB view details)

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

pyblock3-0.2.7-cp37-cp37m-macosx_12_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.7m macOS 12.0+ ARM64

pyblock3-0.2.7-cp37-cp37m-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: pyblock3-0.2.7.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

Hashes for pyblock3-0.2.7.tar.gz
Algorithm Hash digest
SHA256 364c628ecf356d7e4230ef552bcf16508e69d502fa41633a7905bd37982a4bba
MD5 f92221335a272a1c3718670eb215dece
BLAKE2b-256 9c2d91719d7831f43c53be89601b25d91511e853b1facfe8d55cc26b57336aa0

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 138a4813b94acd089ef9277a619bf76006c94ef445b3743f9b7ce008f11c64e8
MD5 046dba55a717177b8f2fd94469eeb84d
BLAKE2b-256 bbe36abdfba53dc2119d481dca7e40c255e5408ae713156236b32933f1174c01

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 e27d282521294d5f15c2e110882a9344689fa3b59fbbb35470754dbb8c9cac2f
MD5 67a7169f9f4d172c461df181f8fae93e
BLAKE2b-256 39b3c51c7898d5b02785c6c4aa2a89e8d9aab3e31c59708e1c2715e67f24898a

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 a44dc029383fd0e3d0947de7bb248c6ef48fd35aee75c51f493786a960c8205e
MD5 f9420cd240d8340c57a1fa0937b2f598
BLAKE2b-256 481b02b4b260b2116187da24d0a7c9c9459e03e6267955d51912a6ba9f112ab0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 57f39c920521310cf3e91e20ea661598012bc5b6fc888e949b86345281d15da2
MD5 52b6f89864003e51c8e2294bc9715d7e
BLAKE2b-256 6b5656619668d020480276a9ed89a1361922edb91ad59005a495717548616193

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 2661829bffd856fb5160bf0cab823a388030643df1d08221f39b6cb2c6de09c4
MD5 0ee8ed3434c3cba23855f54ae78a1a7e
BLAKE2b-256 16272d66b28f25bd203b493111aaa81985489abb573fed277c88389e16576154

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 13fc70c6ecd23aeaf6cc4bb9942af452bb90788f09b25bf578a2eb03f1886772
MD5 bee06adebf226a6d8548cfb6640f330b
BLAKE2b-256 0e827e3e8e2ce885cf866c8f29c804834fb7eb384567d2115bef222acd4eb2eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 72380a60df5ccb251458874f4a510b91c9c256c557e90d41ecb13ada742068eb
MD5 536cda92ed71e0ac67fbf0060c922530
BLAKE2b-256 814b26d0ec2c0bd0e8e8819589b6307872c0a776f16025993ce760237e4c36db

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp38-cp38-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 f3148b87164e15e24ed4d454861def4756af33a4f1652dabff48f8a7fba24bc8
MD5 803e039ded2f3270d9378258549c06a1
BLAKE2b-256 a8e39060f71fbec28ab94f71b0f64885817dd689cf30628ebd80716a528204b2

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 85ae18f80ce6f68f5440dde3a9131e77967c15c9c9d7b721ed561542546ea698
MD5 9bbf54f112796f9f929fd6008309f1b5
BLAKE2b-256 5e62567a6b1d041864bbff78687c95ffbbbcaef1dc512dee082c023e0649183f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0c572dc07e4628b027ec2b89eff6d1cfb2555a73122c626a50e682f61e496d04
MD5 0fd7ed219faa2db452a9dfca29ff326e
BLAKE2b-256 ecf29abad2bf8fd4fb91617ae94b6a9d8651c30400374f1c23bf46582e337bba

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp37-cp37m-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp37-cp37m-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 984e7c1d2fd24c181ba24b9bdae720043070ddf46091e2c83af18d70b2df1acf
MD5 371ca52b95e8e348f3d2a0145757a15f
BLAKE2b-256 6818684b25736d8bd7e080a217b20694b6074fc582b77e96c434394915f41c09

See more details on using hashes here.

File details

Details for the file pyblock3-0.2.7-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyblock3-0.2.7-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 653cc529d64b3b02ca4c9e0bd84afeb08fa751d3c4d7c953bd00c0e57c1406a5
MD5 6014d162a51604c8c79ac638ad3f9f34
BLAKE2b-256 1d7a7e4492f1dd1b10a646094645578e86ff0579c918fabaa0a158343f1637fe

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