def test_machine_debug() -> None:
    backend = IBMQBackend("ibmq_santiago",
                          hub="ibm-q",
                          group="open",
                          project="main")
    backend._MACHINE_DEBUG = True
    c = Circuit(2, 2).H(0).CX(0, 1).measure_all()
    with pytest.raises(CircuitNotValidError) as errorinfo:
        handles = backend.process_circuits([c, c.copy()], n_shots=2)
    assert "in submitted does not satisfy GateSetPredicate" in str(
        errorinfo.value)
    backend.compile_circuit(c)
    handles = backend.process_circuits([c, c.copy()], n_shots=4)
    from pytket.extensions.qiskit.backends.ibm import _DEBUG_HANDLE_PREFIX

    assert all(
        cast(str, hand[0]).startswith(_DEBUG_HANDLE_PREFIX)
        for hand in handles)

    correct_shots = np.zeros((4, 2))
    correct_counts = {(0, 0): 4}

    shots = backend.get_shots(c, n_shots=4)
    assert np.all(shots == correct_shots)
    counts = backend.get_counts(c, n_shots=4)
    assert counts == correct_counts

    newshots = backend.get_shots(c, 4)
    assert np.all(newshots == correct_shots)
    newcounts = backend.get_counts(c, 4)
    assert newcounts == correct_counts
示例#2
0
)
print(
    "Jensen-Shannon Divergence between noiseless simulation probability distribution and invert-corrected noisy simulation probability distribution: ",
    JSD(ghz_noiseless_probabilities, ghz_invert_probabilities),
)

# Lets change from our simulator backend to the Santiago IBMQ device to see how SPAM correction performs on real results.

from pytket.extensions.qiskit import IBMQBackend

ibm_backend = IBMQBackend("ibmq_santiago")

santiago_spam_real = SpamCorrecter([ibm_backend.device.nodes], ibm_backend)
ibm_backend.compile_circuit(ghz_circuit)
all_circuits = santiago_spam_real.calibration_circuits() + [ghz_circuit]
ibm_handles = ibm_backend.process_circuits(all_circuits, n_shots)

ibm_calibration_results = (ibm_backend.get_result(handle).get_counts()
                           for handle in ibm_handles[:-1])
santiago_spam_real.calculate_matrices(ibm_calibration_results)

ghz_santiago_counts = ibm_backend.get_result(ibm_handles[-1]).get_counts()
ghz_santiago_probabilities = probs_from_counts(ghz_santiago_counts)

# Finally we compare performance for our machine results:

ghz_spam_corrected_santiago_counts = santiago_spam_real.correct_counts(
    ghz_santiago_counts, ghz_circuit.qubit_readout)
ghz_invert_corrected_counts = santiago_spam_real.correct_counts(
    ghz_santiago_counts, ghz_circuit.qubit_readout, method="invert")