def test_vacuum(self, setup_eng, hbar, cutoff, bsize, pure, tol):
        """Test vacuum function matches Fock backends"""
        eng, prog = setup_eng(1)

        with prog.context as q:
            ops.Vac | q[0]

        state = eng.run(prog).state

        ket = utils.vacuum_state(basis="fock", fock_dim=cutoff, hbar=hbar)

        if not pure:
            expected = state.dm()
            ket = np.tile(np.outer(ket, ket.conj()), (bsize, 1, 1))
        else:
            expected = state.ket()
            ket = np.tile(ket, (bsize, 1))

        assert np.allclose(expected, ket, atol=tol, rtol=0)
예제 #2
0
 def test_vacuum_state_fock(self, cutoff, hbar):
     """test vacuum state returns correct state vector"""
     state = utils.vacuum_state(basis="fock", hbar=hbar, fock_dim=cutoff)
     assert np.all(state == np.eye(1, cutoff, 0))
예제 #3
0
 def test_vacuum_state_gaussian(self, hbar):
     """test vacuum state returns correct means and covariance"""
     means, cov = utils.vacuum_state(basis="gaussian", hbar=hbar)
     assert np.all(means == np.zeros(2))
     assert np.all(cov == np.identity(2) * hbar / 2)