Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fermion Tensor Network Framework #88

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3c5be57
first commit, fermion Tensor, TensorNetwork, PEPS implemented
yangcal Dec 16, 2020
5c0c41d
col env added & cleanup
yangcal Dec 17, 2020
7fa7ce2
remove _move/left func, setup for bond compress
yangcal Dec 17, 2020
92ee274
compress added
yangcal Dec 23, 2020
c5dc467
bugfix for ftensor shape; fermion_2d.compute_row/col_environment conf…
yangcal Jan 6, 2021
d0caf9f
bugfix in reorder iterator
yangcal Jan 6, 2021
bb8008e
1. bugfix 2. reorganize fermion funcs(compress, contract), canonize a…
yangcal Jan 8, 2021
37af5f4
ind_size reimplementation
yangcal Jan 8, 2021
2895394
bugfix in tensor split, multiply_index_diagonal addded
yangcal Jan 12, 2021
d1b4c78
bugfix for connect_funcs when 2nd tensor is before 1st one in f.s.
yangcal Jan 12, 2021
f65596d
bugfix in reorder; fix connected_contract
yangcal Jan 13, 2021
56ab63e
bugfix for tensor_contract when output_inds given
yangcal Jan 13, 2021
6b615c9
fix bug in fs.replace_tensor
yangcal Jan 14, 2021
4909895
add fermion_2d.gate
yangcal Jan 14, 2021
ca7f463
bugfix for definition of tensor order in contract/split/compress
yangcal Jan 20, 2021
2f604b8
add fermion operators
yangcal Jan 20, 2021
87f9331
bug fix in dense boundary contraction
yangcal Jan 20, 2021
88705f5
add tn.contract method; introduce compute_norm in 2d ftns
yangcal Jan 20, 2021
ec96e26
fermion operators exponential added; operator tests added
yangcal Jan 26, 2021
212032f
2d.compute_local_expectation added
yangcal Jan 26, 2021
571c13c
fix exponential sign
yangcal Jan 26, 2021
13f71c6
reorganize
yangcal Jan 26, 2021
479399b
add fermion tensor norm, rename operator identity
yangcal Jan 27, 2021
32afdbc
add tensor_balance_bonds
yangcal Jan 27, 2021
794c748
add hubbard module; bugfix
yangcal Jan 29, 2021
1a1d032
fermion_2d_tebd added
yangcal Jan 30, 2021
7184740
rescale random fermion tensors
yangcal Feb 2, 2021
b0703c5
Merge remote-tracking branch 'upstream/develop' into develop
yangcal Feb 2, 2021
77567cf
first syn
yangcal Feb 2, 2021
dd2d8cb
rename to_exponential
yangcal Feb 2, 2021
5547c01
fixup to merge with upstream
yangcal Feb 2, 2021
6e770d4
add fermion unittest
yangcal Feb 2, 2021
51f046e
cleanup and add docstring
yangcal Feb 4, 2021
24867b3
bugfix, cleanup and adding docstring
yangcal Feb 4, 2021
d0c6f5d
docstring added, remove fermion_ops module and move it to pyblock3 ba…
yangcal Feb 5, 2021
4294d73
add chemical potential support in Hubbard, cleanup
yangcal Feb 8, 2021
d96bc34
API for QPN modified
yangcal Feb 25, 2021
bb32839
bugfix
yangcal Mar 3, 2021
8201017
parse compress opts to canonize_row/column when contracting boundary
yangcal Apr 2, 2021
5754ccc
restructure to stay consistent with new pyblock3 API; add compression…
yangcal Apr 2, 2021
8659d5d
bug fix for gauge ordering in SimpleUpdate
yangcal Apr 11, 2021
3998bc3
bug fix for numerics test
yangcal Apr 11, 2021
f6aa564
API adjustment and cleanup; rename modules in effort for general boso…
yangcal Apr 15, 2021
ea95802
cleanup and revert tensor_2d
yangcal Apr 26, 2021
382738a
merge recent develop change
yangcal Apr 26, 2021
07117fd
refactor fermion module; tensor_block module added for general symmetry
yangcal Apr 28, 2021
25cfc36
clean up tensor_core module
yangcal Apr 28, 2021
1b0be8e
fix bug when there is only one operand in tensor_contract
yangcal Apr 28, 2021
20bac5c
bugfix in canonize
yangcal Apr 30, 2021
2ac25d4
split gate index fix
yangcal May 3, 2021
7d4b531
fix bug for python backend
yangcal May 5, 2021
160f579
doc added
yangcal May 6, 2021
3be6717
clean up old tests
yangcal May 6, 2021
b4b9496
remove test files
yangcal May 6, 2021
90add79
add func to obtain contraction path for block tensors
yangcal May 21, 2021
1d83286
bugfix
yangcal May 21, 2021
e53892c
add random methods for block tensors and fermion PEPS
yangcal May 28, 2021
66d7775
Merge remote-tracking branch 'upstream/develop' into general
yangcal Jun 7, 2021
cb295ad
adjust to new _inds_to_eq
yangcal Jun 8, 2021
f1db686
bugfix
yangcal Jun 8, 2021
84e8942
bugfix in block_gen.gen_2d_bonds
yangcal Jun 14, 2021
2dc7bb7
typo fix in fermion_2d
yangcal Jun 14, 2021
f0fc03a
remove the reordering after environment construction
yangcal Jun 15, 2021
0a4b884
implement optimized reorder_all method, enable fermion_path attr
yangcal Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 403 additions & 0 deletions quimb/tensor/block_gen.py

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions quimb/tensor/block_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys
from pyblock3.algebra.fermion_symmetry import U11, U1, Z2, Z4, Z22
from pyblock3.algebra.symmetry import BondInfo
from pyblock3.algebra.fermion import eye, SparseFermionTensor
from pyblock3.algebra import fermion_setting as setting
from pyblock3.algebra import fermion_ops

this = sys.modules[__name__]
this.DEFAULT_SYMMETRY = "U1"
this.USE_CPP = True
this.USE_FERMION = True
symmetry_map = setting.symmetry_map

def set_symmetry(symmetry):
symmetry = symmetry.upper()
if symmetry not in symmetry_map:
raise KeyError("input symmetry %s not supported"%symmetry)
this.DEFAULT_SYMMETRY = symmetry
setting.set_symmetry(symmetry)

def set_backend(use_cpp):
this.USE_CPP = use_cpp
setting.set_flat(use_cpp)

def set_fermion(use_fermion):
this.USE_FERMION = use_fermion
setting.set_fermion(use_fermion)

def set_options(**kwargs):
symmetry = kwargs.pop("symmetry", this.DEFAULT_SYMMETRY)
use_fermion = kwargs.pop("fermion", this.USE_FERMION)
use_cpp = kwargs.pop("use_cpp", this.USE_CPP)
set_symmetry(symmetry)
set_fermion(use_fermion)
set_backend(use_cpp)

def dispatch_settings(*keys):
dict = {"symmetry": "DEFAULT_SYMMETRY",
"fermion": "USE_FERMION",
"use_cpp": "USE_CPP"}
_settings = []
for ikey in keys:
if ikey not in dict:
raise KeyError("%s not a valid backend setting"%ikey)
_settings.append(getattr(this, dict[ikey]))
if len(_settings) == 1:
_settings = _settings[0]
return _settings

def get_symmetry():
return setting.symmetry_map[this.DEFAULT_SYMMETRY]

to_exponential = fermion_ops.get_exponential
H1 = fermion_ops.H1
Hubbard = fermion_ops.Hubbard
onsite_U = fermion_ops.onsite_U
measure_SZ = fermion_ops.measure_SZ
ParticleNumber = fermion_ops.ParticleNumber
63 changes: 63 additions & 0 deletions quimb/tensor/block_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from quimb.tensor import block_interface as bitf
import numpy as np

def apply(T, func):
use_cpp = bitf.dispatch_settings("use_cpp")
if use_cpp:
new_T = T.copy()
new_T.data = func(new_T.data)
else:
new_T = T.copy()
for iblk in new_T:
iblk[:] = func(iblk[:])
return new_T

def sqrt(T):
_sqrt = lambda x : x**.5
return apply(T, _sqrt)

def inv_with_smudge(T, cutoff=1e-10, gauge_smudge=1e-6):
def _inv_with_smudge(arr):
new_arr = np.zeros(arr.shape, dtype=arr.dtype)
ind = abs(arr) > cutoff
new_arr[ind] = (arr[ind] + gauge_smudge) ** -1
return new_arr
return apply(T, _inv_with_smudge)

def add_with_smudge(T, cutoff=1e-10, gauge_smudge=1e-6):
def _add_with_smudge(arr):
ind = abs(arr) > cutoff
arr[ind] += gauge_smudge
return arr
return apply(T, _add_with_smudge)

def get_smudge_balance(T1, T2, ix, smudge):
flat = bitf.dispatch_settings("use_cpp")
if flat:
t1, t2 = T1.data.to_sparse(), T2.data.to_sparse()
else:
t1, t2 = T1.data, T2.data
sign1 = t1.pattern[T1.inds.index(ix)]
sign2 = t2.pattern[T2.inds.index(ix)]
s1_pattern = {"+":"-+", "-":"+-"}[sign1]
s2_pattern = {"-":"-+", "+":"+-"}[sign2]

inv = (sign1 == sign2)
block_cls = t1.blocks[0].__class__
block_dict = {}
for iblk1 in t1:
q0 = iblk1.q_labels[0]
block_dict[q0] = np.diag(np.asarray(iblk1)) + smudge
for iblk2 in t2:
q0 = -iblk2.q_labels[0] if inv else iblk2.q_labels[0]
if q0 not in block_dict: continue
block_dict[q0] = block_dict[q0] / (np.diag(np.asarray(iblk2)) + smudge)

s1 = [block_cls(reduced=np.diag(s**-0.25), q_labels=(qlab,)*2) for qlab, s in block_dict.items()]
s2 = [block_cls(reduced=np.diag(s** 0.25), q_labels=(qlab,)*2) for qlab, s in block_dict.items()]
s1 = t1.__class__(blocks=s1, pattern=s1_pattern)
s2 = t2.__class__(blocks=s2, pattern=s2_pattern)
if flat:
s1 = s1.to_flat()
s2 = s2.to_flat()
return s1, s2
Loading