示例#1
0
 def test_ground_state(self):
     length, n, h, U, t = 2, 0.8, 3.8, -6, 1
     fu = generate_operators('fu', length)
     fd = generate_operators('fd', length)
     _b = flatten([fu, fd])
     monomials = [[ci for ci in _b]]
     monomials[-1].extend([Dagger(ci) for ci in _b])
     monomials.append([cj*ci for ci in _b for cj in _b])
     monomials.append([Dagger(cj)*ci for ci in _b for cj in _b])
     monomials[-1].extend([cj*Dagger(ci)
                           for ci in _b for cj in _b])
     monomials.append([Dagger(cj)*Dagger(ci)
                       for ci in _b for cj in _b])
     hamiltonian = 0
     for j in range(length):
         hamiltonian += U * (Dagger(fu[j])*Dagger(fd[j]) * fd[j]*fu[j])
         hamiltonian += -h/2*(Dagger(fu[j])*fu[j] - Dagger(fd[j])*fd[j])
         for k in get_neighbors(j, len(fu), width=1):
             hamiltonian += -t*Dagger(fu[j])*fu[k]-t*Dagger(fu[k])*fu[j]
             hamiltonian += -t*Dagger(fd[j])*fd[k]-t*Dagger(fd[k])*fd[j]
     momentequalities = [n-sum(Dagger(br)*br for br in _b)]
     sdpRelaxation = SdpRelaxation(_b, verbose=0)
     sdpRelaxation.get_relaxation(-1,
                                  objective=hamiltonian,
                                  momentequalities=momentequalities,
                                  substitutions=fermionic_constraints(_b),
                                  extramonomials=monomials)
     sdpRelaxation.solve()
     s = 0.5*(sum((Dagger(u)*u) for u in fu) -
              sum((Dagger(d)*d) for d in fd))
     magnetization = sdpRelaxation[s]
     self.assertTrue(abs(magnetization-0.021325317328560453) < 10e-5)
示例#2
0
    def test_apply_substitutions(self):

        def apply_correct_substitutions(monomial, substitutions):
            if isinstance(monomial, int) or isinstance(monomial, float):
                return monomial
            original_monomial = monomial
            changed = True
            while changed:
                for lhs, rhs in substitutions.items():
                    monomial = monomial.subs(lhs, rhs)
                if original_monomial == monomial:
                    changed = False
                original_monomial = monomial
            return monomial

        length, h, U, t = 2, 3.8, -6, 1
        fu = generate_operators('fu', length)
        fd = generate_operators('fd', length)
        _b = flatten([fu, fd])
        hamiltonian = 0
        for j in range(length):
            hamiltonian += U * (Dagger(fu[j])*Dagger(fd[j]) * fd[j]*fu[j])
            hamiltonian += -h/2*(Dagger(fu[j])*fu[j] - Dagger(fd[j])*fd[j])
            for k in get_neighbors(j, len(fu), width=1):
                hamiltonian += -t*Dagger(fu[j])*fu[k]-t*Dagger(fu[k])*fu[j]
                hamiltonian += -t*Dagger(fd[j])*fd[k]-t*Dagger(fd[k])*fd[j]
        substitutions = fermionic_constraints(_b)
        monomials = expand(hamiltonian).as_coeff_mul()[1][0].as_coeff_add()[1]
        substituted_hamiltonian = sum([apply_substitutions(monomial,
                                                           substitutions)
                                       for monomial in monomials])
        correct_hamiltonian = sum([apply_correct_substitutions(monomial,
                                                               substitutions)
                                   for monomial in monomials])
        self.assertTrue(substituted_hamiltonian == expand(correct_hamiltonian))
示例#3
0
 def test_ground_state(self):
     length, n, h, U, t = 2, 0.8, 3.8, -6, 1
     fu = generate_operators('fu', length)
     fd = generate_operators('fd', length)
     _b = flatten([fu, fd])
     monomials = [[ci for ci in _b]]
     monomials[-1].extend([Dagger(ci) for ci in _b])
     monomials.append([cj * ci for ci in _b for cj in _b])
     monomials.append([Dagger(cj) * ci for ci in _b for cj in _b])
     monomials[-1].extend([cj * Dagger(ci) for ci in _b for cj in _b])
     monomials.append([Dagger(cj) * Dagger(ci) for ci in _b for cj in _b])
     hamiltonian = 0
     for j in range(length):
         hamiltonian += U * (Dagger(fu[j]) * Dagger(fd[j]) * fd[j] * fu[j])
         hamiltonian += -h / 2 * (Dagger(fu[j]) * fu[j] -
                                  Dagger(fd[j]) * fd[j])
         for k in get_neighbors(j, len(fu), width=1):
             hamiltonian += -t * Dagger(fu[j]) * fu[k] - t * Dagger(
                 fu[k]) * fu[j]
             hamiltonian += -t * Dagger(fd[j]) * fd[k] - t * Dagger(
                 fd[k]) * fd[j]
     momentequalities = [n - sum(Dagger(br) * br for br in _b)]
     sdpRelaxation = SdpRelaxation(_b, verbose=0)
     sdpRelaxation.get_relaxation(-1,
                                  objective=hamiltonian,
                                  momentequalities=momentequalities,
                                  substitutions=fermionic_constraints(_b),
                                  extramonomials=monomials)
     sdpRelaxation.solve()
     s = 0.5 * (sum((Dagger(u) * u) for u in fu) - sum(
         (Dagger(d) * d) for d in fd))
     magnetization = sdpRelaxation[s]
     self.assertTrue(abs(magnetization - 0.021325317328560453) < 10e-5)
示例#4
0
    def test_apply_substitutions(self):

        def apply_correct_substitutions(monomial, substitutions):
            if isinstance(monomial, int) or isinstance(monomial, float):
                return monomial
            original_monomial = monomial
            changed = True
            while changed:
                for lhs, rhs in substitutions.items():
                    monomial = monomial.subs(lhs, rhs)
                if original_monomial == monomial:
                    changed = False
                original_monomial = monomial
            return monomial

        length, h, U, t = 2, 3.8, -6, 1
        fu = generate_operators('fu', length)
        fd = generate_operators('fd', length)
        _b = flatten([fu, fd])
        hamiltonian = 0
        for j in range(length):
            hamiltonian += U * (Dagger(fu[j])*Dagger(fd[j]) * fd[j]*fu[j])
            hamiltonian += -h/2*(Dagger(fu[j])*fu[j] - Dagger(fd[j])*fd[j])
            for k in get_neighbors(j, len(fu), width=1):
                hamiltonian += -t*Dagger(fu[j])*fu[k]-t*Dagger(fu[k])*fu[j]
                hamiltonian += -t*Dagger(fd[j])*fd[k]-t*Dagger(fd[k])*fd[j]
        substitutions = fermionic_constraints(_b)
        monomials = expand(hamiltonian).as_coeff_mul()[1][0].as_coeff_add()[1]
        substituted_hamiltonian = sum([apply_substitutions(monomial,
                                                           substitutions)
                                       for monomial in monomials])
        correct_hamiltonian = sum([apply_correct_substitutions(monomial,
                                                               substitutions)
                                   for monomial in monomials])
        self.assertTrue(substituted_hamiltonian == expand(correct_hamiltonian))
示例#5
0
文件: sdpqpy.py 项目: cgogolin/sdpqpy
    def createHamiltonian(self):
        if self._lattice_width != 1:
            raise NotImplementedError("Higher dimension not implemented!")

        if self._periodic or self._periodic == 1:
            bext = self._b + [bi for bi in self._b]
        elif self._periodic == -1:
            bext = self._b + [-bi for bi in self._b]
        else:
            bext = self._b

        hamiltonian = 0
        for r, br in enumerate(self._b[:self._lattice_length]):
            if self.mu != 0:
                hamiltonian += -self.mu * (Dagger(br) * br - 1 / 2)
            for s in get_neighbors(r, len(bext), self._lattice_width):
                hamiltonian += -self.t * \
                    (Dagger(br) * bext[s] + Dagger(bext[s]) * br)
            for d in range(1, self._lattice_length):
                for s in get_next_neighbors(r, len(bext), self._lattice_width):
                    hamiltonian += self.Delta * \
                        math.pow(d, -self.alpha) * (br * bext[s] +
                                                    Dagger(bext[s]) * Dagger(br))
        return hamiltonian
示例#6
0
文件: sdpqpy.py 项目: cgogolin/sdpqpy
    def createHamiltonian(self):
        if self._periodic == -1:
            raise NotImplementedError("Anti periodic not implemented!")
            # fuext = self._fu + [-fi for fi in self._fu]
            # fdext = self._fd + [-fi for fi in self._fd]
        else:
            fuext = self._fu
            fdext = self._fd

        hamiltonian = 0
        V = self.getSize()
        if self.t != 0:
            for j in range(V):
                for k in get_neighbors(j, self.getLength(),
                                       width=self.getWidth(),
                                       periodic=self._periodic):
                    hamiltonian += -self.t * Dagger(fuext[j]) * fuext[k]\
                                   - self.t * Dagger(fuext[k]) * fuext[j]
                    hamiltonian += -self.t * Dagger(fdext[j]) * fdext[k]\
                                   - self.t * Dagger(fdext[k]) * fdext[j]
        if self.U != 0:
            for j in range(V):
                hamiltonian += self.U * (Dagger(fuext[j]) * Dagger(fdext[j]) *
                                         fdext[j] * fuext[j])

        if self.h != 0:
            for j in range(V):
                hamiltonian += -self.h / 2 * (Dagger(fuext[j]) * fuext[j] -
                                              Dagger(fdext[j]) * fdext[j])

        if self.mu != 0:
            for j in range(V):
                hamiltonian += -self.mu * (Dagger(fuext[j]) * fuext[j] +
                                           Dagger(fdext[j]) * fdext[j])

        return hamiltonian
示例#7
0
文件: sdpqpy.py 项目: cgogolin/sdpqpy
    def createHamiltonian(self):
        if self._periodic == -1:
            raise NotImplementedError("Antiperiodic boundary conditions not "
                                      "implemented!")

        hamiltonian = 0
        for r, br in enumerate(self._b):
            if self.U != 0:
                hamiltonian += self.U / 2.0 * \
                    (Dagger(br) * br * (Dagger(br) * br - 1))
            if self.mu != 0:
                hamiltonian += -self.mu * Dagger(br) * br
            if self.t != 0:
                for s in get_neighbors(r, self._lattice_length,
                                       self._lattice_width, self._periodic):
                    hamiltonian += -self.t * (Dagger(br) * self._b[s] +
                                              Dagger(self._b[s]) * br)
            if self.t2 != 0:
                for s in get_next_neighbors(r, self._lattice_length,
                                            self._lattice_width, 2,
                                            self._periodic):
                    hamiltonian += -self.t2 * (Dagger(br) * self._b[s] +
                                               Dagger(self._b[s]) * br)
        return hamiltonian