Skip to content

Commit

Permalink
unit test fixes for renorm change
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Apr 4, 2024
1 parent 6bc0064 commit 8cbcc38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion quimb/tensor/tensor_approx_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def construct_lanczos_tridiag_MPO(A, K, v0=None, initial_bond_dim=None,
bsz = A.phys_dim()**A.L
beta[1] = bsz # == sqrt(prod(A.shape))

compress_kws = {'max_bond': max_bond, 'method': 'svd'}
compress_kws = {'max_bond': max_bond, 'method': 'svd', "renorm": True}

for j in range(1, K + 1):

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tensor/test_belief_propagation/test_l2bp.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_compress_double_layer_loopy(dtype, damping, update):
# compress using basic local compression
tn_eager = qtn.tensor_network_apply_op_vec(pepo, peps, contract=True)
assert tn_eager.num_tensors == 12
tn_eager.compress_all_(max_bond=3)
tn_eager.compress_all_(max_bond=3, canonize=False)
fid_basic = abs(tn_eager.H @ tn_lazy)

# compress using BP
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tensor/test_tensor_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ def test_compress_mps_right(self):
def test_compress_trim_max_bond(self, method):
p0 = MPS_rand_state(20, 20)
p = p0.copy()
p.compress(method=method)
p.compress(method=method, renorm=True)
assert max(p["I4"].shape) == 20
p.compress(max_bond=13, method=method)
p.compress(max_bond=13, method=method, renorm=True)
assert max(p["I4"].shape) == 13
assert_allclose(p.H @ p, p0.H @ p0)

Expand Down
20 changes: 14 additions & 6 deletions tests/test_tensor/test_tensor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,22 +525,30 @@ def test_renorm(self, method):
assert fn2 == pytest.approx(385.0)
assert trc == pytest.approx(55.0)

tn2 = t.split("a", method="svd", cutoff=0.1, cutoff_mode="rsum2")
tn2 = t.split(
"a", method="svd", cutoff=0.1, renorm=True, cutoff_mode="rsum2"
)
a_fn2 = tn2.H @ tn2
assert qtn.bonds_size(*tn2) == 6
assert a_fn2 == pytest.approx(fn2)

tn2 = t.split("a", method="svd", cutoff=40, cutoff_mode="sum2")
tn2 = t.split(
"a", method="svd", cutoff=40, renorm=True, cutoff_mode="sum2"
)
a_fn2 = tn2.H @ tn2
assert qtn.bonds_size(*tn2) == 6
assert a_fn2 == pytest.approx(fn2)

tn1 = t.split("a", method="svd", cutoff=0.2, cutoff_mode="rsum1")
tn1 = t.split(
"a", method="svd", cutoff=0.2, renorm=True, cutoff_mode="rsum1"
)
a_trc = tn1.trace("a", "b").real
assert qtn.bonds_size(*tn1) == 6
assert a_trc == pytest.approx(trc)

tn1 = t.split("a", method="svd", cutoff=11, cutoff_mode="sum1")
tn1 = t.split(
"a", method="svd", cutoff=11, renorm=True, cutoff_mode="sum1"
)
a_trc = tn1.trace("a", "b").real
assert qtn.bonds_size(*tn1) == 6
assert a_trc == pytest.approx(trc)
Expand Down Expand Up @@ -1450,15 +1458,15 @@ def test_compress_between(self, method):
B.expand_ind("d", 10)
tn = A | B
assert A.shared_bond_size(B) == 10
tn.compress_between("T1", "T2", method=method)
tn.compress_between("T1", "T2", method=method, mode="basic")
assert A.shared_bond_size(B) == 5

@pytest.mark.parametrize("method", ["svd", "eig", "isvd", "svds", "rsvd"])
def test_compress_all(self, method):
k = MPS_rand_state(10, 7)
k += k
k /= 2
k.compress_all_(max_bond=7, method=method)
k.compress_all_(max_bond=7, method=method, mode="basic")
assert k.max_bond() == 7
assert_allclose(k.H @ k, 1.0)

Expand Down

0 comments on commit 8cbcc38

Please sign in to comment.