Esempio n. 1
0
 def test_mpo_zeros_like(self):
     A = MPO_rand(10, 7, phys_dim=3, normalize=False)
     Z = MPO_zeros_like(A)
     assert A @ Z == 0.0
     x1 = A.trace()
     x2 = (A + Z).trace()
     assert_allclose(x1, x2)
Esempio n. 2
0
 def test_mpo_zeros_like(self, cyclic):
     A = MPO_rand(10, 7, phys_dim=3, normalize=False, cyclic=cyclic)
     Z = MPO_zeros_like(A)
     assert A @ Z == 0.0
     assert Z.cyclic == cyclic
     x1 = A.trace()
     x2 = (A + Z).trace()
     assert_allclose(x1, x2)
Esempio n. 3
0
 def test_apply_mps(self, cyclic, site_ind_id):
     A = MPO_rand(8, 5, cyclic=cyclic)
     x = MPS_rand_state(8, 4, site_ind_id=site_ind_id, cyclic=cyclic)
     y = A.apply(x)
     assert y.max_bond() == 20
     assert isinstance(y, MatrixProductState)
     assert len(y.tensors) == 8
     assert y.site_ind_id == site_ind_id
Esempio n. 4
0
 def test_compress_mpo(self, cyclic):
     A = MPO_rand(12, 5, cyclic=cyclic)
     assert all(b == 5 for b in A.bond_sizes())
     A.expand_bond_dimension(10)
     assert all(b == 10 for b in A.bond_sizes())
     A.compress()
     assert all(b in (4, 5) for b in A.bond_sizes())
Esempio n. 5
0
 def test_dot_mpo(self):
     A, B = MPO_rand(8, 5), MPO_rand(8,
                                     5,
                                     upper_ind_id='q{}',
                                     lower_ind_id='w{}')
     C = A.apply(B)
     assert C.max_bond() == 25
     assert C.upper_ind_id == 'q{}'
     assert C.lower_ind_id == 'w{}'
     Ad, Bd, Cd = A.to_dense(), B.to_dense(), C.to_dense()
     assert_allclose(Ad @ Bd, Cd)
Esempio n. 6
0
 def test_apply_mpo(self, cyclic):
     A = MPO_rand(8, 5, cyclic=cyclic)
     B = MPO_rand(8,
                  5,
                  upper_ind_id='q{}',
                  lower_ind_id='w{}',
                  cyclic=cyclic)
     C = A.apply(B)
     assert C.max_bond() == 25
     assert C.upper_ind_id == 'q{}'
     assert C.lower_ind_id == 'w{}'
     Ad, Bd, Cd = A.to_dense(), B.to_dense(), C.to_dense()
     assert_allclose(Ad @ Bd, Cd)
Esempio n. 7
0
 def test_subtract_mpo(self, cyclic):
     a, b = MPO_rand(13, 7, cyclic=cyclic), MPO_rand(13, 7, cyclic=cyclic)
     x1 = a.trace() - b.trace()
     assert_allclose(x1, (a - b).trace())
     a -= b
     assert_allclose(x1, a.trace())
Esempio n. 8
0
 def test_upper_lower_ind_id_guard(self):
     A = MPO_rand(8, 5)
     with pytest.raises(ValueError):
         A.upper_ind_id = 'b{}'
     with pytest.raises(ValueError):
         A.lower_ind_id = 'k{}'