Exemplo n.º 1
0
def test_local_overlap(N):
    import matplotlib.pyplot as plt
    plt.style.use('ggplot')
    L = 5
    width = 3
    fig, ax = plt.subplots(1, 5, sharex=True, sharey=True, figsize=(L*width, width+0.8))
    for k in range(0, L):
        real_overlaps = []
        approx_overlaps = []
        print(k)
        for _ in range(N):
            y = fMPS().random(L, 2, 3).left_canonicalise()
            x = y.copy().left_canonicalise(1)
            As = [list(range(i, i+1+k)) for i in range(L-k)]
            approx_overlaps.append(x.approx_overlap(y, As))
            real_overlaps.append(np.abs(x.overlap(y)**2))
        ax[k].set_xlabel(f'{k+1}-local approximate overlaps')
        ax[k].scatter(approx_overlaps, real_overlaps, marker='+')
    ax[0].set_ylabel('true overlap')
    fig.suptitle('$k$-local approx overlap: $\\frac{1}{N-k}\sum_{i=1}^{N-k} tr(\\rho^1_{i...i+k}\\rho^2_{i...i+k})$. Overlap between L=5, D=3 mps, and same mps truncated to D=1.')
    fig.tight_layout()
    fig.subplots_adjust(top=0.8)
    plt.savefig('overlaps.pdf')
Exemplo n.º 2
0
    def test_OTOCs_eye(self):
        """OTOC zero for W=eye"""
        Sx1, Sy1, Sz1 = N_body_spins(0.5, 1, 5)
        Sx2, Sy2, Sz2 = N_body_spins(0.5, 2, 5)
        Sx3, Sy3, Sz3 = N_body_spins(0.5, 3, 5)
        Sx4, Sy4, Sz4 = N_body_spins(0.5, 4, 5)
        Sx5, Sy5, Sz5 = N_body_spins(0.5, 5, 5)

        mps = fMPS().random(5, 2, None).left_canonicalise()
        W = mps.L * [MPO_TFI(0, 0.25, 0.5, 0.5)]
        H = Sz1@Sz2+Sz2@Sz3+Sz3@Sz4+Sz4@Sz5+\
                Sx1+Sx2+Sx3+Sx4+Sx5+\
                Sz1+Sz2+Sz3+Sz4+Sz5
        ops = eye(2**5), eye(2**5)
        ops_ = ((eye(2), 0), (eye(2), 0))
        T = linspace(0, 1, 3)
        F = Trajectory(mps, H=H, W=W)
        ed_evs = F.ed_OTOC(T, ops)
        mps_evs = F.mps_OTOC(T, ops_)
        plt.plot(mps_evs)
        plt.show()
        self.assertTrue(allclose(ed_evs, 0))
        self.assertTrue(allclose(mps_evs, 0))
Exemplo n.º 3
0
    def setUp(self):
        """setUp"""
        self.N = N = 4  # Number of MPSs to test
        #  min and max params for randint
        L_min, L_max = 7, 8
        d_min, d_max = 2, 3
        D, D_sq = 3, 9
        # N random MPSs
        self.pure_cases = [
            fTFD().random(randint(L_min, L_max),
                          randint(d_min, d_max),
                          D=D,
                          pure=True) for _ in range(N)
        ]
        self.mixed_cases = [
            fTFD().random(randint(L_min, L_max),
                          randint(d_min, d_max),
                          D=D_sq,
                          pure=False) for _ in range(N)
        ]

        psi_0_2 = load('../../tests/fixtures/mat2x2.npy')
        self.tfd_0_2 = fTFD().from_fMPS(fMPS().left_from_state(psi_0_2))
Exemplo n.º 4
0
    def test_OTOCs_ed(self):
        """test mps otocs against ed"""
        Sx1, Sy1, Sz1 = N_body_spins(0.5, 1, 5)
        Sx2, Sy2, Sz2 = N_body_spins(0.5, 2, 5)
        Sx3, Sy3, Sz3 = N_body_spins(0.5, 3, 5)
        Sx4, Sy4, Sz4 = N_body_spins(0.5, 4, 5)
        Sx5, Sy5, Sz5 = N_body_spins(0.5, 5, 5)

        mps = fMPS().random(5, 2, None).left_canonicalise()
        W = mps.L * [MPO_TFI(0, 0.25, 0.5, 0.5)]
        H = Sz1@Sz2+Sz2@Sz3+Sz3@Sz4+Sz4@Sz5+\
                Sx1+Sx2+Sx3+Sx4+Sx5+\
                Sz1+Sz2+Sz3+Sz4+Sz5
        ops = Sz2, Sz5
        ops_ = ((Sz, 1), (Sz, 4))
        T = linspace(0, 1, 3)
        F = Trajectory(mps, H=H, W=W, fullH=True)
        ed_evs = F.ed_OTOC(T, ops)
        mps_evs = F.mps_OTOC(T, ops_)
        plt.plot(mps_evs)
        plt.plot(ed_evs)
        plt.show()
        self.assertTrue(allclose(ed_evs, 0))
        self.assertTrue(allclose(mps_evs, 0))
Exemplo n.º 5
0
    def setUp(self):
        """setUp"""
        self.N = N = 5  # Number of MPSs to test
        #  min and max params for randint
        L_min, L_max = 7, 8
        d_min, d_max = 2, 3
        D_min, D_max = 9, 10
        ut_min, ut_max = 3, 7
        # N random MPSs
        self.rand_cases = [fMPS().random(randint(L_min, L_max),
                                         randint(d_min, d_max),
                                         randint(D_min, D_max))
                           for _ in range(N)]
        # N random MPSs, right canonicalised and truncated to random D
        self.right_cases = [fMPS().random(
                            randint(L_min, L_max),
                            randint(d_min, d_max),
                            randint(D_min, D_max)).right_canonicalise(
                            randint(D_min, D_max))
                            for _ in range(N)]
        self.right_ortho_cases = [fMPS().random(
                                randint(L_min, L_max),
                                randint(d_min, d_max),
                                randint(D_min, D_max)).right_orthogonalise()
                           for _ in range(N)]
        # N random MPSs, left canonicalised and truncated to random D
        self.left_cases = [fMPS().random(
                            randint(L_min, L_max),
                            randint(d_min, d_max),
                            randint(D_min, D_max)).left_canonicalise(
                            randint(D_min, D_max))
                           for _ in range(N)]
        self.left_ortho_cases = [fMPS().random(
                                randint(L_min, L_max),
                                randint(d_min, d_max),
                                randint(D_min, D_max)).left_orthogonalise()
                           for _ in range(N)]
        self.mixed_cases = [fMPS().random(
                            randint(L_min, L_max),
                            randint(d_min, d_max),
                            randint(D_min, D_max)).mixed_canonicalise(
                            randint(ut_min, ut_max),
                            randint(D_min, D_max))
                            for _ in range(N)]


        # finite fixtures 
        fix_loc = 'fixtures/'
        self.tens_0_2 = load(fix_loc+'mat2x2.npy')
        self.tens_0_3 = load(fix_loc+'mat3x3.npy')
        self.tens_0_4 = load(fix_loc+'mat4x4.npy')
        self.tens_0_5 = load(fix_loc+'mat5x5.npy')
        self.tens_0_6 = load(fix_loc+'mat6x6.npy')
        self.tens_0_7 = load(fix_loc+'mat7x7.npy')
        self.tens_0_8 = load(fix_loc+'mat8x8.npy')
        self.tens_0_9 = load(fix_loc+'mat9x9.npy')

        self.mps_0_2 = fMPS().left_from_state(self.tens_0_2)
        self.psi_0_2 = self.mps_0_2.recombine().reshape(-1)

        self.mps_0_3 = fMPS().left_from_state(self.tens_0_3)
        self.psi_0_3 = self.mps_0_3.recombine().reshape(-1)

        self.mps_0_4 = fMPS().left_from_state(self.tens_0_4)
        self.psi_0_4 = self.mps_0_4.recombine().reshape(-1)

        self.mps_0_5 = fMPS().left_from_state(self.tens_0_5)
        self.psi_0_5 = self.mps_0_5.recombine().reshape(-1)

        self.mps_0_6 = fMPS().left_from_state(self.tens_0_6)
        self.psi_0_6 = self.mps_0_6.recombine().reshape(-1)

        self.mps_0_7 = fMPS().left_from_state(self.tens_0_7)
        self.psi_0_7 = self.mps_0_7.recombine().reshape(-1)

        self.mps_0_8 = fMPS().left_from_state(self.tens_0_8)
        self.psi_0_8 = self.mps_0_8.recombine().reshape(-1)

        self.mps_0_9 = fMPS().left_from_state(self.tens_0_9)
        self.psi_0_9 = self.mps_0_9.recombine().reshape(-1)
        self.fixtures = [self.mps_0_2, self.mps_0_3, self.mps_0_4,
                         self.mps_0_5, self.mps_0_6, self.mps_0_7,
                         self.mps_0_8, self.mps_0_9]

        self.all_cases = self.rand_cases+self.right_cases+self.left_cases+self.mixed_cases+self.fixtures
Exemplo n.º 6
0
 def test_serialize_deserialize_real(self):
     mps = self.mps_0_4
     mps_ = fMPS().deserialize(mps.serialize(True), mps.L, mps.d, mps.D, True)
     self.assertTrue(mps==mps_)