Beispiel #1
0
    def test_1x2(self):
        """Test a 1x2 lattice Bose-Hubbard model"""
        self.logTestName()
        self.eng.reset()
        q = self.eng.register
        H = bose_hubbard(1, 2, self.J, self.U)

        with self.eng:
            Fock(2) | q[0]
            BoseHubbardPropagation(H, self.t, self.k) | q

        state = self.eng.run('fock', cutoff_dim=7)

        Hm = -self.J*np.sqrt(2)*np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) \
            + self.U*np.diag([1, 0, 1])
        init_state = np.array([1, 0, 0])
        exp = np.abs(np.dot(expm(-1j * self.t * Hm), init_state))**2

        self.assertTrue(
            np.allclose(state.fock_prob([2, 0]), exp[0], rtol=self.tol))
        self.assertTrue(
            np.allclose(state.fock_prob([1, 1]), exp[1], rtol=self.tol))
        self.assertTrue(
            np.allclose(state.fock_prob([0, 2]), exp[2], rtol=self.tol))
Beispiel #2
0
    def test_global(self):
        """Test a 1x2 lattice Bose-Hubbard model in global mode"""
        self.logTestName()
        self.eng.reset()
        q = self.eng.register

        with self.eng:
            Sgate(0.1) | q[2]
            Fock(2) | q[0]
            BoseHubbardPropagation(self.H, self.t, self.k, mode='global') | q

        state = self.eng.run('fock', cutoff_dim=7, modes=[0, 1])

        Hm = -self.J*np.sqrt(2)*np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) \
            + self.U*np.diag([1, 0, 1])
        init_state = np.array([1, 0, 0])
        exp = np.abs(np.dot(expm(-1j * self.t * Hm), init_state))**2

        self.assertTrue(
            np.allclose(state.fock_prob([2, 0]), exp[0], rtol=self.tol))
        self.assertTrue(
            np.allclose(state.fock_prob([1, 1]), exp[1], rtol=self.tol))
        self.assertTrue(
            np.allclose(state.fock_prob([0, 2]), exp[2], rtol=self.tol))
Beispiel #3
0
 def test_non_hermitian(self):
     """Tests exception if non-Hermitian H"""
     with self.assertRaises(ValueError):
         H = QuadOperator('q0', 1 + 2j)
         BoseHubbardPropagation(H, self.t, self.k, hbar=self.hbar)
Beispiel #4
0
 def test_outside_context_no_hbar(self):
     """Tests exception if outside the engine with no hbar"""
     with self.assertRaises(ValueError):
         BoseHubbardPropagation(self.Hquad, self.t, self.k)
Beispiel #5
0
from openfermion.hamiltonians import bose_hubbard

import strawberryfields as sf
from strawberryfields.ops import *
from sfopenboson.ops import BoseHubbardPropagation

H = bose_hubbard(1, 2, 1, 1.5)

eng, q = sf.Engine(2)
with eng:
    Fock(2) | q[1]
    BoseHubbardPropagation(H, 1.086, 20) | q

state = eng.run('fock', cutoff_dim=3)

print("Prob(2,0) = ", state.fock_prob([2,0]))
print("Prob(1,1) = ", state.fock_prob([1,1]))
print("Prob(0,2) = ", state.fock_prob([0,2]))