Beispiel #1
0
def test_shots_bits_edgecases(qvm: None, quilc: None) -> None:
    print(type(qvm))
    print(type(quilc))
    forest_backend = ForestBackend("9q-square")

    for n_bits in range(1, 9):  # Getting runtime error if n_qubit > 9.
        for n_shots in range(1, 11):
            c = Circuit(n_bits, n_bits)

            # TODO TKET-813 add more shot based backends and move to integration tests
            forest_backend.compile_circuit(c)
            h = forest_backend.process_circuit(c, n_shots)
            res = forest_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(forest_backend.get_shots(c, n_shots),
                                  correct_shots)
            assert forest_backend.get_shots(c, n_shots).shape == correct_shape
            assert forest_backend.get_counts(c, n_shots) == correct_counts
Beispiel #2
0
def test_ilo(qvm: None, quilc: None) -> None:
    b = ForestBackend("9q-square")
    bs = ForestStateBackend()
    c = Circuit(2)
    c.CZ(0, 1)
    c.Rx(1.0, 1)
    assert np.allclose(bs.get_state(c), np.asarray([0, -1j, 0, 0]))
    assert np.allclose(bs.get_state(c, basis=BasisOrder.dlo),
                       np.asarray([0, 0, -1j, 0]))
    c.rename_units({Qubit(0): Node(0), Qubit(1): Node(1)})
    c.measure_all()
    assert (b.get_shots(c, 2) == np.asarray([[0, 1], [0, 1]])).all()
    assert (b.get_shots(c, 2,
                        basis=BasisOrder.dlo) == np.asarray([[1, 0],
                                                             [1, 0]])).all()
    assert b.get_counts(c, 2) == {(0, 1): 2}
    assert b.get_counts(c, 2, basis=BasisOrder.dlo) == {(1, 0): 2}
Beispiel #3
0
def test_measures(qvm: None, quilc: None) -> None:
    n_qbs = 9
    c = Circuit(n_qbs, n_qbs)
    x_qbs = [2, 5, 7, 8]
    for i in x_qbs:
        c.X(i)
    c.measure_all()
    b = ForestBackend("9q-square")
    b.compile_circuit(c)
    shots = b.get_shots(c, 10)
    print(shots)
    all_ones = True
    all_zeros = True
    for i in x_qbs:
        all_ones = all_ones and cast(bool, np.all(shots[:, i]))
    for i in range(n_qbs):
        if i not in x_qbs:
            all_zeros = all_zeros and (not np.any(shots[:, i]))
    assert all_ones
    assert all_zeros
Beispiel #4
0
def test_sim(qvm: None, quilc: None) -> None:
    c = circuit_gen(True)
    b = ForestBackend("9q-square")
    b.compile_circuit(c)
    shots = b.get_shots(c, 1024)
    print(shots)