def test_resulthandle() -> None: c = Circuit(4, 4).H(0).CX(0, 2) b = ProjectQBackend() handles = b.process_circuits([c, c.copy()]) ids = [han[0] for han in handles] assert all(isinstance(idval, str) for idval in ids) assert ids[0] != ids[1] assert len(b.get_result(handles[0]).get_state()) == (1 << 4) assert b.circuit_status(handles[1]).status == StatusEnum.COMPLETED with pytest.raises(TypeError) as errorinfo: _ = b.get_result(ResultHandle("43", 5)) assert "ResultHandle('43', 5) does not match expected identifier types" in str( errorinfo.value) wronghandle = ResultHandle("asdf") with pytest.raises(CircuitNotRunError) as errorinfocirc: _ = b.get_result(wronghandle) assert "Circuit corresponding to {0!r} ".format( wronghandle) + "has not been run by this backend instance." in str( errorinfocirc.value)
def test_shots_bits_edgecases(n_shots, n_bits) -> None: projectq_backend = ProjectQBackend() c = Circuit(n_bits, n_bits) # TODO TKET-813 add more shot based backends and move to integration tests h = projectq_backend.process_circuit(c, n_shots) res = projectq_backend.get_result(h) correct_shots = np.zeros((n_shots, n_bits), dtype=int) correct_shape = (n_shots, n_bits) correct_counts = Counter({(0, ) * n_bits: n_shots}) # BackendResult assert np.array_equal(res.get_shots(), correct_shots) assert res.get_shots().shape == correct_shape assert res.get_counts() == correct_counts # Direct assert np.array_equal(projectq_backend.get_shots(c, n_shots), correct_shots) assert projectq_backend.get_shots(c, n_shots).shape == correct_shape assert projectq_backend.get_counts(c, n_shots) == correct_counts