Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
63cddc4
started implementing block-sparse tensors
mganahl Oct 22, 2019
2910b27
removed files
mganahl Oct 22, 2019
6dafdd7
Merge remote-tracking branch 'upstream/master' into block_sparse
mganahl Oct 24, 2019
46f1e10
working on AbelianIndex
mganahl Oct 25, 2019
9ba1d21
Merge remote-tracking branch 'upstream/master' into block_sparse
mganahl Nov 28, 2019
91f32a6
working in block sparisty
mganahl Nov 29, 2019
58feabc
added reshape
mganahl Nov 30, 2019
307f2dc
added Index, an index type for symmetric tensors
mganahl Nov 30, 2019
1ebbc7f
added small tutorial
mganahl Nov 30, 2019
1eb3d6f
added docstring
mganahl Nov 30, 2019
d25d8aa
fixed bug in retrieve_diagonal_blocks
mganahl Nov 30, 2019
ae8cda6
TODO added
mganahl Nov 30, 2019
bbac9c4
improved initialization a bit
mganahl Nov 30, 2019
db828c7
more efficient initialization
mganahl Dec 1, 2019
99204f7
just formatting
mganahl Dec 1, 2019
73a9628
added random
mganahl Dec 1, 2019
efa64a4
added fuse_degeneracies
mganahl Dec 1, 2019
7619162
fixed bug in reshape
mganahl Dec 1, 2019
2be30a9
dosctring, typing
mganahl Dec 1, 2019
742824f
removed TODO
mganahl Dec 1, 2019
2e6c395
removed confusing code line
mganahl Dec 1, 2019
ab13d4a
bug removed
mganahl Dec 1, 2019
d375b1d
comment
mganahl Dec 1, 2019
2727cd0
added __mul__ to Index
mganahl Dec 2, 2019
283e364
added sparse_shape
mganahl Dec 2, 2019
7328ad4
more in tutorial
mganahl Dec 2, 2019
e5b6147
comment
mganahl Dec 2, 2019
eb91c79
added new test function
mganahl Dec 2, 2019
a544dbc
testing function hacking
mganahl Dec 2, 2019
0457cca
docstring
mganahl Dec 2, 2019
95958a7
small speed up
mganahl Dec 3, 2019
ac3d980
Remove gui directory (migrated to another repo) (#399)
coryell Dec 3, 2019
5d2d2ba
a slightly more elegant code
mganahl Dec 7, 2019
04eadf3
use one more np function
mganahl Dec 7, 2019
2ea5674
removed some crazy slow code
mganahl Dec 7, 2019
5d8c86a
faster code
mganahl Dec 7, 2019
22a642e
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 7, 2019
4eae410
Update README.md (#404)
Dec 9, 2019
04c8573
add return_data
mganahl Dec 9, 2019
7c2d5a0
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 9, 2019
29bb154
Merge remote-tracking branch 'upstream/master' into block_sparse
mganahl Dec 9, 2019
33d1a40
doc
mganahl Dec 9, 2019
fb1978a
bug fix
mganahl Dec 9, 2019
5228f56
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 9, 2019
0d4a625
a little faster
mganahl Dec 11, 2019
82a4148
substantial speedup
mganahl Dec 11, 2019
7bd7be7
renaming
mganahl Dec 11, 2019
7a8c7df
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 11, 2019
d9c094b
removed todo
mganahl Dec 11, 2019
06c3f3c
some comments
mganahl Dec 11, 2019
426fd1a
comments
mganahl Dec 11, 2019
7f3e148
fixed some bug in reshape
mganahl Dec 11, 2019
19c3fe8
comments
mganahl Dec 11, 2019
5c8fd3e
default value changed
mganahl Dec 11, 2019
94c8c2c
fixed bug, old version is now faster again
mganahl Dec 12, 2019
7eec7f0
cleaned up reshape
mganahl Dec 12, 2019
c188ab9
started adding tests
mganahl Dec 12, 2019
d7ab7ab
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 12, 2019
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
24 changes: 7 additions & 17 deletions tensornetwork/block_tensor/block_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ def compute_nonzero_block_shapes(charges: List[np.ndarray],
return charge_shape_dict


def retrieve_non_zero_diagonal_blocks_deprecated(
def retrieve_non_zero_diagonal_blocks(
data: np.ndarray,
charges: List[np.ndarray],
flows: List[Union[bool, int]],
return_data: Optional[bool] = True) -> Dict:
"""
Given the meta data and underlying data of a symmetric matrix, compute
all diagonal blocks and return them in a dict.
This is a deprecated version which in general performs worse than the
current main implementation.
Args:
data: An np.ndarray of the data. The number of elements in `data`
has to match the number of non-zero elements defined by `charges`
Expand Down Expand Up @@ -236,14 +234,17 @@ def retrieve_non_zero_diagonal_blocks_deprecated(
return blocks


def retrieve_non_zero_diagonal_blocks(
def retrieve_non_zero_diagonal_blocks_deprecated(
data: np.ndarray,
charges: List[np.ndarray],
flows: List[Union[bool, int]],
return_data: Optional[bool] = False) -> Dict:
"""
Given the meta data and underlying data of a symmetric matrix, compute
all diagonal blocks and return them in a dict.
This is a deprecated version which in general performs worse than the
current main implementation.

Args:
data: An np.ndarray of the data. The number of elements in `data`
has to match the number of non-zero elements defined by `charges`
Expand Down Expand Up @@ -287,7 +288,6 @@ def retrieve_non_zero_diagonal_blocks(
row_charges, return_inverse=True, return_counts=True)
unique_column_charges, column_locations, column_dims = np.unique(
column_charges, return_inverse=True, return_counts=True)

#convenience container for storing the degeneracies of each
#row and column charge
row_degeneracies = dict(zip(unique_row_charges, row_dims))
Expand All @@ -300,12 +300,11 @@ def retrieve_non_zero_diagonal_blocks(

degeneracy_vector = row_dims[column_locations]
stop_positions = np.cumsum(degeneracy_vector)

blocks = {}
for c in common_charges:
#numpy broadcasting is substantially faster than kron!
a = np.expand_dims(
stop_positions[column_locations == -c] - row_degeneracies[c], 0)
stop_positions[column_charges == -c] - row_degeneracies[c], 0)
b = np.expand_dims(np.arange(row_degeneracies[c]), 1)
if not return_data:
blocks[c] = [a + b, (row_degeneracies[c], column_degeneracies[-c])]
Expand Down Expand Up @@ -572,16 +571,7 @@ def raise_error():
if self.shape[n] > dense_shape[n]:
raise_error()
elif dense_shape[n] < self.shape[n]:
while dense_shape[n] < self.shape[n]:
#split index at n
try:
i1, i2 = split_index(self.indices.pop(n))
except ValueError:
raise_error()
self.indices.insert(n, i1)
self.indices.insert(n + 1, i2)
if self.shape[n] < dense_shape[n]:
raise_error()
raise_error()

def get_diagonal_blocks(self, return_data: Optional[bool] = True) -> Dict:
"""
Expand Down
2 changes: 0 additions & 2 deletions tensornetwork/block_tensor/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from tensornetwork.network_components import Node, contract, contract_between
# pylint: disable=line-too-long
from tensornetwork.backends import backend_factory

import numpy as np
import copy
from typing import List, Union, Any, Optional, Tuple, Text

Expand Down
46 changes: 46 additions & 0 deletions tensornetwork/block_tensor/index_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
# pylint: disable=line-too-long
from tensornetwork.block_tensor.index import Index, fuse_index_pair, split_index, fuse_charges, fuse_degeneracies


def test_fuse_charges():
q1 = np.asarray([0, 1])
q2 = np.asarray([2, 3, 4])
fused_charges = fuse_charges(q1, 1, q2, 1)
assert np.all(fused_charges == np.asarray([2, 3, 3, 4, 4, 5]))
fused_charges = fuse_charges(q1, 1, q2, -1)
assert np.all(fused_charges == np.asarray([-2, -1, -3, -2, -4, -3]))


def test_index_fusion_mul():
D = 100
B = 4
dtype = np.int16
q1 = np.random.randint(-B // 2, B // 2 + 1,
D).astype(dtype) #quantum numbers on leg 1
q2 = np.random.randint(-B // 2, B // 2 + 1,
D).astype(dtype) #quantum numbers on leg 2
i1 = Index(charges=q1, flow=1, name='index1') #index on leg 1
i2 = Index(charges=q2, flow=1, name='index2') #index on leg 2

i12 = i1 * i2
assert i12.left_child is i1
assert i12.right_child is i2
assert np.all(i12.charges == fuse_charges(q1, 1, q2, 1))


def test_index_fusion():
D = 100
B = 4
dtype = np.int16
q1 = np.random.randint(-B // 2, B // 2 + 1,
D).astype(dtype) #quantum numbers on leg 1
q2 = np.random.randint(-B // 2, B // 2 + 1,
D).astype(dtype) #quantum numbers on leg 2
i1 = Index(charges=q1, flow=1, name='index1') #index on leg 1
i2 = Index(charges=q2, flow=1, name='index2') #index on leg 2

i12 = fuse_index_pair(i1, i2)
assert i12.left_child is i1
assert i12.right_child is i2
assert np.all(i12.charges == fuse_charges(q1, 1, q2, 1))