def test_catstate_complex_error(self): """Test that passing a complex parameter to gates that previously accepted complex parameters raises an error.""" with pytest.raises(ValueError, match="cannot be complex"): prog = Program(1) with prog.context as q: ops.Catstate(0.2 + 1j) | q eng = Engine("fock", backend_options={"cutoff_dim": 5}) res = eng.run(prog)
def test_cat_state(self, setup_eng, hbar, cutoff, bsize, pure, tol): """Test cat state function matches Fock backends""" eng, prog = setup_eng(1) a = 0.32 + 0.1j p = 0.43 with prog.context as q: ops.Catstate(a, p) | q[0] state = eng.run(prog) ket = utils.cat_state(a, p, fock_dim=cutoff) 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)