def plot_dataset(dataset: qcodes.DataSet, parameter_names: Optional[list] = None, fig: Optional[int] = 1) -> None: """ Plot a dataset to matplotlib figure window Args: dataset: DataSet to be plotted parameter_names: List of arrays to be plotted fig: Specification if Matplotlib figure window """ if parameter_names is None: parameter_names = [dataset.default_parameter_name()] if parameter_names == 'all': parameter_names = [name for name in dataset.arrays.keys() if not dataset.arrays[name].is_setpoint] default_array = dataset.default_parameter_array() if fig: plt.figure(fig) plt.clf() if len(default_array.shape) >= 2: if len(parameter_names) > 1: arrays = [dataset.default_parameter_array(parameter_name) for parameter_name in parameter_names] plot_handle = MatPlot(*arrays, num=fig) else: plot_handle = MatPlot(dataset.default_parameter_array(parameter_names[0]), num=fig) else: for idx, parameter_name in enumerate(parameter_names): if idx == 0: plot_handle = MatPlot(dataset.default_parameter_array(parameter_name), num=fig) else: plot_handle.add(dataset.default_parameter_array(parameter_name,))
def _create_plot(i, name, data, counter_two): # Step the color on all subplots no just on plots # within the same axis/subplot # this is to match the qcodes-pyqtplot behaviour. title = "{} #{:03d}".format(CURRENT_EXPERIMENT["sample_name"], data.location_provider.counter) rasterized_note = " rasterized plot full data available in datafile" color = 'C' + str(counter_two) counter_two += 1 plot = MatPlot() inst_meas_name = "{}_{}".format(i._instrument.name, name) inst_meas_data = getattr(data, inst_meas_name) inst_meta_data = __get_plot_type(inst_meas_data, plot) if 'z' in inst_meta_data: xlen, ylen = inst_meta_data['z'].shape rasterized = xlen * ylen > 5000 plot.add(inst_meas_data, rasterized=rasterized) else: rasterized = False plot.add(inst_meas_data, color=color) plot.subplots[0].grid() if rasterized: plot.subplots[0].set_title(title + rasterized_note) else: plot.subplots[0].set_title(title) plot.save("{}_{:03d}.pdf".format(plot.get_default_title(), counter_two)) plot.fig.canvas.draw()
def diffDataset(alldata, diff_dir='y', sigma=2, fig=None, meas_arr_name='measured'): """ Differentiate a dataset and plot the result. Args: alldata (qcodes DataSet) diff_dir (str): direction to differentiate in meas_arr_name (str): name of the measured array to be differentiated fig (int): the number for the figure to plot sigma (float): parameter for gaussian filter kernel """ meas_arr_name = alldata.default_parameter_name(meas_arr_name) meas_array = alldata.arrays[meas_arr_name] imx = qtt.utilities.tools.diffImageSmooth(meas_array.ndarray, dy=diff_dir, sigma=sigma) name = 'diff_dir_%s' % diff_dir name = uniqueArrayName(alldata, name) data_arr = qcodes.DataArray( name=name, label=name, array_id=name, set_arrays=meas_array.set_arrays, preset_data=imx) alldata.add_array(data_arr) if fig is not None: plt.figure(fig) plt.clf() plot = MatPlot(interval=0, num=fig) plot.add(alldata.arrays[name]) plot.fig.axes[0].autoscale(tight=True) plot.fig.axes[1].autoscale(tight=True) return alldata
def _create_plot(i, name, data, counter_two, display_plot=True): # Step the color on all subplots no just on plots # within the same axis/subplot # this is to match the qcodes-pyqtplot behaviour. title = "{} #{:03d}".format(CURRENT_EXPERIMENT["sample_name"], data.location_provider.counter) rasterized_note = " rasterized plot full data available in datafile" color = 'C' + str(counter_two) counter_two += 1 plot = MatPlot() if issubclass( i.__class__, MultiChannelInstrumentParameter) or i._instrument is None: inst_meas_name = name else: inst_meas_name = "{}_{}".format(i._instrument.name, name) inst_meas_data = getattr(data, inst_meas_name) try: inst_meas_data = getattr(data, inst_meas_name) except AttributeError: inst_meas_name = "{}{}_0_0".format(i._instrument.name, name) inst_meas_data = getattr(data, inst_meas_name) inst_meta_data = __get_plot_type(inst_meas_data, plot) if 'z' in inst_meta_data: xlen, ylen = inst_meta_data['z'].shape rasterized = xlen * ylen > 5000 po = plot.add(inst_meas_data, rasterized=rasterized) auto_color_scale_from_config(po.colorbar, auto_color_scale, inst_meta_data['z'], cutoff_percentile) else: rasterized = False plot.add(inst_meas_data, color=color) plot.subplots[0].grid() if rasterized: plot.subplots[0].set_title(title + rasterized_note) else: plot.subplots[0].set_title(title) title_list = plot.get_default_title().split(sep) title_list.insert(-1, CURRENT_EXPERIMENT['pdf_subfolder']) title = sep.join(title_list) plot.rescale_axis() plot.tight_layout() plot.save("{}_{:03d}.pdf".format(title, counter_two)) if display_plot: plot.fig.canvas.draw() plt.show() else: plt.close(plot.fig)
def plot_flips(self , figsize=(8, 3)): up_proportion_arrays = [ val for key, val in self.results.ESR.items() if key.startswith('up_proportion') and 'idxs' not in key ] assert len(up_proportion_arrays) >= 2 plot = MatPlot(up_proportion_arrays, marker='o', ms=5, linestyle='', figsize=figsize) ax = plot[0] ax.set_xlim(-0.5, len(up_proportion_arrays[0])-0.5) ax.set_ylim(-0.015, 1.015) ax.set_xlabel('Shot index') ax.set_ylabel('Up proportion') # Add threshold lines ax.hlines(self.results.NMR.threshold_up_proportion, *ax.get_xlim(), lw=3) ax.hlines(self.results.NMR.threshold_low, *ax.get_xlim(), color='grey', linestyle='--', lw=2) ax.hlines(self.results.NMR.threshold_high, *ax.get_xlim(), color='grey', linestyle='--', lw=2) if 'initialization' in self.results: plot.add(self.results.initialization.up_proportions, marker='o', ms=8, linestyle='', color='grey', zorder=0, alpha=0.5) initialization_filtered_shots = next( val for key, val in self.results["initialization"].items() if key.startswith("filtered_shots") ) else: initialization_filtered_shots = [True] * len(self.results.NMR.filtered_shots) NMR_filtered_shots = self.results.NMR.filtered_shots for k, up_proportion_tuple in enumerate(zip(*up_proportion_arrays)): if not initialization_filtered_shots[k]: color = 'orange' elif not NMR_filtered_shots[k]: color = 'red' else: color = 'green' ax.plot([k, k], sorted(up_proportion_tuple)[-2:], color=color, zorder=-1) plot.tight_layout() # print contrast sorted_up_proportions = np.sort(np.array(up_proportion_arrays), axis=0) up_proportion = np.mean(sorted_up_proportions[-1]) dark_counts = np.mean(sorted_up_proportions[:-1]) contrast = up_proportion - dark_counts print(f'Contrast = {up_proportion:.2f} - {dark_counts:.2f} = {contrast:.2f}') return plot
def test_return_handle(self): plotM = MatPlot(interval=0) returned_handle = plotM.add([1, 2, 3]) line_handle = plotM[0].get_lines()[0] self.assertIs(returned_handle, line_handle) plotM.clear() plt.close(plotM.fig)
time_range = time_range fitting_num = X_num x = np.linspace(0, fitting_num - 1, fitting_num) t = np.linspace(0, time_range, fitting_num) #pars1, pcov = curve_fit(sequence_decay, x, average[0],) pars1, pcov = curve_fit(Exp_Sin_decay, t * 1e6, average[0], p0=(0.2, 0.3, 6, 1.5, 0.3), bounds=((0, -np.inf, 0.2, -np.inf, -np.inf), (np.inf, np.inf, 10, np.inf, np.inf))) pt = MatPlot() pt.add(x=t, y=average[0], xlabel='dephasing_time', ylabel='probability |11>') pt.add(x=t, y=sequence_decay(t * 1e6, pars1[0], pars1[1], pars1[-1])) pt.add( x=t, y=Exp_Sin_decay(t * 1e6, pars1[0], pars1[1], pars1[2], pars1[3], pars1[4]), ) print('T2* in exp1:', pars1[-1], 'us') print('freq:', pars1[2], 'MHz') #pars2, pcov = curve_fit(Exp_Sin_decay, x, average[1],) pars2, pcov = curve_fit(Exp_Sin_decay, t * 1e6, average[1], p0=(0.2, 0.3, 6, 1.5, 0.3), bounds=((0, -np.inf, 0.2, -np.inf, -np.inf), (np.inf, np.inf, 10, np.inf, np.inf)))
fitting_point = 51 x = np.linspace(0, 1.5e-6, fitting_point)[:fitting_point] y = ds.probability_data[:, i, 0:fitting_point].mean(axis=0) pars, pcov = curve_fit(T2_star_fitting, x, y, p0=(0.8, 0.3, 4e6, 0, 0.5e-6), bounds=((0.25, -np.inf, 1e6, -np.inf, 0), (2, np.inf, 10e6, np.inf, 5))) #pars, pcov = curve_fit(T2_star_fitting2, x, y, # p0 = (0.8, 0.3, 0.5e-6), # bounds = ((0.25,-np.inf,0),(2,np.inf,8e-6))) #%% pt = MatPlot() #pt.add(x = x, y = T1_fitting(x,pars[0],pars[1],pars[2])) pt.add(x=x, y=T2_star_fitting(x, pars[0], pars[1], pars[2], pars[3], pars[4])) #pt.add(x = x, y = T2_star_fitting2(x,pars[0],pars[1],pars[2])) pt.add(x=x, y=ds.probability_data[:, i, start_point:start_point + fitting_point].mean(axis=0)) print('T1 is: ', pars[0] * 1000, 'ms') #pt1 = MatPlot() #pt1.add_to_plot(x = x, y = T1_fitting(x,pars[0],pars[1],pars[2]),fmt='*') #%%
x, y, p0=(0.9, 0.2, 0.3), bounds=((0.5, 0, 0), (1, 0.8, 0.8))) # bounds = ((), ())) #pars, pcov = curve_fit(RB_Fidelity, x, y, # p0 = (-0.9, 0.2, -0.4), # bounds = ((-1, 0, -1),(-0.5, 0.8, 0))) #%% plot_point = fitting_point pt = MatPlot() pt.add(x=x[:plot_point], y=ds.probability_data[:, i, 11:11 + fitting_point].mean(axis=0)[:plot_point], fmt='bp', xlabel='Clifford Numbers', ylabel='$P_{|1>}$', xunit='N', yunit='%') pt.add( x=x[:plot_point], y=RB_Fidelity(x, pars[0], pars[1], pars[2])[:plot_point], fmt='b--', ) #pt.add_to_plot(xlabel = 'Clifford Numbers') #%% #pt1 = MatPlot() #pt1.add(z=ds.probability_data[:,i,11:11+fitting_point]) ds2 = DS2 x2 = np.array([len(clifford_sets[0][i]) for i in range(fitting_point)])
location_15crot = '2017-10-25/19-36-23/BillCoish_experimentAllXY_sequence' location_3init = '2017-10-25/20-04-38/BillCoish_experimentAllXY_sequence' #location = '2017-12-12/17-47-41/RB_experimentAllXY_sequence' #%% ds = load_data(location=location_3init, io=IO, formatter=formatter) #%% average trace x = ds.index3_set[0, 0, 0, 0, :] i = 0 y = ds.raw_data[:, 0, i, :, :].mean(axis=(0, 1)) y = ds.raw_data[10, 0, i, :, :].mean(axis=0) y = ds.raw_data[10, 0, i, 58, :] #%% ''' Qubit = 2 i = 0 if Qubit == 2 else 1 fitting_point = 59 x = np.linspace(1e-6, 25e-3, 60)[:fitting_point] y = ds.probability_data[:,i,:fitting_point].mean(axis = 0) pars, pcov = curve_fit(T1_fitting, x, y,) ''' #%% pt = MatPlot() pt.add(x=x, y=y) #print('T1 is: ', pars[0], 'ms')
pars1, pcov1 = curve_fit(RB_Fidelity, x[start:], P1[start:], p0 = (0.9, 0.2, 0), bounds = ((0.5, 0, 0),(1, 1, 0.001))) pars2, pcov2 = curve_fit(RB_Fidelity, x[start:], P2[start:], p0 = (0.9, 0.2, 0), bounds = ((0.5, 0, 0),(1, 1, 0.001))) pars3, pcov3 = curve_fit(RB_Fidelity, x[start:], P3[start:], p0 = (0.9, 0.2, 0), bounds = ((0.5, 0, 0),(1, 1, 0.001))) P = 3/15 * (pars1[0] + pars2[0]) + 9/15 * pars3[0] Fidelity = 1- (1-P)*3/4 print('Fidelity:', Fidelity) #%% import matplotlib as mpl #plot_point = fitting_points plot_points = fitting_points pt = MatPlot() pt.add(x = x[:plot_points],y = P1[:plot_points], fmt = 'rp',xlabel = 'Clifford Numbers', ylabel = '$P_{|1>}$', xunit = 'N', yunit = '%') pt.add(x = x[:plot_points],y = P2[:plot_points], fmt = 'bp',xlabel = 'Clifford Numbers', ylabel = '$P_{|1>}$', xunit = 'N', yunit = '%') pt.add(x = x[:plot_points],y = P3[:plot_points], fmt = 'gp',xlabel = 'Clifford Numbers', ylabel = '$P_{|1>}$', xunit = 'N', yunit = '%') pt.add(x = x[:plot_points], y = RB_Fidelity(x,pars1[0],pars1[1],pars1[2])[:plot_points],fmt = 'r--', ) pt.add(x = x[:plot_points], y = RB_Fidelity(x,pars2[0],pars2[1],pars2[2])[:plot_points],fmt = 'b--', ) pt.add(x = x[:plot_points], y = RB_Fidelity(x,pars3[0],pars3[1],pars3[2])[:plot_points],fmt = 'g--', ) #%% character benchmarking with normalization P_pi_q1 = 0.98 P_pi_q2 = 0.97 P_init_q1 = 1#0.99 P_init_q2 = 1#0.99
x, y, p0=(0.2, 1.5e6, 0, 0.3, 2e-6), bounds=((0.3, 1e6, -np.pi, -1, 0), (0.5, 2.5e6, np.pi, 1, 10e-6))) y_fit = Exp_Sin(x, pars[0], pars[1], pars[2], pars[3], pars[4]) #%% fit resonance pt1 = MatPlot() pt1.add(x=x, y=y, fmt='bs', xlabel='Frequecny shift', ylabel='$P_{|1>}$', xunit='MHz', yunit='%') pt1.add( x=x1, y=y_fit, fmt='r--', ) # xlabel = 'Clifford Numbers', ylabel = 'probability |1>')#fmt='*') #%% fit Rabi pt1 = MatPlot() #pt1.add_to_plot(x = x, y = y, fmt='bs') #pt1.add_to_plot(x = x, y = y_fit, fmt = 'r--')#fmt='*')