Esempio n. 1
0
def _tomography_test_data(qp, name, qr, cr, tomoset, shots):
    tomo.create_tomography_circuits(qp, name, qr, cr, tomoset)
    result = qp.execute(tomo.tomography_circuit_names(tomoset, name),
                        shots=shots,
                        seed=42)
    data = tomo.tomography_data(result, name, tomoset)
    return tomo.fit_tomography_data(data)
Esempio n. 2
0
 def _tomo_postselect(self, results, name, tomoset, select):
     # this postselect is based on tomo.tomography_data
     labels = tomo.tomography_circuit_names(tomoset, name)
     circuits = tomoset['circuits']
     data = []
     prep = None
     for j, _ in enumerate(labels):
         select_bitpos = None
         for cbit_label in results.results[j].header.clbit_labels:
             if cbit_label[0] == select.name:
                 select_bitpos = cbit_label[1]
         all_counts = results.get_counts(labels[j])
         filt_counts = []
         filt_keys = []
         for k, v in all_counts.items():
             if int(k[-1-select_bitpos]) == 1:
                 filt_keys.append(k[:select_bitpos-2])
                 filt_counts.append(v)
         filt_labels = dict(zip(filt_keys, filt_counts))
         if filt_labels == {}:
             filt_labels = {'0': 0}
         counts = tomo.marginal_counts(filt_labels, tomoset['qubits'])
         shots = sum(counts.values())
         meas = circuits[j]['meas']
         prep = circuits[j].get('prep', None)
         meas_qubits = sorted(meas.keys())
         if prep:
             prep_qubits = sorted(prep.keys())
         circuit = {}
         for c in counts.keys():
             circuit[c] = {}
             circuit[c]['meas'] = [(meas[meas_qubits[k]], int(c[-1 - k]))
                                   for k in range(len(meas_qubits))]
             if prep:
                 circuit[c]['prep'] = [prep[prep_qubits[k]] for k in
                                       range(len(prep_qubits))]
         data.append({'counts': counts, 'shots': shots, 'circuit': circuit})
     ret = {'data': data, 'meas_basis': tomoset['meas_basis']}
     if prep:
         ret['prep_basis'] = tomoset['prep_basis']
     return ret
def _tomography_test_data(qp, name, qr, cr, tomoset, shots):
    tomo.create_tomography_circuits(qp, name, qr, cr, tomoset)
    result = qp.execute(tomo.tomography_circuit_names(tomoset, name),
                        shots=shots, seed=42, timeout=180)
    data = tomo.tomography_data(result, name, tomoset)
    return tomo.fit_tomography_data(data)