예제 #1
0
def test_aer_result_handle() -> None:
    c = Circuit(2, 2).H(0).CX(0, 1).measure_all()

    b = AerBackend()

    handles = b.process_circuits([c, c.copy()], n_shots=2)

    ids, indices = zip(*(han for han in handles))

    assert all(isinstance(idval, str) for idval in ids)
    assert indices == (0, 1)

    assert len(b.get_result(handles[0]).get_shots()) == 2

    with pytest.raises(TypeError) as errorinfo:
        _ = b.get_result(ResultHandle("43"))
    assert "ResultHandle('43',) does not match expected identifier types" in str(
        errorinfo.value)

    wronghandle = ResultHandle("asdf", 3)

    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)
예제 #2
0
def test_cache() -> None:
    b = AerBackend()
    c = circuit_gen()
    b.compile_circuit(c)
    h = b.process_circuits([c], 2)[0]
    b.get_result(h).get_shots()
    assert h in b._cache
    b.pop_result(h)
    assert h not in b._cache
    assert not b._cache

    b.get_counts(c, n_shots=2)
    b.get_counts(c.copy(), n_shots=2)
    b.empty_cache()
    assert not b._cache
예제 #3
0
from pytket.extensions.qiskit import AerBackend
from qiskit.providers.aer.noise import NoiseModel

n_shots = 8192
santiago_node_subsets = pytket_santiago_device.nodes
pytket_noisy_sim_backend = AerBackend(
    NoiseModel.from_backend(ibmq_santiago_backend))
santiago_spam = SpamCorrecter([santiago_node_subsets],
                              pytket_noisy_sim_backend)

# The SpamCorrecter uses these subsets of qubits to produce calibration circuits.

calibration_circuits = santiago_spam.calibration_circuits()
print("Number of calibration circuits: ", len(calibration_circuits))

sim_handles = pytket_noisy_sim_backend.process_circuits(
    calibration_circuits, n_shots)

# Count results from the simulator are then used to calculate the matrices used for SPAM correction for ```ibmq_santiago```.

sim_count_results = (pytket_noisy_sim_backend.get_result(handle).get_counts()
                     for handle in sim_handles)
santiago_spam.calculate_matrices(sim_count_results)

from pytket import Circuit

ghz_circuit = (Circuit(len(pytket_santiago_device.nodes)).H(0).CX(0, 1).CX(
    1, 2).measure_all())
pytket_noisy_sim_backend.compile_circuit(ghz_circuit)
ghz_noisy_counts = pytket_noisy_sim_backend.get_counts(ghz_circuit, n_shots)

# We also run a noiseless simulation so we can compare performance.