def initialize_measurement(self): # Start with an empty set of actions in the loop actions = [] if self.set_vals is not None: set_loop = qc.Loop(self.set_vals[0]) elif self.points is not None: # No set vals specified, but points are, so create dummy parameter set_loop = qc.Loop(_dummy_parameter[0:self.points:1]) # Also measure the set_parameters, as we are going to update them actions += self.set_parameters else: raise RuntimeError('Either set_vals or point must be defined') # Add measurement of acquisition parameter actions.append(self.acquisition_parameter) if self.break_if: actions.append( BreakIf( partial(self.satisfies_condition_set, self.acquisition_parameter, action=self.break_if))) self.measurement = set_loop.each(*actions) return self.measurement
def do_bg_iv(md, tg_set, V_sd, states, params, tg, sd, plot_params=[], bg_step=0.02, iv_step=0.00004, wait_time=5): for state in states: md.select(state) tg_set.set(tg[0]) V_sd.set(sd[0]) sleep(wait_time) # Inner Loop (V_sd) inner_loop = qc.Loop(V_sd.sweep(sd[0], sd[1], step=iv_step)) inner_loop = inner_loop.each(*params) inner_loop = inner_loop.then(qc.Task(V_sd.set, sd[0]), qc.Wait(wait_time)) # Outer Loop (tg) loop = qc.Loop(tg_set.sweep(tg[0], tg[1], step=bg_step)) loop = loop.each(inner_loop) data = loop.get_data_set() # Show each plot plots = [] for param in plot_params: param_data = getattr(data, param, None) if param_data is None: warnings.warn("Missing parameter {} not plotted".format(param), RuntimeWarning) continue plot = qc.QtPlot() plot.add(param_data, name=param, title=param) plots.append(plot) # Define function to live update all plots def upd(): for plot in plots: plot.update() # Update plots at the end of each line loop = loop.with_bg_task(upd) # Run the loop loop.run() # Set parameters to zero tg_set.set(0) V_sd.set(0) # Clear mulberry at end md.clear()
def do2d(inst_set, start, stop, num_points, delay, inst_set2, start2, stop2, num_points2, delay2, *inst_meas, do_plots=True, use_threads=True): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step inst_set2: Second instrument to sweep over start2: Start of sweep for second instrument stop2: End of sweep for second instrument num_points2: Number of steps to perform delay2: Delay at every step for second instrument *inst_meas: do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. Returns: plot, data : returns the plot and the dataset """ for inst in inst_meas: if getattr(inst, "setpoints", False): raise ValueError("3d plotting is not supported") innerloop = qc.Loop(inst_set2.sweep(start2, stop2, num=num_points2), delay2).each(*inst_meas) outerloop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(innerloop) set_params = ((inst_set, start, stop), (inst_set2, start2, stop2)) meas_params = _select_plottables(inst_meas) plot, data = _do_measurement(outerloop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) return plot, data
def initialize_measurement(self): if self.break_if is False: self.measurement = qc.Loop(self.set_vals[0]).loop( self.set_vals[1]).each(self.acquisition_parameter) else: break_action = BreakIf( partial(self.satisfies_condition_set, self.acquisition_parameter, action=self.break_if)) self.measurement = qc.Loop(self.set_vals[0]).each( qc.Loop(self.set_vals[1]).each(self.acquisition_parameter, break_action), break_action) return self.measurement
def sweep2d(meas_param, sweep_param1, start1, stop1, step1, sweep_param2, start2, stop2, step2, delay=0.01, do_plots=True): """ Function which does a 2 dimensional sweep and optionally plots the results. Args: meas_param: parameter which we want the value of at each point sweep_param1: parameter to be swept in outer loop (default on y axis) start1: starting value for sweep_param1 stop1: final value for sweep_param1 step1: value to step sweep_param1 by sweep_param2: parameter to be swept in inner loop (default on x axis) start2: starting value for sweep_param2 stop2: final value for sweep_param2 step2: value to step sweep_param2 by delay (default 0.01): mimimum time to spend on each point do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. Returns: data (qcodes dataset) plot: QT plot """ innerloop = qc.Loop(sweep_param2.sweep(start2, stop2, step2), delay).each(meas_param) outerloop = qc.Loop(sweep_param1.sweep(start1, stop1, step1), delay).each(innerloop) set_params = ((sweep_param1, start1, stop1), (sweep_param2, start2, stop2)) meas_params = _select_plottables(meas_param) plot, data = _do_measurement(outerloop, set_params, meas_params, do_plots=do_plots) return data, plot
def do_cavity_freq_sweep(cavity, localos, cavity_freq, acq_ctrl, cavity_pm=10e6, freq_step=1e6, demod_freq=None, live_plot=True, key=None, save=True): """ Function which sweeps the cavity frequency around central value by pm_range and measures using given acq_ctr, also steps local os to keep same demod freq. Args: cavity instrument (r&s SGS100) localos instrument (r&s SGS100) cavity_freq: central cavity drive freq acq_ctrl instrument (alazar acq controller) cavity_pm (float) (default 10e6): sweep range will be cavity_freq +- this value freq_step (float) (default 1e6) demod_freq (float) (default None): default uses the current value live_plot (default true) key (default None): string specifying specific parameter array to be plotted, default is to plot all save (default True): whether to save png on completion, nb if you choose not to live plot and the measured parameter returns multiple values then unless you specify a specific one to plot via 'key' then none will be saved. Returns: data, plot(s) """ if demod_freq is None: demod_freq = get_demod_freq(cavity, localos, acq_ctrl) loop = qc.Loop(cavity.frequency.sweep(cavity_freq - cavity_pm, cavity_freq + cavity_pm, freq_step)).each( qc.Task(localos.frequency.set, (cavity.frequency + demod_freq)), acq_ctrl.acquisition) if live_plot: dataset = loop.get_data_set() dataset.data_num = dataset.location_provider.counter plot = plot_data_single_window(dataset, acq_ctrl.acquisition, key=key) try: if save: _ = loop.with_bg_task(plot.update, plot.save).run() else: _ = loop.with_bg_task(plot.update).run() print('warning: plots not saved, if you want to save this' 'plot run plot.save()') except KeyboardInterrupt: print("Measurement Interrupted") return dataset, plot else: data = loop.run() data.data_num = data.location_provider.counter plots = plot_data(data, key=key) if (key is not None) and save: plots.save() else: print('warning: plots not saved. To save one choose ' 'and run plots[i].save()') return data, plots
def top_gate_sweep_B_field_step(md, pairs, parameters): global ami, yoko_t, lockins B_field_values = [ -1.0, -0.5, -0.25, -0.05, 0.25, 0.5, 1.0 ] # if you change these you need to change the values in the analysis E_field_start = -0.7 E_field_stop = 0.5 yoko_t.voltage.post_delay = 0.1 yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 yoko_t.voltage(0) yoko_t.output('on') for field in B_field_values: ami.field.set(field) for pair in pairs: md.select(pair) sleep(10) yoko_t.voltage(E_field_start) yoko_t.voltage.post_delay = 5 * lockins[0].time_constant() loop = qc.Loop( yoko_t.voltage.sweep(E_field_start, E_field_stop, num=200)) # same as above, here if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="MD_{}_FIELD_{}".format(pair, field)) yoko_t.voltage.post_delay = 0.1 yoko_t.voltage(0) md.clear() yoko_t.output('off') ami.field.set(0)
def sweep_awg_chans(meas_param, awg_ch_1, awg_ch_2, start, stop, step, delay=0.01, live_plot=True, key=None, save=True): loop = qc.Loop(awg_ch_1.sweep(start, stop, step)).each( qc.Task(awg_ch_2.set, awg_ch_1.get), meas_param) if live_plot: dataset = loop.get_data_set() dataset.data_num = dataset.location_provider.counter plot = plot_data_single_window(dataset, meas_param, key=key) try: if save: _ = loop.with_bg_task(plot.update, plot.save).run() else: _ = loop.with_bg_task(plot.update).run() print('warning: plots not saved, if you want to save this' 'plot run plot.save()') except KeyboardInterrupt: print("Measurement Interrupted") return dataset, plot else: data = loop.run() data.data_num = data.location_provider.counter plots = plot_data(data, key=key) if (key is not None) and save: plots.save() else: print('warning: plots not saved. To save one choose ' 'and run plots[i].save()') return data, plots
def get(self): self.loop = qc.Loop(self.y_gate[self.DC_y_vals]).loop( self.x_gate[self.DC_x_vals]).each(self.acquisition_parameter) self.acquisition_parameter.temporary_settings(continuous=True) try: if not self.continuous: self.setup() self.data = self.loop.run(name=f'multi_2D_scan', set_active=False, formatter=self.formatter, save_metadata=False) # except: # logger.debug('except stopping') # self.layout.stop() # self.acquisition_parameter.clear_settings() # raise finally: if not self.continuous: logger.debug('finally stopping') self.layout.stop() self.acquisition_parameter.clear_settings() arr = np.zeros( (len(self.DC_y_vals) * self.pts, len(self.DC_x_vals) * self.pts)) for y_idx in range(len(self.DC_y_vals)): for x_idx in range(len(self.DC_x_vals)): DC_data = self.data.DC_voltage[y_idx, x_idx] arr[y_idx * self.pts:(y_idx + 1) * self.pts, x_idx * self.pts:(x_idx + 1) * self.pts] = DC_data return arr,
def top_gate_leak_test(pairs, parameters, start=-0.8, stop=1.0): # value in volts global md, ami, yoko_t, lockins E_field_start = start E_field_stop = stop yoko_t.voltage.post_delay = 0.1 yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 yoko_t.voltage(0) yoko_t.output('on') for pair in pairs: md.select(pair) sleep(10) yoko_t.voltage(E_field_start) yoko_t.voltage.post_delay = 7 * lockins[0].time_constant() loop = qc.Loop( yoko_t.voltage.sweep(E_field_start, E_field_stop, num=50)) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="Leak_test_MD_{}_".format(pair)) yoko_t.voltage.post_delay = 0.1 yoko_t.voltage(0) md.clear() yoko_t.output('off') ami.field.set(0)
def top_gate_step_B_field_sweep(pairs, parameters, start=-0.015, stop=0.015, points=301): global md, ami, yoko_t, lockins test_values = np.linspace(-0.6, -0.2, 30) yoko_t.voltage(0) yoko_t.output('on') yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 tau = 7 * lockins[0].time_constant() for pair in pairs: md.select(pair) for item in test_values: yoko_t.voltage(item) ami.field.set(start) sleep(600) loop = qc.Loop(ami.field.sweep(start, stop, num=points), delay=tau) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="field_sweep_MD_{}_".format(pair)) yoko_t.voltage(0) yoko_t.output('off') yoko_t.voltage(0) ami.field.set(0)
def do1d(inst_set, start, stop, num_points, delay, *inst_meas, do_plots=True, use_threads=False): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step *inst_meas: any number of instrument to measure and/or tasks to perform at each step of the sweep do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. Returns: plot, data : returns the plot and the dataset """ loop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(*inst_meas) set_params = (inst_set, start, stop), meas_params = _select_plottables(inst_meas) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) return plot, data
def sweep_awg_chans(meas_param, awg_ch_1, awg_ch_2, start, stop, step, delay=0.01, do_plots=True): """ Sweeps two awg channels at once and is otherwise the same as sweep1d Args: meas_param: parameter which we want the value of at each point awg_ch_1: one of the awg channels to vary awg_ch_2: one of the awg channels to vary start: starting value for awg channels stop: final value for awg channels step: value to step awg channels delay (default 0.01): mimimum time to spend on each point do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. Returns: data (qcodes dataset) plot: QT plot """ loop = qc.Loop(awg_ch_1.sweep(start, stop, step)).each( qc.Task(awg_ch_2.set, awg_ch_1.get), meas_param) set_params = ((awg_ch_1, start, stop, step),) meas_params = _select_plottables(meas_param) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots) return data, plot
def cooldown_loop(t, ft, resist, loops): loop = qc.Loop(t[0:loops:1]) loop = loop.each(t, ft, *resist) data = loop.get_data_set() p = printer(data) loop.with_bg_task(p) loop.run() return data
def field_sweep(ami, parameters, start, stop, points): loop = qc.Loop(ami.field.sweep(start, stop, num=points)) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) data = loop.get_data_set() loop.run() return data
def do_cavity_freq_sweep2d(cavity, localos, other_param, cavity_freq, acq_ctrl, start, stop, step, cavity_pm=10e6, freq_step=1e6, demod_freq=None, delay=0.01, do_plots=True): """ Function which sweeps the cavity frequency around central value by pm_range and measures using given acq_ctr, also steps local os to keep same demod freq. Args: cavity instrument (r&s SGS100) localos instrument (r&s SGS100) cavity_freq: central cavity drive freq acq_ctrl instrument (alazar acq controller) cavity_pm (float) (default 10e6): sweep range will be cavity_freq +- this value freq_step (float) (default 1e6) demod_freq (float) (default None): default uses the current value delay (default 0.01): mimimum time to spend on each point do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. Returns: data (qcodes dataset) plot: QT plot """ if demod_freq is None: demod_freq = get_demod_freq(cavity, localos, acq_ctrl) freq_start = cavity_freq - cavity_pm freq_stop = cavity_freq + cavity_pm loop = qc.Loop(other_param.sweep(start, stop, step)).loop( cavity.frequency.sweep(freq_start, freq_stop, freq_step), delay).each( qc.Task(localos.frequency.set, (cavity.frequency + demod_freq)), acq_ctrl.acquisition) set_params = ((other_param, start, stop), (cavity.frequency, freq_start, freq_stop)) meas_params = _select_plottables(acq_ctrl.acquisition) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots) return data, plot
def do1dDiagonal(inst_set, inst2_set, start, stop, num_points, delay, start2, slope, *inst_meas, do_plots=True, use_threads=True): """ Perform diagonal sweep in 1 dimension, given two instruments Args: inst_set: Instrument to sweep over inst2_set: Second instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step start2: Second start point slope: slope of the diagonal cut *inst_meas: any number of instrument to measure do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. Returns: plot, data : returns the plot and the dataset """ # (WilliamHPNielsen) If I understand do1dDiagonal correctly, the inst2_set # is supposed to be varied secretly in the background set_params = ((inst_set, start, stop), ) meas_params = _select_plottables(inst_meas) slope_task = qc.Task(inst2_set, (inst_set) * slope + (slope * start - start2)) loop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(slope_task, *inst_meas, inst2_set) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) return plot, data
def do1dDiagonal(inst_set, inst2_set, start, stop, num_points, delay, start2, slope, *inst_meas, do_plots=True, use_threads=False, auto_color_scale: Optional[bool]=None, cutoff_percentile: Optional[Union[Tuple[Number, Number], Number]]=None): """ Perform diagonal sweep in 1 dimension, given two instruments Args: inst_set: Instrument to sweep over inst2_set: Second instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step start2: Second start point slope: slope of the diagonal cut *inst_meas: any number of instrument to measure do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. auto_color_scale: if True, the colorscale of heatmap plots will be automatically adjusted to disregard outliers. cutoff_percentile: percentile of data that may maximally be clipped on both sides of the distribution. If given a tuple (a,b) the percentile limits will be a and 100-b. See also the plotting tuorial notebook. Returns: plot, data : returns the plot and the dataset """ # (WilliamHPNielsen) If I understand do1dDiagonal correctly, the inst2_set # is supposed to be varied secretly in the background set_params = ((inst_set, start, stop),) meas_params = _select_plottables(inst_meas) slope_task = qc.Task(inst2_set, (inst_set) * slope + (slope * start - start2)) loop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(slope_task, *inst_meas, inst2_set) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads, auto_color_scale=auto_color_scale, cutoff_percentile=cutoff_percentile) return plot, data
def test_reshape_metadata(): import qtt.measurements.scans param = qcodes.ManualParameter('dummy') try: dataset = qcodes.Loop(param[0:1:10]).each(param).run() except: dataset = None pass if dataset is not None: _ = reshape_metadata(dataset, printformat='dict') instr = qcodes.Instrument( qtt.measurements.scans.instrumentName( '_dummy_test_reshape_metadata_123')) st = qcodes.Station(instr) _ = reshape_metadata(st, printformat='dict') instr.close()
def do1d(inst_set, start, stop, num_points, delay, *inst_meas, do_plots=True, use_threads=True): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step *inst_meas: any number of instrument to measure and/or tasks to perform at each step of the sweep do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. Returns: plot, data : returns the plot and the dataset """ log.info( "Starting do1D sweeping {} from {} to {} in {} steps measuring {}". format(inst_set.name, start, stop, num_points, inst_meas)) loop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(*inst_meas) set_params = (inst_set, start, stop), meas_params = _select_plottables(inst_meas) start = time.perf_counter() plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) stop = time.perf_counter() log.info("running do1D took {:.6f} s at {:.6f} s per point".format( stop - start, (stop - start) / num_points)) return plot, data
def do1d(inst_set, start, stop, num_points, delay, *inst_meas, do_plots=True, use_threads=False, auto_color_scale: Optional[bool]=None, cutoff_percentile: Optional[Union[Tuple[Number, Number], Number]]=None): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step *inst_meas: any number of instrument to measure and/or tasks to perform at each step of the sweep do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. auto_color_scale: if True, the colorscale of heatmap plots will be automatically adjusted to disregard outliers. cutoff_percentile: percentile of data that may maximally be clipped on both sides of the distribution. If given a tuple (a,b) the percentile limits will be a and 100-b. See also the plotting tuorial notebook. Returns: plot, data : returns the plot and the dataset """ loop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(*inst_meas) set_params = (inst_set, start, stop), meas_params = _select_plottables(inst_meas) plot, data = _do_measurement(loop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads, auto_color_scale=auto_color_scale, cutoff_percentile=cutoff_percentile) return plot, data
def top_gate_step_B_field_sweep_var(pairs, parameters, le_array, E_start, E_stop, E_steps): '''with variable field limits dependent on le''' global md, ami, yoko_t, lockins test_values = np.linspace(E_start, E_stop, E_steps) yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 yoko_t.voltage(0) yoko_t.output('on') tau = 7 * lockins[0].time_constant() for pair in pairs: md.select(pair) for item in test_values: yoko_t.voltage(item) h_bar = 1.0545718e-34 e = 1.60217662e-19 poly = np.poly1d(le_array) l_e = poly(item) B_e = np.abs(h_bar / (4 * e * l_e**2)) print(B_e) if B_e > 0.010: B_e = 0.010 start = B_e + 0.005 stop = -1 * start points = int(round((start - stop) / 0.00005)) print(points) ami.field.set(start) sleep(60) loop = qc.Loop(ami.field.sweep(start, stop, num=points), delay=tau) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="field_sweep_MD_{}_".format(pair)) yoko_t.voltage(0) yoko_t.output('off') yoko_t.voltage(0) ami.field.set(0)
def inverse_B_field_sweep(md, pairs, parameters): global ami, yoko_t, lockins start_field = 1.2 stop_field = 2.0 step_num = 200 steps = np.linspace(1 / start_field, 1 / stop_field, step_num) field_vals = np.array([1 / steps]) tg_values = [-0.4, -0.2, -0.15, -0.1, -0.05, 0] # get n_e at these exact biases - fit? yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 yoko_t.voltage(0) yoko_t.output('on') for pair in pairs: md.select(pair) tau = 7 * lockins[0].time_constant() for item in tg_values: yoko_t.voltage(item) ami.field.set(start_field) sleep(300) loop = qc.Loop(ami.field[field_vals], delay=tau) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run() yoko_t.voltage(0) md.clear() yoko_t.output('off') ami.field.set(0)
def lockin_IV(pairs, parameters, start=-100, stop=100): global md, ami, yoko_t, lockins resistance_value = 1.0e+7 # eries resistor Ohms excitation = 1.0 # nA points = int((np.abs(start) + np.abs(stop) + 1) / excitation) I_range = np.linspace(start, stop, points) # nA print(points) lockins[0].amplitude.set(resistance_value * excitation * 1.e-9) tau = 7 * lockins[0].time_constant() DC_out = (resistance_value * I_range * 1.e-9) for pair in pairs: md.select(pair) sleep(10) loop = qc.Loop(lockins[0].sine_outdc[DC_out], delay=tau) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="IV_MD_{}_".format(pair)) md.clear()
def top_gate_step_B_field_sweep_var(pairs, parameters, le_array, E_start, E_stop, E_steps): '''with variable field limits dependent on le WITH YOKO MAGNET POWER SUPPLY''' global md, yoko_mag, yoko_t, lockins test_values = np.linspace(E_start, E_stop, E_steps) yoko_t.voltage.step = 0.01 yoko_t.voltage.inter_delay = 0.1 yoko_t.voltage(0) yoko_t.output('on') tau = 7 * lockins[0].time_constant() for pair in pairs: md.select(pair) yoko_t.voltage(test_values[0]) sleep(60 * 5) for item in test_values: h_bar = 1.0545718e-34 e = 1.60217662e-19 poly = np.poly1d(le_array) l_e = poly(item) print(l_e) B_e = np.abs(h_bar / (4 * e * l_e**2)) print(B_e) if B_e > 0.010: B_e = 0.010 if B_e < 0.001: B_e = 0.001 step_f = 0.000005 step_c = 0.0001 coarse_range = B_e + 0.001 fine_range = 0.0015 # Round coarse_range to the smaller multiple of step_c coarse_range = int(coarse_range / step_c) * step_c # Convert from tesla to A coarse_range = coarse_range * (1 / 0.0641) fine_range = fine_range * (1 / 0.0641) step_f = step_f * (1 / 0.0641) step_c = step_c * (1 / 0.0641) # Create Segments seg1 = yoko_mag.current.sweep(coarse_range, fine_range, step=step_c) seg2 = yoko_mag.current.sweep(fine_range, -fine_range, step=step_f) seg3 = yoko_mag.current.sweep(-fine_range, -coarse_range, step=step_c) yoko_t.voltage(item) yoko_mag.current.set(coarse_range) sleep(20) loop = qc.Loop(seg1 + seg2 + seg3, delay=tau) if isinstance(parameters, Iterable): loop = loop.each(*parameters) else: loop = loop.each(parameters) loop.run(name="field_sweep_MD_{}_".format(pair)) yoko_t.voltage(0) yoko_t.output('off') yoko_t.voltage(0) yoko_mag.current.set(0)
def do2d(inst_set, start, stop, num_points, delay, inst_set2, start2, stop2, num_points2, delay2, *inst_meas, do_plots=True, use_threads=False, set_before_sweep: Optional[bool]=False, innerloop_repetitions: Optional[int]=1, innerloop_pre_tasks: Optional[Sequence]=None, innerloop_post_tasks: Optional[Sequence]=None): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step inst_set2: Second instrument to sweep over start2: Start of sweep for second instrument stop2: End of sweep for second instrument num_points2: Number of steps to perform delay2: Delay at every step for second instrument *inst_meas: do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. set_before_sweep: if True the outer parameter is set to its first value before the inner parameter is swept to its next value. innerloop_pre_tasks: Tasks to execute before each iteration of the outer loop innerloop_post_tasks: Tasks to execute after each iteration of the outer loop Returns: plot, data : returns the plot and the dataset """ for inst in inst_meas: if getattr(inst, "setpoints", False): setpoints = inst.setpoints if isinstance(setpoints, Iterable): if all(len(v) == 0 for v in setpoints): continue raise ValueError("3d plotting is not supported") actions = [] for i_rep in range(innerloop_repetitions): innerloop = qc.Loop(inst_set2.sweep(start2, stop2, num=num_points2), delay2).each(*inst_meas) if set_before_sweep: ateach = [innerloop, Task(inst_set2, start2)] else: ateach = [innerloop] if innerloop_pre_tasks is not None: ateach = list(innerloop_pre_tasks) + ateach if innerloop_post_tasks is not None: ateach = ateach + list(innerloop_post_tasks) actions += ateach outerloop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(*actions) set_params = ((inst_set, start, stop), (inst_set2, start2, stop2)) meas_params = _select_plottables(inst_meas) plot, data = _do_measurement(outerloop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) return plot, data
def do2d(inst_set, start, stop, num_points, delay, inst_set2, start2, stop2, num_points2, delay2, *inst_meas, do_plots=True, use_threads=True): """ Args: inst_set: Instrument to sweep over start: Start of sweep stop: End of sweep num_points: Number of steps to perform delay: Delay at every step inst_set2: Second instrument to sweep over start2: Start of sweep for second instrument stop2: End of sweep for second instrument num_points2: Number of steps to perform delay2: Delay at every step for second instrument *inst_meas: do_plots: Default True: If False no plots are produced. Data is still saved and can be displayed with show_num. use_threads: If True and if multiple things are being measured, multiple threads will be used to parallelise the waiting. Returns: plot, data : returns the plot and the dataset """ log.info("Starting do2D sweeping {} from {} to {} in {} steps and" " {} from {} to {} in {} steps " "measuring {}".format(inst_set.name, start, stop, num_points, inst_set2.name, start2, stop2, num_points2, inst_meas)) for inst in inst_meas: if getattr(inst, "setpoints", False): raise ValueError("3d plotting is not supported") innerloop = qc.Loop(inst_set2.sweep(start2, stop2, num=num_points2), delay2).each(*inst_meas) outerloop = qc.Loop(inst_set.sweep(start, stop, num=num_points), delay).each(innerloop) set_params = ((inst_set, start, stop), (inst_set2, start2, stop2)) meas_params = _select_plottables(inst_meas) start = time.perf_counter() plot, data = _do_measurement(outerloop, set_params, meas_params, do_plots=do_plots, use_threads=use_threads) stop = time.perf_counter() log.info( "running do2D took {:.6f} s at {:.6f} s per line and {:.6f} s per point" .format(stop - start, (stop - start) / num_points, (stop - start) / (num_points * num_points2))) return plot, data
def single_param_sweep(SetParam, SetArray, delay, *MeasParams, DataName='', XParam=None, YParam=None, plot_results=True, save_plots=True): """ Single parameter sweep, single measure (for more measurements, add parameters to the .each() part). Includes live plot. Returns: data (a qcodes DataSet object), plot Arguments: SetParam: The parameter to sweep (such as a voltage) SetArray: should be a list or numpy array of values you want to set SetParam to. delay: The delay time between when SetParam is set till the MeasParams are measured (0 by default). *MeasParam: The comma-separated parameters you want to measure at each setpoint Keyword Arguments: DataName: A name to tag the data (defaults to nothing) XParam: Optional, the x parameter to be used in plotting (if not used, will default to the set parameter for every plot). Must be either a list that is the same length as YParam, a single parameter, or None. YParam: Allows you to pick only a few parameters to plot out of those measured. (if not mentioned, will plot all *MeasParams) plot_results: True by default, if false, suppresses plotting save_plots: True by default. If false, doesn't save plots at the end of the sweep """ loop = qc.Loop(SetParam[SetArray], delay=delay).each(*MeasParams) data = loop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for i in range(len(plot)): fname = '{}_{}.png'.format( plot[i].get_default_title(), str(XParam[i]) + 'vs' + str(YParam[i])) plot[i].save(filename=fname) else: fname = '{}_{}.png'.format(plot.get_default_title(), str(XParam) + 'vs' + str(*MeasParams)) plot.save(filename=fname) if plot_results: if XParam is None: XParam = SetParam if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(XParam) + '_set'), getattr(data, str(*MeasParams)), window_title=str(XParam) + ' vs. ' + str(*MeasParams)) loop.with_bg_task(plot.update) else: if YParam is None: YParam = MeasParams if type(XParam) is not list and type(XParam) is not tuple: if type(YParam) is not list and type(YParam) is not tuple: XParam = [XParam] YParam = [YParam] else: XParam = [XParam] * len(MeasParams) elif len(XParam) != len(YParam): raise ValueError('length of XParam list must be the same as' + 'length of YParam list') # Create a str for XParam so we can account for _set in the str XParamStr = [] for i in range(len(XParam)): xpi = str(XParam[i]) if xpi == str(SetParam): XParamStr.append(xpi + '_set') else: XParamStr.append(xpi) for i in range(len(YParam)): title = str(YParam[i]) + ' vs. ' + str(XParam[i]) plot.append( qc.QtPlot(getattr(data, XParamStr[i]), getattr(data, str(YParam[i])), window_title=title)) loop.with_bg_task(_plot_update) try: loop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot
def data_log(delay, *MeasParams, N=None, minutes=None, DataName='', XParam=None, YParam=None, breakif=None, plot_results=True, save_plots=True): """A loop that takes measurements every "delay" seconds (starts measuring at startup, and each delay comes after the measurement). Either choose to measure N times or for minutes. The arrays of the data are: count_set (the number of the data point), time0 (the time since the start), *MeasParams (comma-separated collection of parameters (instr.param) measured at each point) Note that the amount of minutes may be slightly larger than min because this assumes the time of measurement for the parameters is 0. Returns: data (a DataSet object), plot (a plot or a list of plots if MeasParams has more than one parameter) Arguments: delay: Seconds between each measurement *MeasParams: a comma-separated collection of parameters to measure Keyword Arguments: N: The number of data points to take (if left None, need to use minutes) minutes: The number of minutes to take data points (if left as None, need to use N). If minutes/delay is not an integer, rounds up DataName: the name to be placed on the file (defaults to '') XParam: an optional specification of the x-axis parameter to plot (defaults to time0 for all plots). If you want different x-axes for different plots, use a list. To include time0 in that list, use the string 'time' or 'time0'. The list must be the same length as YParam or MeasParams YParam: optional specification of y-axis parameters to plot (if not specified, it will create one plot per MeasParam). breakif: specify a parameterless function that returns true when the break condition is met (example ppms temperature < 2.01) plot_results: if you want to do the data log without plots, set this to False save_plots: True by default. If false, doesn't save plots at the end of the sweep """ if breakif is None: def breakif(): pass count = qc.ManualParameter('count') time0 = time_from_start('time0') if N is None and minutes is None: return ValueError('Must have either N or minutes arguments') elif N is not None and minutes is not None: return ValueError('Only use N or minutes arguments') elif N is not None and minutes is None: loop = qc.Loop(count.sweep(1, int(N), step=1)).each(time0, *MeasParams, qc.Wait(delay), qc.BreakIf(breakif)) elif minutes is not None and N is None: N = ceil(minutes * 60 / delay) loop = qc.Loop(count.sweep(1, int(N), step=1)).each(time0, *MeasParams, qc.Wait(delay), qc.BreakIf(breakif)) data = loop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for p in plot: p.save() else: plot.save() if plot_results: if XParam is None: XParam = time0 if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(XParam)), getattr(data, str(*MeasParams)), window_title=str(XParam) + ' vs. ' + str(*MeasParams)) loop.with_bg_task(plot.update) else: if YParam is None: YParam = MeasParams if type(XParam) is not list and type(XParam) is not tuple: if type(YParam) is not list and type(YParam) is not tuple: XParam = [XParam] YParam = [YParam] else: XParam = [XParam] * len(MeasParams) elif len(XParam) != len(YParam): raise ValueError('length of XParam list must be the same as' + 'length of YParam list') for i in range(len(XParam)): if type(XParam[i]) is str: if XParam[i] == 'time' or XParam[i] == 'time0': XParam[i] = time0 # plot = [] for i in range(len(YParam)): title = str(YParam[i]) + ' vs. ' + str(XParam[i]) plot.append( qc.QtPlot(getattr(data, str(XParam[i])), getattr(data, str(YParam[i])), window_title=title)) # def _plot_update(): # for p in plot: # p.update() # # def _plot_save(): # for p in plot: # p.save() loop.with_bg_task(_plot_update) try: time0.reset() loop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot
def twod_param_sweep(SetParam1, SetArray1, SetParam2, SetArray2, *MeasParams, SetDelay1=0, SetDelay2=0, Param2_SetBetween=None, DataName='', ZParam=None, plot_results=True, save_plots=True): """ Single parameter sweep, single measure (for more measurements, add parameters to the .each() part). Includes live plot. Note: if the SetParam1 array is nonuniform, the y axis of the plot will be messed up. Try MatPlot instead of QtPlot in that situation. Returns: data (a qcodes DataSet object), plot Arguments: SetParam1: The outer parameter to sweep (such as a temperature) SetArray1: should be a list or numpy array of values you want to set SetParam1 to. This array will be run through once SetParam2: The inner parameter to sweep (such as a voltage) Param2_SetBetween: Sets parameter 2 to this value at the end of each sweep of the parameter (completion of one row) and before changing parameter 1. SetArray1: should be a list or numpy array of values you want to set SetParam2 to. This array will be run through for each value of SetArray1 MeasParams: The parameter(s) you want to measure at each setpoint Keyword Arguments: SetDelay1: The delay time between when SetParam1 is set till the SetParam2 is set to its first value (0 by default) SetDelay2: Delay time between when SetParam2 is set and the MeasParam is measured (0 by default) DataName: A name to tag the data (defaults to nothing) ZParam: Allows you to pick only a few parameters to plot out of those measured. (if not mentioned, will plot all *MeasParams) plot_results: True by default, if false, suppresses plotting save_plots: True by default. If false, doesn't save plots at the end of the sweep """ if Param2_SetBetween is None: def between_func(): pass else: def between_func(): SetParam2(Param2_SetBetween) return innerloop = qc.Loop(SetParam2[SetArray2], delay=SetDelay2).each(*MeasParams) twodloop = qc.Loop(SetParam1[SetArray1], delay=SetDelay1).each(innerloop, qc.Task(between_func)) data = twodloop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for i in range(len(plot)): fname = '{}_{}.png'.format(plot[i].get_default_title(), str(ZParam[i])) plot[i].save(filename=fname) else: fname = '{}_{}.png'.format(plot.get_default_title(), str(*MeasParams)) plot.save(filename=fname) if plot_results: if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(*MeasParams)), window_title=str(*MeasParams)) twodloop.with_bg_task(plot.update) else: if ZParam is None: ZParam = MeasParams if type(ZParam) is not list and type(ZParam) is not tuple: ZParam = [ZParam] for zp in ZParam: plot.append( qc.QtPlot(getattr(data, str(zp)), window_title=str(zp))) twodloop.with_bg_task(_plot_update) try: twodloop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot