Beispiel #1
0
 def ph_onsite(cls, mol_list: MolList, opera: str, mol_idx:int, ph_idx=0):
     assert opera in ["b", r"b^\dagger", r"b^\dagger b"]
     mpo = cls()
     mpo.mol_list = mol_list
     for imol, mol in enumerate(mol_list):
         if mol_list.scheme < 4:
             mpo.append(xp.eye(2).reshape(1, 2, 2, 1))
         elif mol_list.scheme == 4:
             if len(mpo) == mol_list.e_idx():
                 n = mol_list.mol_num
                 mpo.append(xp.eye(n).reshape(1, n, n, 1))
         else:
             assert False
         iph = 0
         for ph in mol.dmrg_phs:
             for iqph in range(ph.nqboson):
                 ph_pbond = ph.pbond[iqph]
                 if imol == mol_idx and iph == ph_idx:
                     mt = ph_op_matrix(opera, ph_pbond)
                 else:
                     mt = ph_op_matrix("Iden", ph_pbond)
                 mpo.append(mt.reshape(1, ph_pbond, ph_pbond, 1))
                 iph += 1
     mpo.build_empty_qn()
     return mpo
Beispiel #2
0
 def identity(cls, mol_list: MolList):
     mpo = cls()
     mpo.mol_list = mol_list
     for p in mol_list.pbond_list:
         mpo.append(xp.eye(p).reshape(1, p, p, 1))
     mpo.build_empty_qn()
     return mpo
Beispiel #3
0
 def check_rortho(self):
     """
     check R-orthogonal
     """
     tensm = self.array.reshape([self.shape[0], np.prod(self.shape[1:])])
     s = xp.dot(tensm, tensm.T.conj())
     return allclose(s, xp.eye(s.shape[0]), atol=1e-3)
Beispiel #4
0
 def check_lortho(self):
     """
     check L-orthogonal
     """
     tensm = self.array.reshape([np.prod(self.shape[:-1]), self.shape[-1]])
     s = xp.dot(tensm.T.conj(), tensm)
     return allclose(s, xp.eye(s.shape[0]), atol=1e-3)
Beispiel #5
0
 def check_lortho(self, rtol=1e-5, atol=1e-8):
     """
     check L-orthogonal
     """
     tensm = asxp(
         self.array.reshape([np.prod(self.shape[:-1]), self.shape[-1]]))
     s = tensm.T.conj() @ tensm
     return xp.allclose(s, xp.eye(s.shape[0]), rtol=rtol, atol=atol)
Beispiel #6
0
 def check_rortho(self, rtol=1e-5, atol=1e-8):
     """
     check R-orthogonal
     """
     tensm = asxp(
         self.array.reshape([self.shape[0],
                             np.prod(self.shape[1:])]))
     s = tensm @ tensm.T.conj()
     return xp.allclose(s, xp.eye(s.shape[0]), rtol=rtol, atol=atol)
Beispiel #7
0
    def dot(self, other: "MatrixProduct") -> complex:
        """
        dot product of two mps / mpo
        """

        assert len(self) == len(other)
        e0 = xp.eye(1, 1)
        # for debugging. It has little computational cost anyway
        debug_t = []
        for mt1, mt2 in zip(self, other):
            # sum_x e0[:,x].m[x,:,:]
            debug_t.append(e0)
            e0 = tensordot(e0, mt2.array, 1)
            # sum_ij e0[i,p,:] self[i,p,:]
            # note, need to flip a (:) index onto top,
            # therefore take transpose
            if mt1.ndim == 3:
                e0 = tensordot(e0, mt1.array, ([0, 1], [0, 1])).T
            elif mt1.ndim == 4:
                e0 = tensordot(e0, mt1.array, ([0, 1, 2], [0, 1, 2])).T
            else:
                assert False

        return complex(e0[0, 0])
Beispiel #8
0
def eye(N, M=None, dtype=None):
    if dtype is None:
        dtype = backend.real_dtype
    return Matrix(xp.eye(N, M), dtype=dtype)