Ejemplo n.º 1
0
    def test_dm_two_mode(self, setup_eng, hbar, cutoff, tol):
        """Tests multimode dm preparation"""
        eng, prog = setup_eng(2)

        ket0 = np.random.uniform(
            -1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket0 = ket0 / np.linalg.norm(ket0)
        ket1 = np.random.uniform(
            -1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket1 = ket1 / np.linalg.norm(ket1)

        ket = np.outer(ket0, ket1)
        rho = np.einsum("ij,kl->ikjl", ket, ket.conj())
        with prog.context as q:
            ops.DensityMatrix(rho) | q
        state = eng.run(prog).state
        assert np.allclose(state.dm(), rho, atol=tol, rtol=0)

        eng.reset()

        prog = sf.Program(2)
        state1 = BaseFockState(rho, 2, False, cutoff)
        with prog.context as q:
            ops.DensityMatrix(state1) | q
        state2 = eng.run(prog).state
        assert np.allclose(state1.dm(), state2.dm(), atol=tol, rtol=0)
Ejemplo n.º 2
0
    def test_ket_one_mode(self, setup_eng, hbar, cutoff, tol):
        """Tests single mode ket preparation"""
        eng, prog = setup_eng(2)
        ket0 = np.random.uniform(-1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket0 = ket0 / np.linalg.norm(ket0)
        with prog.context as q:
            ops.Ket(ket0) | q[0]
        state = eng.run(prog, modes=[0])
        assert np.allclose(state.dm(), np.outer(ket0, ket0.conj()), atol=tol, rtol=0)

        eng.reset()

        prog = sf.Program(2)
        state1 = BaseFockState(ket0, 1, True, cutoff, hbar)
        with prog.context as q:
            ops.Ket(state1) | q[0]
        state2 = eng.run(prog, modes=[0])
        assert np.allclose(state1.dm(), state2.dm(), atol=tol, rtol=0)
Ejemplo n.º 3
0
    def test_dm_one_mode(self, setup_eng, hbar, cutoff, tol):
        """Tests single mode DM preparation"""
        eng, prog = setup_eng(2)

        ket = np.random.uniform(-1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket = ket / np.linalg.norm(ket)
        rho = np.outer(ket, ket.conj())
        with prog.context as q:
            ops.DensityMatrix(rho) | q[0]
        state = eng.run(prog, modes=[0])
        assert np.allclose(state.dm(), rho, atol=tol, rtol=0)

        eng.reset()

        prog = sf.Program(2)
        state1 = BaseFockState(rho, 1, False, cutoff, hbar)
        with prog.context as q:
            ops.DensityMatrix(state1) | q[0]
        state2 = eng.run(prog, modes=[0])
        assert np.allclose(state1.dm(), state2.dm(), atol=tol, rtol=0)
Ejemplo n.º 4
0
    def test_ket_two_mode(self, setup_eng, hbar, cutoff, tol):
        """Tests multimode ket preparation"""
        eng, prog = setup_eng(2)
        ket0 = np.random.uniform(-1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket0 = ket0 / np.linalg.norm(ket0)
        ket1 = np.random.uniform(-1, 1, cutoff) + 1j * np.random.uniform(-1, 1, cutoff)
        ket1 = ket1 / np.linalg.norm(ket1)

        ket = np.outer(ket0, ket1)
        with prog.context as q:
            ops.Ket(ket) | q
        state = eng.run(prog)
        assert np.allclose(
            state.dm(), np.einsum("ij,kl->ikjl", ket, ket.conj()), atol=tol, rtol=0
        )

        eng.reset()

        prog = sf.Program(2)
        state1 = BaseFockState(ket, 2, True, cutoff, hbar)
        with prog.context as q:
            ops.Ket(state1) | q
        state2 = eng.run(prog)
        assert np.allclose(state1.dm(), state2.dm(), atol=tol, rtol=0)