Esempio n. 1
0
def process_tomography(Program, numberSamples, qubits):
    process_tomography_qpu, _, _ = do_process_tomography(
        Program, numberSamples, qpu, qubits)
    process_tomography_qvm, _, _ = do_process_tomography(
        Program, numberSamplesQVM, qvm, qubits)

    print('The process matrix:\n', process_tomography_qpu.to_chi())
    with open(
            'processmatrix_qpu_' + gate_str + '_' + str(qubits[0]) + '_' +
            str(numberSamples) + '.txt', 'w') as text_file:
        print("QPU Estimated process matrix: {}".format(
            process_tomography_qpu.to_chi()),
              file=text_file)

    process_fidelity = process_tomography_qpu.avg_gate_fidelity(
        process_tomography_qvm.r_est)
    print('The estimate process fidelity is:', process_fidelity)

    qpu_plot = process_tomography_qpu.plot()
    qpu_plot.text(0.4,
                  .95,
                  r'$F_{{\rm avg}}={:1.1f}\%$'.format(process_fidelity * 100),
                  size=25)

    plt.savefig('process_tomography_qpu_' + gate_str + '_' + str(qubits[0]) +
                '_' + str(numberSamples) + '.png')
    process_tomography_qvm.plot()
    plt.savefig('process_tomography_qvm_' + gate_str + '_' + str(qubits[0]) +
                '_' + str(numberSamplesQVM) + '.png')
Esempio n. 2
0
def test_do_process_tomography():
    nsamples = 3000
    qubits = list(range(MAX_QUBITS_PROCESS_TOMO + 1))
    # Test with too many qubits.
    with pytest.raises(ValueError):
        _ = do_process_tomography(CNOT_PROGRAM, nsamples,
                                  cxn, qubits)
    process_tomo, assignment_probs, histograms = do_process_tomography(CNOT_PROGRAM, nsamples, cxn)
    cnot_ideal = qt.cnot()
    assert abs(1 - process_tomo.avg_gate_fidelity(cnot_ideal)) < EPS
    for histogram_collection in histograms:
        for histogram in histogram_collection:
            assert np.sum(histogram) == nsamples
    num_qubits = len(CNOT_PROGRAM.get_qubits())
    assert np.isclose(assignment_probs, np.eye(2 ** num_qubits), atol=EPS).all()
Esempio n. 3
0
def qvm_chi_matrix(Program, numberSamples, qubits):
    process_tomography_qvm, _, _ = do_process_tomography(
        Program, numberSamplesQVM, qvm, qubits)

    print('The process matrix:\n', process_tomography_qvm.to_chi())
    with open(
            'processmatrix_qvm_' + gate_str + '_' + str(qubits[0]) + '_' +
            str(numberSamples) + '.txt', 'w') as text_file:
        print("QVM Estimated process matrix: {}".format(
            process_tomography_qvm.to_chi()),
              file=text_file)