コード例 #1
0
ファイル: test_peps.py プロジェクト: cyclops-community/koala
 def test_contract_vector(self, backend):
     qstate = peps.random(3, 3, 2, backend=backend)
     statevector = qstate.statevector(contract_option=Snake())
     for contract_option in [BMPS(None), BMPS(ReducedSVD(16)), BMPS(RandomizedSVD(16)), BMPS(ImplicitRandomizedSVD(16))]:
         with self.subTest(contract_option=contract_option):
             contract_result = qstate.statevector(contract_option=contract_option)
             self.assertTrue(backend.allclose(statevector.tensor, contract_result.tensor))
コード例 #2
0
 def test_einsumsvd_options(self, tb):
     from tensorbackends.interface import ReducedSVD, RandomizedSVD, ImplicitRandomizedSVD
     a = tb.astensor(
         [[0, 2e-3j, 0, 0], [1e-3, 0, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4j]],
         dtype=complex)
     p = tb.astensor(
         [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
         dtype=complex)
     s_true = tb.astensor([4, 3])
     low_rank = tb.astensor(
         [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4j]],
         dtype=complex)
     options = [
         ReducedSVD(rank=2),
         RandomizedSVD(rank=2, niter=2, oversamp=1),
         ImplicitRandomizedSVD(rank=2, niter=2)
     ]
     for option in options:
         with self.subTest(option=option):
             u, s, v = tb.einsumsvd('ij,jk->is,sk', p, a, option=option)
             usv = tb.einsum('is,s,sk->ik', u, s, v)
             self.assertEqual(u.shape, (4, 2))
             self.assertEqual(s.shape, (2, ))
             self.assertEqual(v.shape, (2, 4))
             self.assertTrue(tb.allclose(s, s_true))
             self.assertTrue(tb.allclose(usv, low_rank, atol=1e-9))
コード例 #3
0
ファイル: test_peps.py プロジェクト: cyclops-community/koala
 def test_contract_scalar(self, backend):
     qstate = peps.random(3, 4, 2, backend=backend)
     norm = qstate.norm(contract_option=Snake())
     for contract_option in contract_options:
         if contract_option is not Snake:
             for svd_option in (None, ReducedSVD(16), RandomizedSVD(16), ImplicitRandomizedSVD(16), ImplicitRandomizedSVD(16, orth_method='local_gram')):
                 with self.subTest(contract_option=contract_option.__name__, svd_option=svd_option):
                     self.assertTrue(backend.isclose(norm, qstate.norm(contract_option=contract_option(svd_option))))
コード例 #4
0
 def test_einsvd_options(self, tb):
     from tensorbackends.interface import ReducedSVD, RandomizedSVD
     a = tb.astensor([[1e-3,0,0,0],[0,2e-3j,0,0],[0,0,3,0],[0,0,0,4j]], dtype=complex).reshape(2,2,2,2)
     s_true = tb.astensor([4,3])
     low_rank = tb.astensor([[0,0,0,0],[0,0,0,0],[0,0,3,0],[0,0,0,4j]], dtype=complex)
     for option in [ReducedSVD(rank=2), RandomizedSVD(rank=2, niter=2, oversamp=1)]:
         with self.subTest(option=option):
             u, s, v = tb.einsvd('ijkl->(ij)s,s(kl)', a, option=option)
             usv = tb.einsum('is,s,sk->ik', u, s, v)
             self.assertEqual(u.shape, (4,2))
             self.assertEqual(s.shape, (2,))
             self.assertEqual(v.shape, (2,4))
             self.assertTrue(tb.allclose(s, s_true))
             self.assertTrue(tb.allclose(usv, low_rank, atol=1e-9))
コード例 #5
0
 def test_einsumsvd_absorb_s(self, tb):
     from tensorbackends.interface import ReducedSVD, RandomizedSVD, ImplicitRandomizedSVD
     a = tb.astensor([[0,2e-3j,0,0],[1e-3,0,0,0],[0,0,3,0],[0,0,0,4j]], dtype=complex)
     p = tb.astensor([[0,1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]], dtype=complex)
     s_true = tb.astensor([4,3])
     low_rank = tb.astensor([[0,0,0,0],[0,0,0,0],[0,0,3,0],[0,0,0,4j]], dtype=complex)
     options = [
         ReducedSVD(rank=2),
         RandomizedSVD(rank=2, niter=2, oversamp=1),
         ImplicitRandomizedSVD(rank=2, niter=2, orth_method='qr'),
         ImplicitRandomizedSVD(rank=2, niter=2, orth_method='local_gram'),
     ]
     for option in options:
         for absorb_s in ['even', 'u', 'v']:
             with self.subTest(option=option):
                 u, _, v = tb.einsumsvd('ij,jk->is,sk', p, a, option=option, absorb_s=absorb_s)
                 usv = tb.einsum('is,sk->ik', u, v)
                 self.assertEqual(u.shape, (4,2))
                 self.assertEqual(v.shape, (2,4))
                 self.assertTrue(tb.allclose(usv, low_rank, atol=1e-9))