Example #1
0
    def test_partial_tranpose(self):
        p = MPS_rand_state(8, 10)
        r = p.ptr([2, 3, 4, 5, 6, 7])
        rd = r.to_dense()

        assert qu.isherm(rd)
        assert qu.ispos(rd)

        rpt = r.partial_transpose([0, 1, 2])
        rptd = rpt.to_dense()

        upper_inds = tuple('b{}'.format(i) for i in range(6))
        lower_inds = tuple('k{}'.format(i) for i in range(6))
        outer_inds = rpt.outer_inds()
        assert all(i in outer_inds for i in upper_inds + lower_inds)

        assert qu.isherm(rptd)
        assert not qu.ispos(rptd)
Example #2
0
 def test_partial_trace(self, rescale):
     n = 10
     p = MPS_rand_state(n, 7)
     r = p.ptr(keep=[2, 3, 4, 6, 8],
               upper_ind_id='u{}',
               rescale_sites=rescale)
     rd = r.to_dense()
     if rescale:
         assert r.lower_inds == ('u0', 'u1', 'u2', 'u3', 'u4')
         assert r.upper_inds == ('k0', 'k1', 'k2', 'k3', 'k4')
     else:
         assert r.lower_inds == ('u2', 'u3', 'u4', 'u6', 'u8')
         assert r.upper_inds == ('k2', 'k3', 'k4', 'k6', 'k8')
     assert_allclose(r.trace(), 1.0)
     assert isherm(rd)
     pd = p.to_dense()
     rdd = pd.ptr([2] * n, keep=[2, 3, 4, 6, 8])
     assert_allclose(rd, rdd)
Example #3
0
 def test_partial_trace(self, rescale, keep):
     n = 10
     p = MPS_rand_state(n, 7)
     r = p.ptr(keep=keep, upper_ind_id='u{}', rescale_sites=rescale)
     rd = r.to_dense()
     if isinstance(keep, slice):
         keep = p.slice2sites(keep)
     else:
         if rescale:
             assert r.lower_inds == ('u0', 'u1', 'u2', 'u3', 'u4')
             assert r.upper_inds == ('k0', 'k1', 'k2', 'k3', 'k4')
         else:
             assert r.lower_inds == ('u2', 'u3', 'u4', 'u6', 'u8')
             assert r.upper_inds == ('k2', 'k3', 'k4', 'k6', 'k8')
     assert_allclose(r.trace(), 1.0)
     assert qu.isherm(rd)
     pd = p.to_dense()
     rdd = pd.ptr([2] * n, keep=keep)
     assert_allclose(rd, rdd)