Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

add svd #459

Merged
merged 226 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
226 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
abdcd8e
Quantum abstractions (#379)
amilsted Dec 12, 2019
a8ab55a
adding random uniform initialization (#412)
summer-bebop Dec 12, 2019
d228f61
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 14, 2019
46aeec1
replace kron with broadcasting
mganahl Dec 14, 2019
c73a511
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 15, 2019
6844f2c
column-major -> row-major
mganahl Dec 15, 2019
4f4ba93
documentation
mganahl Dec 15, 2019
8a5dbfd
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 15, 2019
d583e2b
added function to compute unique charges and charge degeneracies
mganahl Dec 17, 2019
b9f45cb
improved block finding, fixed bug in reshape
mganahl Dec 18, 2019
69309eb
fuse_charge_pair added
mganahl Dec 18, 2019
5026ed3
use is_leave
mganahl Dec 18, 2019
8ada65d
new tests
mganahl Dec 18, 2019
11ab7c0
removed TODO, BlockSparseTensor.shape returns ref instead of copy
mganahl Dec 18, 2019
04c4028
added tests
mganahl Dec 18, 2019
e521d35
added tests
mganahl Dec 18, 2019
3fec7ba
column-major -> row-major
mganahl Dec 19, 2019
a6f91a6
fix broken tests
mganahl Dec 19, 2019
7f4f3ce
test added
mganahl Dec 19, 2019
86adb1b
mostly docstring
mganahl Dec 19, 2019
5657456
docstring
mganahl Dec 19, 2019
1a07b78
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 19, 2019
a89d972
added map_to_integer
mganahl Dec 20, 2019
1faf8c1
test for map_to_integer
mganahl Dec 20, 2019
053dcbe
added functions to find sparse positions when fusing two charges
mganahl Dec 20, 2019
3076ff0
renaming of routines
mganahl Dec 20, 2019
386d177
added unfuse
mganahl Dec 20, 2019
f32edc3
test unfuse
mganahl Dec 20, 2019
2048841
fixed bug in the new routine for finding diagonal blocks
mganahl Dec 20, 2019
0c4f557
test added
mganahl Dec 20, 2019
69afbb6
docstring
mganahl Dec 20, 2019
d7d02be
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 20, 2019
b739015
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Dec 20, 2019
9981237
added tests
mganahl Dec 20, 2019
08b9a15
renaming
mganahl Dec 21, 2019
4a7d0b6
tests
mganahl Dec 21, 2019
00c279e
transpose added, map_to_integer removed
mganahl Dec 24, 2019
21fe636
find_dense_positions made faster
mganahl Dec 27, 2019
7c4b849
working on transpose
mganahl Dec 27, 2019
4d80da2
transpose modified
mganahl Dec 30, 2019
1a2238f
Index.name -> property
mganahl Dec 30, 2019
9b417b7
added charge types
mganahl Jan 1, 2020
b267322
adding tests
mganahl Jan 1, 2020
c1e75a1
fixing bugs
mganahl Jan 1, 2020
a1cf874
implementing more symmetries
mganahl Jan 2, 2020
f913898
typo + remove cython lookup
mganahl Jan 2, 2020
2707837
split charge.py from index.py
mganahl Jan 2, 2020
8865798
tests for charge.py
mganahl Jan 2, 2020
37d31c4
test added
mganahl Jan 2, 2020
03ce492
added matmul
mganahl Jan 2, 2020
71e67b2
added test for matmul
mganahl Jan 2, 2020
30dcbf8
tests + allow np.int8
mganahl Jan 2, 2020
8416b42
typo
mganahl Jan 2, 2020
33df922
undo typo
mganahl Jan 2, 2020
515870e
test\
mganahl Jan 2, 2020
841e59c
savety commit, starting to add multiple charges
mganahl Jan 3, 2020
0e74d49
Charge -> ChargeCollection
mganahl Jan 3, 2020
0c928ee
removed offsets from U1Charge (unnecessary), Charge -> ChargeCollection
mganahl Jan 3, 2020
fe1bd47
new tests
mganahl Jan 3, 2020
53c5063
tests for new index
mganahl Jan 3, 2020
707fb55
new Index class
mganahl Jan 3, 2020
5230997
new block tensor
mganahl Jan 3, 2020
71f3e2c
shorter code
mganahl Jan 3, 2020
dd6d992
add __eq__, remove nonzero, add unique
mganahl Jan 4, 2020
093d696
working on charges.py
mganahl Jan 4, 2020
e650938
fix small bug in BaseCharge.__init__
mganahl Jan 4, 2020
ea81cda
fix tests after bugfix
mganahl Jan 4, 2020
906e486
tests for equals() and __eq__
mganahl Jan 4, 2020
729fe6c
added equals()
mganahl Jan 4, 2020
a965e58
added typing
mganahl Jan 4, 2020
17224b1
ChargeCollection.__repr__ modified
mganahl Jan 4, 2020
b9c3de0
*** empty log message ***
mganahl Jan 4, 2020
656e2d5
this commit is not working
mganahl Jan 4, 2020
bb2966d
fix bug in __len__
mganahl Jan 4, 2020
84ded26
working in implemetation of multiple charges
mganahl Jan 4, 2020
be7f790
bugfix in ChargeCollection.__getitem__
mganahl Jan 5, 2020
884cf36
adding tests
mganahl Jan 5, 2020
8a581f3
sleep commit
mganahl Jan 5, 2020
1f8adf5
added iterators
mganahl Jan 6, 2020
d729c56
ChargeCollection.__init__:
mganahl Jan 6, 2020
9987165
lunch commit
mganahl Jan 6, 2020
1c8455f
back from lunch
mganahl Jan 6, 2020
e43974c
tests added
mganahl Jan 6, 2020
6e5bd04
ported find_sparse_positions and find_diagonal_sparse_blocks to new c…
mganahl Jan 6, 2020
ab5c386
broken commit
mganahl Jan 6, 2020
1c70fb5
fixed bug in find_dense_positions
mganahl Jan 7, 2020
f5ed165
fix bug in find_dense_positions
mganahl Jan 7, 2020
ea4a1ab
docstring
mganahl Jan 7, 2020
604be26
fix bug in Index initialization
mganahl Jan 7, 2020
ec66d50
fix bug in Index initialization
mganahl Jan 7, 2020
4da8335
typo
mganahl Jan 7, 2020
6e5d9b9
remove __rmul__ calls of ChargeCollection and BaseCharge
mganahl Jan 8, 2020
a860208
removed __rmul__
mganahl Jan 8, 2020
180895c
removed some bugs inb transpose
mganahl Jan 8, 2020
9b30651
broken commit
mganahl Jan 8, 2020
4fea323
broken commit
mganahl Jan 8, 2020
4a47dc6
remove csr matrix, use search sorted
mganahl Jan 9, 2020
e0bfba9
remove unfuse, use divmod
mganahl Jan 9, 2020
955b900
broken commit, working on tensordot
mganahl Jan 9, 2020
05e7313
tensordot implemented, not tested
mganahl Jan 10, 2020
8e9f53e
removed commented codex
mganahl Jan 10, 2020
4102c76
fix tests
mganahl Jan 10, 2020
e23e628
fix tests
mganahl Jan 10, 2020
cb6d55a
added test for BlockSparseTensor back
mganahl Jan 10, 2020
93dbc01
renaming files
mganahl Jan 10, 2020
0b7f64b
fix tutorial, fix import
mganahl Jan 10, 2020
abb9cef
faster find_dense_positions
mganahl Jan 10, 2020
a8de6ac
compute reduced svd in `backends.numpy.decompositions.svd_decompostio…
orialb Jan 12, 2020
fd80aac
added intersect to BaseCharge
mganahl Jan 12, 2020
a0eff12
broken commmit (Apple sucks big time)
mganahl Jan 13, 2020
ca67919
broken commit
mganahl Jan 13, 2020
ff1b94a
broken commit
mganahl Jan 14, 2020
dc2739c
broken commit
mganahl Jan 14, 2020
8a4f8eb
Fixes for contract_between(). (#421)
amilsted Jan 14, 2020
83c39de
broken commit
mganahl Jan 14, 2020
0522f1a
broken
mganahl Jan 15, 2020
5816866
added `return_indices` to intersect
mganahl Jan 15, 2020
d0bb787
faster transpose + tensordot implementation
mganahl Jan 15, 2020
6478f03
Update requirements_travis.txt (#426)
Jan 17, 2020
707f38d
rewrote find_dense_positions to take multipe charges
mganahl Jan 20, 2020
16105ed
find_sparse_positions update to be a tiny bit faster
mganahl Jan 20, 2020
3be9a81
Remove duplicate Dockerfile from root directory (#431)
kshithijiyer Jan 20, 2020
83ff4af
BaseNode / Edge class name type check protection add (#424)
IllgamhoDuck Jan 20, 2020
b7c7e7c
fix bug in _get_diagonal_dense_blocks
mganahl Jan 20, 2020
2df212e
fix bug
mganahl Jan 20, 2020
bbfe1f0
fixed bug in transpose
mganahl Jan 20, 2020
a814de8
Test network operations (#441)
MichaelMarien Jan 21, 2020
1d5c53c
Rename backend shape methods (google#355) (#436)
kosehy Jan 21, 2020
d8772bb
fixed final_order passing for tensordot
mganahl Jan 21, 2020
e213de9
Added SAT Tutorial (#438)
olgOk Jan 21, 2020
c56c1fa
More Test! (#444)
MichaelMarien Jan 22, 2020
aa3caec
Return empty dict for empty sequence input to MPS left_envs and right…
AidanGG Jan 23, 2020
a159393
Issue #339. with tn.DefaultBackend(backend): support (#434)
katolikyan Jan 23, 2020
5d6ffc9
Algebraic operation add( + ), sub( - ), mul( * ), div( / ) for BaseNo…
IllgamhoDuck Jan 23, 2020
38e57ff
improved performance, but only u1 currently supported in this commit
mganahl Jan 26, 2020
7087127
Fix unsafe None checks (#449)
jayanthchandra Jan 26, 2020
ce21161
Backend test (#448)
MichaelMarien Jan 27, 2020
1dd23c9
Version bump for release
Jan 28, 2020
f18f70f
merging Glen's and my code
mganahl Jan 29, 2020
6f7caac
fix bug in unique
mganahl Jan 29, 2020
2646f26
adding/removing tests
mganahl Jan 29, 2020
71e542b
add benchmark file
mganahl Jan 29, 2020
b316544
adding files
mganahl Jan 29, 2020
d1d53e3
Merge remote-tracking branch 'upstream/master' into block_sparse_merged
mganahl Jan 29, 2020
8fad258
deleted some files
mganahl Jan 29, 2020
d51e94b
fix bug
mganahl Jan 29, 2020
2f55188
renaming and shortening
mganahl Jan 29, 2020
2c65f8b
cleaning up code
mganahl Jan 29, 2020
c52e843
cleaning up
mganahl Jan 29, 2020
6166ff7
removed _check_flows
mganahl Jan 29, 2020
9796708
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Jan 29, 2020
41b1488
remove a print
mganahl Jan 30, 2020
56522fd
fix bug
mganahl Jan 30, 2020
830ad64
nothing
mganahl Jan 30, 2020
d402758
fix big in flatten_meta_data
mganahl Jan 30, 2020
4c425b0
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Jan 30, 2020
9615d10
added bunch of tests
mganahl Jan 31, 2020
925a696
added inner and outer product
mganahl Jan 31, 2020
a7acb5c
removed binary tree, switched to a list of charges
mganahl Jan 31, 2020
919867e
added copy()
mganahl Jan 31, 2020
76db6ca
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Jan 31, 2020
f9b26af
bugfix
mganahl Jan 31, 2020
4105650
added __add__ __sub__ __mul__ __rmul__
mganahl Jan 31, 2020
d70ce28
added __eq__
mganahl Jan 31, 2020
6ad61a5
change dosctring
mganahl Jan 31, 2020
4c6c083
added svd
mganahl Feb 1, 2020
d325569
better check
mganahl Feb 1, 2020
ba045ec
Merge remote-tracking branch 'upstream/experimental_blocksparse' into…
mganahl Feb 1, 2020
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
119 changes: 110 additions & 9 deletions tensornetwork/block_tensor/block_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,40 @@ def init_random():

return cls(data=init_random(), indices=indices)

def __sub__(self, other: "BlockSparseTensor"):
if self.dense_shape != other.dense_shape:
raise ValueError("cannot subtract tensors with shapes {}and {}".format(
self.dense_shape, other.dense_shape))
if len(self.indices) != len(other.indices):
raise ValueError(
"cannot subtract tensors with different index-lengths {} and {}"
.format(len(self.indices), len(other.indices)))

if not np.all(
self.indices[n] == other.indices[n] for n in range(len(self.indices))):
raise ValueError("cannot subtract tensors non-matching indices")
return BlockSparseTensor(data=self.data - other.data, indices=self.indices)

def __add__(self, other: "BlockSparseTensor"):
if self.dense_shape != other.dense_shape:
raise ValueError("cannot add tensors with shapes {}and {}".format(
self.dense_shape, other.dense_shape))
if len(self.indices) != len(other.indices):
raise ValueError(
"cannot add tensors with different index-lengths {} and {}".format(
len(self.indices), len(other.indices)))

if not np.all(
self.indices[n] == other.indices[n] for n in range(len(self.indices))):
raise ValueError("cannot add tensors non-matching indices")
return BlockSparseTensor(data=self.data + other.data, indices=self.indices)

def __mul__(self, number: np.number):
return BlockSparseTensor(data=self.data * number, indices=self.indices)

def __rmul__(self, number: np.number):
return BlockSparseTensor(data=self.data * number, indices=self.indices)

@property
def rank(self):
return len(self.indices)
Expand All @@ -770,14 +804,6 @@ def shape(self) -> Tuple:
def dtype(self) -> Type[np.number]:
return self.data.dtype

@property
def flows(self):
return [i.flow for i in self.indices]

@property
def charges(self):
return [i.charges for i in self.indices]

@property
def flat_charges(self):
flat = []
Expand Down Expand Up @@ -957,7 +983,7 @@ def transpose(tensor: BlockSparseTensor,
Returns:
BlockSparseTensor: The transposed tensor.
"""
return tensor.transpose()
return tensor.transpose(order)


def outerproduct(tensor1: BlockSparseTensor,
Expand Down Expand Up @@ -1176,3 +1202,78 @@ def tensordot(
shapes_1[:, n1])] @ tensor2.data[tr_sparse_blocks_2[n2].reshape(
shapes_2[:, n2])]).ravel()
return BlockSparseTensor(data=data, indices=free_indices)


def svd(tensor: BlockSparseTensor,
full_matrices: Optional[bool] = True,
compute_uv: Optional[bool] = True,
hermitian: Optional[bool] = False):
if tensor.rank != 2:
raise NotImplementedError("SVD currently supports only rank-2 tensors.")

flat_charges = tensor.indices[0]._charges + tensor.indices[1]._charges
flat_flows = tensor.flat_flows
partition = len(tensor.indices[0].flat_charges)
blocks, charges, shapes = _find_diagonal_sparse_blocks(
flat_charges, flat_flows, partition)

u_blocks = []
singvals = []
v_blocks = []
for n in range(len(blocks)):
u, s, v = np.linalg.svd(
np.reshape(tensor.data[blocks[n]], shapes[:, n]), full_matrices,
compute_uv, hermitian)
u_blocks.append(u)
v_blocks.append(v)
singvals.append(np.diag(s))

#define the new charges on the two central bonds
new_left_charge = charges.__new__(type(charges))
new_right_charge = charges.__new__(type(charges))
left_charge_labels = np.concatenate([
np.full(u_blocks[n].shape[1], fill_value=n, dtype=np.int16)
for n in range(len(u_blocks))
])
right_charge_labels = np.concatenate([
np.full(v_blocks[n].shape[0], fill_value=n, dtype=np.int16)
for n in range(len(v_blocks))
])
left_singval_charge = charges.__new__(type(charges))
right_singval_charge = charges.__new__(type(charges))
left_singval_charge_labels = np.concatenate([
np.full(singvals[n].shape[0], fill_value=n, dtype=np.int16)
for n in range(len(singvals))
])
right_singval_charge_labels = np.concatenate([
np.full(singvals[n].shape[1], fill_value=n, dtype=np.int16)
for n in range(len(singvals))
])

new_left_charge.__init__(charges.unique_charges, left_charge_labels,
charges.charge_types)
new_right_charge.__init__(charges.unique_charges, right_charge_labels,
charges.charge_types)
left_singval_charge.__init__(charges.unique_charges,
left_singval_charge_labels, charges.charge_types)
right_singval_charge.__init__(
charges.unique_charges, right_singval_charge_labels, charges.charge_types)

#get the indices of the new tensors U,S and V
indices_u = [Index(new_left_charge, True), tensor.indices[0]]
indices_v = [Index(new_right_charge, False), tensor.indices[1]]
indices_s = [
Index(left_singval_charge, False),
Index(right_singval_charge, True)
]

#We fill in data into the transposed U
#TODO: reuse data from _find_diagonal_sparse_blocks above
#to avoid the transpose
return BlockSparseTensor(
np.concatenate([np.ravel(u.T) for u in u_blocks]), indices_u).transpose(
(1, 0)), BlockSparseTensor(
np.concatenate([np.ravel(s) for s in singvals]),
indices_s), BlockSparseTensor(
np.concatenate([np.ravel(v) for v in v_blocks]),
indices_v), u_blocks, v_blocks, charges
21 changes: 17 additions & 4 deletions tensornetwork/block_tensor/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@
class Index:
"""
An index class to store indices of a symmetric tensor.
An index keeps track of all its childs by storing references
to them (i.e. it is a binary tree).
"""

def __init__(self,
charges: Union[List[BaseCharge], BaseCharge],
flow: Union[List[int], int],
name: Optional[Union[List[Text], Text]] = None) -> None:
"""
Initialize an `Index` object.
"""
if isinstance(charges, BaseCharge):
charges = [charges]
self._charges = charges
if isinstance(flow, (np.bool_, bool, np.bool)):
if np.isscalar(flow):
flow = [flow]
if not all([isinstance(f, (np.bool_, np.bool, bool)) for f in flow]):
raise TypeError("flows have to be boolean")
raise TypeError("flows have to be boolean. Found flow = {}".format(flow))
self.flow = flow
if isinstance(name, str):
name = [name]
Expand All @@ -51,6 +52,18 @@ def __repr__(self):
def dim(self):
return np.prod([i.dim for i in self._charges])

def __eq__(self, other):
if len(other._charges) != len(self._charges):
return False
for n in range(len(self._charges)):
if not np.all(
self._charges[n].unique_charges == other._charges[n].unique_charges):
return False
if not np.all(
self._charges[n].charge_labels == other._charges[n].charge_labels):
return False
return True

def copy(self):
"""
Returns:
Expand Down