def save_yaml(self): """ Save a copy of current experiment settings """ head = os.path.dirname(self.filename.value) fulldir = os.path.splitext(self.filename.value)[0] if not os.path.exists(fulldir): os.makedirs(fulldir) config.yaml_dump(config.yaml_load(config.configFile), os.path.join(fulldir, os.path.split(config.configFile)[1]), flatten = True)
def run_sweeps(self): #For now, only update histograms if we don't have a parameter sweep. if not self.sweeper.axes: self.init_plots() self.add_manual_plotter(self.re_plot) self.add_manual_plotter(self.im_plot) else: if any([ x.save_kernel.value for x in self.filters.values() if type(x) is SingleShotMeasurement ]): logger.warning( "Kernel saving is not supported if you have parameter sweeps!" ) super(SingleShotFidelityExperiment, self).run_sweeps() if not self.sweeper.axes: self._update_histogram_plots() if hasattr(self, 'extra_plot_server'): try: self.extra_plot_server.stop() except: pass if self.sweeper.axes and self.optimize: #select the buffers/writers whose sources are singleshot filters fid_buffers = [ buff for buff in self.buffers if self.settings['filters'][ buff.name]['source'].strip().split()[1] == 'fidelity' ] if not fid_buffers: raise NameError( "Please connect a buffer to the single-shot filter output in order to optimize fidelity." ) #set sweep parameters to the values that maximize fidelity. Then update the saved_settings with the new values for buff in fid_buffers: dataset, descriptor = buff.get_data(), buff.get_descriptor() opt_ind = np.argmax(dataset['Data']) for k, axis in enumerate(self.sweeper.axes): instr_tree = axis.parameter.instr_tree param_key = self.saved_settings['instruments'] for key in instr_tree[:-1]: # go through the tree param_key = param_key[key] opt_value = float(dataset[axis.name][opt_ind]) # special case to set APS ch12 amplitudes if instr_tree[-1] == 'amplitude' and instr_tree[ -2] in self.saved_settings['instruments'].keys(): param_key['tx_channels']['12']['1'][ 'amplitude'] = round(float(opt_value), 5) param_key['tx_channels']['12']['2'][ 'amplitude'] = round(float(opt_value), 5) else: param_key[instr_tree[-1]] = opt_value logger.info("Set{} to {}.".format( " ".join(str(x) for x in instr_tree), opt_value)) config.yaml_dump(self.saved_settings, config.configFile)
def write_to_file(self): awg_settings = self.settings['instruments'][self.AWG] awg_settings['tx_channels'][self.chan]['amp_factor'] = round(self.amplitude_factor.value, 5) awg_settings['tx_channels'][self.chan]['phase_skew'] = round(self.phase_skew.value, 5) awg_settings['tx_channels'][self.chan][self.chan[0]]['offset'] = round(self.I_offset.value, 5) awg_settings['tx_channels'][self.chan][self.chan[1]]['offset'] = round(self.Q_offset.value, 5) self.settings['instruments'][self.AWG] = awg_settings config.yaml_dump(self.settings, config.configFile) logger.info("Mixer calibration for {}-{} written to experiment file.".format(self.AWG, self.chan))
def test_writehdf5_with_settings(self): exp = SweptTestExperiment() clear_test_data() wr = WriteToHDF5("test_writehdf5.h5", save_settings=True) edges = [(exp.voltage, wr.sink)] exp.set_graph(edges) exp.add_sweep(exp.field, np.linspace(0, 100.0, 4)) exp.add_sweep(exp.freq, np.linspace(0, 10.0, 3)) exp.run_sweeps() self.assertTrue(os.path.exists("test_writehdf5-0000.h5")) with h5py.File("test_writehdf5-0000.h5", 'r') as f: self.assertTrue(0.0 not in f['main/data/voltage']) self.assertTrue( np.sum(f['main/data/field']) == 5 * 3 * np.sum(np.linspace(0, 100.0, 4))) self.assertTrue( np.sum(f['main/data/freq']) == 5 * 4 * np.sum(np.linspace(0, 10.0, 3))) self.assertTrue( np.sum(f['main/data/samples']) == 3 * 4 * np.sum(np.linspace(0, 4, 5))) self.assertTrue( "Here the run loop merely spews" in f.attrs['exp_src']) self.assertTrue(f['main/data'].attrs['time_val'] == 0) self.assertTrue(f['main/data'].attrs['unit_freq'] == "Hz") self.assertTrue(f['header'].attrs['settings'] == yaml_dump( yaml_load(configFile), flatten=True)) os.remove("test_writehdf5-0000.h5")
def save_yaml_h5(self): """ Save a copy of current experiment settings in the h5 metadata""" header = self.file.create_group("header") # load them dump to get the 'include' information header.attrs['settings'] = config.yaml_dump(config.yaml_load(config.configFile), flatten = True)