def prepare_plots(self): self.plot_dicts['main'] = { 'plotfn': self.plot_line, 'xvals': self.proc_data_dict['xvals_A'], 'xlabel': self.proc_data_dict['xlabel'][0], 'xunit': self.proc_data_dict['xunit'][0][0], 'yvals': self.proc_data_dict['yvals_A'], 'ylabel': self.proc_data_dict['ylabel'], 'yunit': self.proc_data_dict['yunit'], 'setlabel': 'A', 'title': (self.proc_data_dict['timestamps'][0] + ' \n' + self.proc_data_dict['measurementstring'][0]), 'do_legend': True, 'yrange': (0,1), 'legend_pos': 'upper right'} self.plot_dicts['on'] = { 'plotfn': self.plot_line, 'ax_id': 'main', 'xvals': self.proc_data_dict['xvals_B'], 'xlabel': self.proc_data_dict['xlabel'][0], 'xunit': self.proc_data_dict['xunit'][0][0], 'yvals': self.proc_data_dict['yvals_B'], 'ylabel': self.proc_data_dict['ylabel'], 'yunit': self.proc_data_dict['yunit'], 'setlabel': 'B', 'do_legend': True, 'legend_pos': 'upper right'} if self.do_fitting: self.plot_dicts['line_fit_A'] = { 'ax_id': 'main', 'plotfn': self.plot_fit, 'fit_res': self.fit_dicts['line_fit_A']['fit_res'], 'plot_init': self.options_dict['plot_init'], 'setlabel': 'Fit A', 'do_legend': True} self.plot_dicts['line_fit_B'] = { 'ax_id': 'main', 'plotfn': self.plot_fit, 'fit_res': self.fit_dicts['line_fit_B']['fit_res'], 'plot_init': self.options_dict['plot_init'], 'setlabel': 'Fit B', 'do_legend': True} ic, ic_unit = SI_val_to_msg_str( self.proc_data_dict['intersect'][0], self.proc_data_dict['xunit'][0][0], return_type=float) self.plot_dicts['intercept_message'] = { 'ax_id': 'main', 'plotfn': self.plot_line, 'xvals': [self.proc_data_dict['intersect'][0]], 'yvals': [self.proc_data_dict['intersect'][1]], 'line_kws': {'alpha': .5, 'color':'gray', 'markersize':15}, 'marker': 'o', 'setlabel': 'Intercept: {:.3f} {}'.format(ic, ic_unit), 'do_legend': True}
def prepare_plots(self): self.plot_dicts['main'] = { 'plotfn': self.plot_line, 'xvals': self.proc_data_dict['xvals_off'], 'xlabel': self.raw_data_dict['xlabel'][0], 'xunit': self.raw_data_dict['xunit'][0][0], 'yvals': self.proc_data_dict['yvals_off'], 'ylabel': self.proc_data_dict['ylabel'], 'yunit': self.proc_data_dict['yunit'], 'setlabel': 'CZ off', 'title': (self.raw_data_dict['timestamps'][0] + ' \n' + self.raw_data_dict['measurementstring'][0]), 'do_legend': True, 'yrange': (0,1), 'legend_pos': 'upper right'} self.plot_dicts['on'] = { 'plotfn': self.plot_line, 'ax_id': 'main', 'xvals': self.proc_data_dict['xvals_on'], 'xlabel': self.raw_data_dict['xlabel'][0], 'xunit': self.raw_data_dict['xunit'][0][0], 'yvals': self.proc_data_dict['yvals_on'], 'ylabel': self.proc_data_dict['ylabel'], 'yunit': self.proc_data_dict['yunit'], 'setlabel': 'CZ on', 'do_legend': True, 'legend_pos': 'upper right'} if self.do_fitting: self.plot_dicts['line_fit_off'] = { 'ax_id': 'main', 'plotfn': self.plot_fit, 'fit_res': self.fit_dicts['line_fit_off']['fit_res'], 'plot_init': self.options_dict['plot_init'], 'setlabel': 'Fit CZ off', 'do_legend': True} self.plot_dicts['line_fit_on'] = { 'ax_id': 'main', 'plotfn': self.plot_fit, 'fit_res': self.fit_dicts['line_fit_on']['fit_res'], 'plot_init': self.options_dict['plot_init'], 'setlabel': 'Fit CZ on', 'do_legend': True} ic, ic_unit = SI_val_to_msg_str( self.proc_data_dict['zero_phase_diff_intersect'], self.raw_data_dict['xunit'][0][0], return_type=float) self.plot_dicts['intercept_message'] = { 'ax_id': 'main', 'plotfn': self.plot_line, 'xvals': [self.proc_data_dict['zero_phase_diff_intersect']], 'yvals': [np.mean(self.proc_data_dict['xvals_on'])], 'line_kws': {'alpha': 0}, 'setlabel': 'Intercept: {:.1f} {}'.format(ic, ic_unit), 'do_legend': True}
def buildTreeSnapshot(self, snapshot): # exists so that function can be called with no data in construction if snapshot is None: return parent = self.invisibleRootItem() for ins in sorted(snapshot.keys()): ins_snapshot = snapshot[ins] if ins not in self.nodes: self.nodes[ins] = QtGui.QTreeWidgetItem([ins, "", ""]) parent.addChild(self.nodes[ins]) node = self.nodes[ins] for par_name in sorted(ins_snapshot['parameters'].keys()): par_snap = ins_snapshot['parameters'][par_name] # Depending on the type of data stored in value do different # things, currently only blocks non-dicts if 'value' in par_snap.keys(): # Some parameters do not have a value, these are not shown # in the instrument monitor. if not isinstance(par_snap['value'], dict): value_str, unit = SI_val_to_msg_str( par_snap['value'], par_snap['unit']) # Omits printing of the date to make it more readable if par_snap['ts'] is not None: latest_str = par_snap['ts'][11:] else: latest_str = '' # Name of the node in the self.nodes dictionary param_node_name = '{}.{}'.format(ins, par_name) # If node does not yet exist, create a node if param_node_name not in self.nodes: param_node = QtGui.QTreeWidgetItem( [par_name, value_str, unit, latest_str]) node.addChild(param_node) self.nodes[param_node_name] = param_node else: # else update existing node param_node = self.nodes[param_node_name] param_node.setData(1, 0, value_str) param_node.setData(2, 0, unit) param_node.setData(3, 0, latest_str)
def test_SI_val_to_msg_str(self): val, unit = SI_val_to_msg_str(1030, 'm') self.assertEqual(val, str(1.03)) self.assertEqual(unit, 'km')
def prepare_plots(self): # Did we load two voltage components (shall we do 2D plots?) two_dim_data = len( self.proc_data_dict['all_channel_int_voltages'][0]) == 2 eff_voltage_label = self.proc_data_dict['shots_xlabel'] eff_voltage_unit = self.proc_data_dict['shots_xunit'] x_volt_label = self.raw_data_dict['value_names'][0] x_volt_unit = self.raw_data_dict['value_units'][0] if two_dim_data: y_volt_label = self.raw_data_dict['value_names'][1] y_volt_unit = self.raw_data_dict['value_units'][1] z_hist_label = 'Counts' label_0 = '|g> prep.' label_1 = '|e> prep.' title = ('\n' + self.timestamps[0] + ' - "' + self.raw_data_dict['measurementstring'] + '"') #### 1D histograms log_hist = self.options_dict.get('log_hist', False) bin_x = self.proc_data_dict['bin_edges'] bin_y = self.proc_data_dict['hist'] self.plot_dicts['hist_0'] = { 'title': 'Binned Shot Counts' + title, 'ax_id': '1D_histogram', 'plotfn': self.plot_bar, 'xvals': bin_x, 'yvals': bin_y[0], 'xwidth': self.proc_data_dict['binsize'], 'bar_kws': { 'log': log_hist, 'alpha': .4, 'facecolor': 'C0', 'edgecolor': 'C0' }, 'setlabel': label_0, 'xlabel': eff_voltage_label, 'xunit': eff_voltage_unit, 'ylabel': z_hist_label, } self.plot_dicts['hist_1'] = { 'ax_id': '1D_histogram', 'plotfn': self.plot_bar, 'xvals': bin_x, 'yvals': bin_y[1], 'xwidth': self.proc_data_dict['binsize'], 'bar_kws': { 'log': log_hist, 'alpha': .3, 'facecolor': 'C3', 'edgecolor': 'C3' }, 'setlabel': label_1, 'do_legend': True, 'xlabel': eff_voltage_label, 'xunit': eff_voltage_unit, 'ylabel': z_hist_label, } if log_hist: self.plot_dicts['hist_0']['yrange'] = (0.5, 1.5 * np.max(bin_y[0])) self.plot_dicts['hist_1']['yrange'] = (0.5, 1.5 * np.max(bin_y[1])) #### CDF cdf_xs = self.proc_data_dict['cumsum_x'] cdf_ys = self.proc_data_dict['cumsum_y'] cdf_ys[0] = cdf_ys[0] / np.max(cdf_ys[0]) cdf_ys[1] = cdf_ys[1] / np.max(cdf_ys[1]) xra = (bin_x[0], bin_x[-1]) self.plot_dicts['cdf_shots_0'] = { 'title': 'Culmulative Shot Counts (no binning)' + title, 'ax_id': 'cdf', 'plotfn': self.plot_line, 'xvals': cdf_xs[0], 'yvals': cdf_ys[0], 'setlabel': label_0, 'xrange': xra, 'line_kws': { 'color': 'C0', 'alpha': 0.3 }, 'marker': '', 'xlabel': eff_voltage_label, 'xunit': eff_voltage_unit, 'ylabel': 'Culmulative Counts', 'yunit': 'norm.', 'do_legend': True, } self.plot_dicts['cdf_shots_1'] = { 'ax_id': 'cdf', 'plotfn': self.plot_line, 'xvals': cdf_xs[1], 'yvals': cdf_ys[1], 'setlabel': label_1, 'line_kws': { 'color': 'C3', 'alpha': 0.3 }, 'marker': '', 'xlabel': eff_voltage_label, 'xunit': eff_voltage_unit, 'ylabel': 'Culmulative Counts', 'yunit': 'norm.', 'do_legend': True, } ### Vlines for thresholds th_raw = self.proc_data_dict['threshold_raw'] threshs = [ th_raw, ] if self.do_fitting: threshs.append(self.proc_data_dict['threshold_fit']) threshs.append(self.proc_data_dict['threshold_discr']) for ax in ['1D_histogram', 'cdf']: self.plot_dicts[ax + '_vlines_thresh'] = { 'ax_id': ax, 'plotfn': self.plot_vlines_auto, 'xdata': threshs, 'linestyles': ['--', '-.', ':'], 'labels': ['$th_{raw}$', '$th_{fit}$', '$th_{d}$'], 'colors': ['0.3', '0.5', '0.2'], 'do_legend': True, } #### 2D Histograms if two_dim_data: iq_centers = None if 'IQ_pos' in self.proc_data_dict and self.proc_data_dict[ 'IQ_pos'] is not None: iq_centers = self.proc_data_dict['IQ_pos'] peak_marker_2D = { 'plotfn': self.plot_line, 'xvals': iq_centers[1], 'yvals': iq_centers[0], 'xlabel': x_volt_label, 'xunit': x_volt_unit, 'ylabel': y_volt_label, 'yunit': y_volt_unit, 'marker': 'x', 'linestyle': '', 'color': 'black', #'line_kws': {'markersize': 1, 'color': 'black', 'alpha': 1}, 'setlabel': 'Peaks', 'do_legend': True, } peak_marker_2D_rot = deepcopy(peak_marker_2D) peak_marker_2D_rot['xvals'] = iq_centers[0] peak_marker_2D_rot['yvals'] = iq_centers[1] self.plot_dicts['2D_histogram_0'] = { 'title': 'Raw ' + label_0 + ' Binned Shot Counts' + title, 'ax_id': '2D_histogram_0', 'plotfn': self.plot_colorxy, 'xvals': self.proc_data_dict['2D_histogram_y'], 'yvals': self.proc_data_dict['2D_histogram_x'], 'zvals': self.proc_data_dict['2D_histogram_z'][0], 'xlabel': x_volt_label, 'xunit': x_volt_unit, 'ylabel': y_volt_label, 'yunit': y_volt_unit, 'zlabel': z_hist_label, 'zunit': '-', 'cmap': 'Blues', } if iq_centers is not None: dp = deepcopy(peak_marker_2D) dp['ax_id'] = '2D_histogram_0' self.plot_dicts['2D_histogram_0_marker'] = dp self.plot_dicts['2D_histogram_1'] = { 'title': 'Raw ' + label_1 + ' Binned Shot Counts' + title, 'ax_id': '2D_histogram_1', 'plotfn': self.plot_colorxy, 'xvals': self.proc_data_dict['2D_histogram_y'], 'yvals': self.proc_data_dict['2D_histogram_x'], 'zvals': self.proc_data_dict['2D_histogram_z'][1], 'xlabel': x_volt_label, 'xunit': x_volt_unit, 'ylabel': y_volt_label, 'yunit': y_volt_unit, 'zlabel': z_hist_label, 'zunit': '-', 'cmap': 'Reds', } if iq_centers is not None: dp = deepcopy(peak_marker_2D) dp['ax_id'] = '2D_histogram_1' self.plot_dicts['2D_histogram_1_marker'] = dp #### Scatter Shots volts = self.proc_data_dict['all_channel_int_voltages'] vxr = [ np.min([np.min(a) for a in volts[:][1]]), np.max([np.max(a) for a in volts[:][1]]) ] vyr = [ np.min([np.min(a) for a in volts[:][0]]), np.max([np.max(a) for a in volts[:][0]]) ] self.plot_dicts['2D_shots_0'] = { 'title': 'Raw Shots' + title, 'ax_id': '2D_shots', 'plotfn': self.plot_line, 'xvals': volts[0][1], 'yvals': volts[0][0], #'range': [vxr, vyr], #'xrange': vxr, #'yrange': vyr, 'xlabel': x_volt_label, 'xunit': x_volt_unit, 'ylabel': y_volt_label, 'yunit': y_volt_unit, 'zlabel': z_hist_label, 'marker': 'o', 'linestyle': '', 'color': 'C0', 'line_kws': { 'markersize': 0.25, 'color': 'C0', 'alpha': 0.5 }, 'setlabel': label_0, 'do_legend': True, } self.plot_dicts['2D_shots_1'] = { 'ax_id': '2D_shots', 'plotfn': self.plot_line, 'xvals': volts[1][1], 'yvals': volts[1][0], #'range': [vxr, vyr], #'xrange': vxr, #'yrange': vyr, 'xlabel': x_volt_label, 'xunit': x_volt_unit, 'ylabel': y_volt_label, 'yunit': y_volt_unit, 'zlabel': z_hist_label, 'marker': 'o', 'linestyle': '', 'color': 'C3', 'line_kws': { 'markersize': 0.25, 'color': 'C3', 'alpha': 0.5 }, 'setlabel': label_1, 'do_legend': True, } if iq_centers is not None: dp = deepcopy(peak_marker_2D) dp['ax_id'] = '2D_shots' self.plot_dicts['2D_shots_marker'] = dp # The cumulative histograms ##################################### # Adding the fits to the figures # ##################################### if self.do_fitting: #todo: add seperate fits for residual and main gaussians x = np.linspace(bin_x[0], bin_x[-1], 150) para_hist_tmp = self.fit_res['shots_all_hist'].best_values para_cdf = self.fit_res['shots_all'].best_values para_hist = para_cdf para_hist['A_amplitude'] = para_hist_tmp['A_amplitude'] para_hist['B_amplitude'] = para_hist_tmp['B_amplitude'] ro_g = ro_gauss(x=[x, x], **para_hist) self.plot_dicts['new_fit_shots_0'] = { 'ax_id': '1D_histogram', 'plotfn': self.plot_line, 'xvals': x, 'yvals': ro_g[0], 'setlabel': 'Fit ' + label_0, 'line_kws': { 'color': 'C0' }, 'marker': '', 'do_legend': True, } self.plot_dicts['new_fit_shots_1'] = { 'ax_id': '1D_histogram', 'plotfn': self.plot_line, 'xvals': x, 'yvals': ro_g[1], 'marker': '', 'setlabel': 'Fit ' + label_1, 'line_kws': { 'color': 'C3' }, 'do_legend': True, } self.plot_dicts['cdf_fit_shots_0'] = { 'ax_id': 'cdf', 'plotfn': self.plot_line, 'xvals': x, 'yvals': self._CDF_0(x), 'setlabel': 'Fit ' + label_0, 'line_kws': { 'color': 'C0', 'alpha': 0.8 }, 'linestyle': ':', 'marker': '', 'do_legend': True, } self.plot_dicts['cdf_fit_shots_1'] = { 'ax_id': 'cdf', 'plotfn': self.plot_line, 'xvals': x, 'yvals': self._CDF_1(x), 'marker': '', 'linestyle': ':', 'setlabel': 'Fit ' + label_1, 'line_kws': { 'color': 'C3', 'alpha': 0.8 }, 'do_legend': True, } ########################################## # Add textbox (eg.g Thresholds, fidelity # # information, number of shots etc) # ########################################## if not self.presentation_mode: fit_text = 'Thresholds:' fit_text += '\nName | Level | Fidelity' thr, th_unit = SI_val_to_msg_str( self.proc_data_dict['threshold_raw'], eff_voltage_unit, return_type=float) raw_th_msg = ('\n>raw | ' + '{:.2f} {} | '.format(thr, th_unit) + '{:.1f}%'.format( self.proc_data_dict['F_assignment_raw'] * 100)) fit_text += raw_th_msg if self.do_fitting: thr, th_unit = SI_val_to_msg_str( self.proc_data_dict['threshold_fit'], eff_voltage_unit, return_type=float) fit_th_msg = ( '\n>fit | ' + '{:.2f} {} | '.format(thr, th_unit) + '{:.1f}%'.format( self.proc_data_dict['F_assignment_fit'] * 100)) fit_text += fit_th_msg thr, th_unit = SI_val_to_msg_str( self.proc_data_dict['threshold_discr'], eff_voltage_unit, return_type=float) fit_th_msg = ( '\n>dis | ' + '{:.2f} {} | '.format(thr, th_unit) + '{:.1f}%'.format(self.proc_data_dict['F_discr'] * 100)) fit_text += fit_th_msg snr = self.fit_res['shots_all'].params['SNR'] fit_text += '\nSNR (fit) = ${:.3f}\\pm{:.3f}$'.format( snr.value, snr.stderr) fr = self.fit_res['shots_all'] bv = fr.params a_sp = bv['A_spurious'] fit_text += '\n\nSpurious Excitations:' fit_text += '\n$p(e|0) = {:.3f}$'.format(a_sp.value) if self.options_dict.get('fixed_p01', True) == True: fit_text += '$\\pm{:.3f}$'.format(a_sp.stderr) else: fit_text += ' (fixed)' b_sp = bv['B_spurious'] fit_text += ' \n$p(g|\\pi) = {:.3f}$'.format(b_sp.value) if self.options_dict.get('fixed_p10', True) == True: fit_text += '$\\pm{:.3f}$'.format(b_sp.stderr) else: fit_text += ' (fixed)' if two_dim_data: offs = self.proc_data_dict['raw_offset'] #fit_text += '\nOffset from raw:\n' #fit_text += '({:.3f},{:.3f}) {},\n'.format(offs[0], offs[1], eff_voltage_unit) fit_text += '\n\nRotated by ${:.1f}^\\circ$'.format( (offs[2] * 180 / np.pi) % 180) auto_rot = self.options_dict.get('auto_rotation_angle', True) fit_text += '(auto)' if auto_rot else '(man.)' else: fit_text += '\n\n(Single quadrature data)' fit_text += '\n\nTotal shots: %d+%d' % ( *self.proc_data_dict['nr_shots'], ) for ax in ['cdf', '1D_histogram']: self.plot_dicts['text_msg_' + ax] = { 'ax_id': ax, # 'ypos': 0.15, 'xpos': 1.05, 'horizontalalignment': 'left', 'plotfn': self.plot_text, 'box_props': 'fancy', 'text_string': fit_text, }
def run_fitting(self): super().run_fitting() self.fit_res['fit_res_P2'] = OrderedDict() self.fit_res['fit_res_P1'] = OrderedDict() self.fit_res['fit_res_P0'] = OrderedDict() decay_mod = lmfit.Model(f.ExpDecayFunc, independent_vars='t') decay_mod.set_param_hint('tau', value=15e-6, min=0, vary=True) decay_mod.set_param_hint('amplitude', value=1, min=0, vary=True) decay_mod.set_param_hint('offset', value=0, vary=True) decay_mod.set_param_hint('n', value=1, vary=False) params1 = decay_mod.make_params() try: for value_name in self.raw_data_dict['value_names']: fit_res_P2 = decay_mod.fit( data=self.proc_data_dict['P2'][value_name], t=self.proc_data_dict['time'], params=params1) self.fit_res['fit_res_P2'] = fit_res_P2 tau2_best = fit_res_P2.best_values['tau'] text_msg = ( r'$T_1^{fe}$ : ' + SI_val_to_msg_str( round(fit_res_P2.params['tau'].value, 6), 's')[0] + SI_val_to_msg_str(fit_res_P2.params['tau'].value, 's')[1]) except Exception as e: logging.warning("Fitting failed") logging.warning(e) self.fit_res['fit_res_P2'] = {} doubledecay_mod = lmfit.Model(f.DoubleExpDecayFunc, independent_vars='t') doubledecay_mod.set_param_hint('tau1', value=10e-6, min=0, vary=True) doubledecay_mod.set_param_hint('tau2', value=tau2_best, min=0, vary=False) doubledecay_mod.set_param_hint('amp1', value=1.0, min=0, vary=True) doubledecay_mod.set_param_hint('amp2', value=-4.5, min=-10, vary=True) doubledecay_mod.set_param_hint('offset', value=.0, vary=True) doubledecay_mod.set_param_hint('n', value=1, vary=False) params2 = doubledecay_mod.make_params() try: for value_name in self.raw_data_dict['value_names']: fit_res_P1 = doubledecay_mod.fit( data=self.proc_data_dict['P1'][value_name], t=self.proc_data_dict['time'], params=params2) self.fit_res['fit_res_P1'] = fit_res_P1 tau1_best = fit_res_P1.best_values['tau1'] amp1_best = fit_res_P1.best_values['amp1'] amp2_best = fit_res_P1.best_values['amp2'] text_msg += ( '\n' + r'$T_1^{eg}$ : ' + SI_val_to_msg_str( round(fit_res_P1.params['tau1'].value, 6), 's')[0] + SI_val_to_msg_str(fit_res_P1.params['tau1'].value, 's')[1]) except Exception as e: logging.warning("Doulbe Fitting failed") logging.warning(e) self.fit_res['fit_res_P1'] = {} doubledecay_mod = lmfit.Model(DoubleExpDecayFunclocal, independent_vars='t') doubledecay_mod.set_param_hint('tau1', value=tau1_best, min=0, vary=False) doubledecay_mod.set_param_hint('tau2', value=tau2_best, min=0, vary=False) doubledecay_mod.set_param_hint('amp1', value=amp1_best, min=0, vary=False) doubledecay_mod.set_param_hint('amp2', value=amp2_best, min=-10, vary=False) doubledecay_mod.set_param_hint('offset', value=.0, vary=True) doubledecay_mod.set_param_hint('n', value=1, vary=False) params3 = doubledecay_mod.make_params() try: for value_name in self.raw_data_dict['value_names']: fit_res_P0 = doubledecay_mod.fit( data=self.proc_data_dict['P0'][value_name], t=self.proc_data_dict['time'], params=params3) self.fit_res['fit_res_P0'] = fit_res_P0 except Exception as e: logging.warning("Double Fitting failed") logging.warning(e) self.fit_res['fit_res_P0'] = {} self.proc_data_dict['fit_msg'] = text_msg