コード例 #1
0
def test_machine_debug() -> None:
    b = IonQBackend(api_key="invalid", device_name="simulator", label="test 5")
    b._MACHINE_DEBUG = True
    c = Circuit(2)
    c.H(0)
    c.CX(0, 1)
    c.measure_all()
    n_shots = 100
    counts = b.get_counts(c, n_shots=n_shots, timeout=30)
    assert counts[(0, 0)] == n_shots
コード例 #2
0
def test_shots_bits_edgecases(n_shots, n_bits) -> None:
    ionq_backend = IonQBackend(api_key="invalid",
                               device_name="simulator",
                               label="test 5")
    ionq_backend._MACHINE_DEBUG = True
    c = Circuit(n_bits, n_bits)
    # TODO TKET-813 add more shot based backends and move to integration tests
    h = ionq_backend.process_circuit(c, n_shots)
    res = ionq_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(ionq_backend.get_shots(c, n_shots), correct_shots)
    assert ionq_backend.get_shots(c, n_shots).shape == correct_shape
    assert ionq_backend.get_counts(c, n_shots) == correct_counts