def list_experiments( db_folder: Optional[str] = None, ) -> Tuple[str, Dict[str, List[int]]]: """""" if db_folder is None: db_folder = nt.config["db_folder"] # print(os.listdir(db_folder)) # print(db_folder) # db_files = glob.glob(db_folder + '*.db') # db_files = glob.glob(db_folder) all_fls = os.listdir(db_folder) db_files = [db_file for db_file in all_fls if db_file.endswith(".db")] print("db_files: {}".format(db_files)) db_names = [ntpath.basename(path) for path in db_files] all_experiments = {} for idb, db_file in enumerate(db_files): qc.config["core"]["db_location"] = os.path.join(db_folder, db_file) exp_ids = [] exps = experiments() for exprmt in exps: exp_ids.append(exprmt.exp_id) all_experiments[db_names[idb]] = exp_ids return db_folder, all_experiments
def get_runs_from_db( path: str, start: int = 0, stop: Union[None, int] = None, get_structure: bool = False) -> Dict[int, DataSetInfoDict]: """ Get a db ``overview`` dictionary from the db located in ``path``. The ``overview`` dictionary maps ``DataSet.run_id``s to dataset information as returned by ``get_ds_info`` functions. `start` and `stop` refer to indices of the runs in the db that we want to have details on; if `stop` is None, we'll use runs until the end. If `get_structure` is True, include info on the run data structure in the return dict. """ initialise_or_create_database_at(path) datasets = sorted(chain.from_iterable(exp.data_sets() for exp in experiments()), key=attrgetter('run_id')) # There is no need for checking whether ``stop`` is ``None`` because if # it is the following is simply equivalent to ``datasets[start:]`` datasets = datasets[start:stop] overview = { ds.run_id: get_ds_info(ds, get_structure=get_structure) for ds in datasets } return overview
def test_load_or_create_experiment_creating_not_empty(): """Test that an experiment is correctly created when DB is not empty""" exp = load_or_create_experiment("experiment_name_1", "sample_name_1") exp_2 = load_or_create_experiment("experiment_name_2", "sample_name_2") actual_experiments = experiments() assert len(actual_experiments) == 2 assert_experiments_equal(actual_experiments[0], exp) assert_experiments_equal(actual_experiments[1], exp_2)
def test_load_or_create_experiment_different_sample_name(): """ Test that an experiment is created for the case when the experiment name is the same, but the sample name is different """ exp = new_experiment("experiment_name", "sample_name_1") exp_2 = load_or_create_experiment("experiment_name", "sample_name_2") actual_experiments = experiments() assert len(actual_experiments) == 2 assert exp.name == exp_2.name assert exp.sample_name != exp_2.sample_name
def get_last_dataid( db_name: str, db_folder: Optional[str] = None, ) -> int: """ Return last 'global' dataid for given database. It is this ID that is used in plot_by_id """ if db_folder is None: db_folder = nt.config["db_folder"] if db_name[-2:] != "db": db_name += ".db" nt.set_database(db_name, db_folder=db_folder) last_index = 0 for experiment in experiments(): last_index += experiment.last_counter return last_index
def load_database(self): def check_existing_ds(ds): for old_ds in self.datasets: if str(ds['run id']) == str(old_ds['run id']) and str(ds['exp name']) == str(old_ds['exp name']) \ and str(ds['sample name']) == str(old_ds['sample name']) and str(ds['db']) == str(old_ds['db']): return False return True gui = SaveDataGUI(self) if gui.exec_(): (db, exp_name, sample_name) = gui.get_save_info() initialise_or_create_database_at(db) exps = experiments() new_datasets = 0 for exp in exps: for ds in exp.data_sets(): if len(exp_name) == 0 or ds.exp_name == exp_name: if len(sample_name ) == 0 or ds.sample_name == sample_name: new_ds = {} new_ds['run id'] = ds.run_id new_ds['exp name'] = ds.exp_name new_ds['sample name'] = ds.sample_name new_ds['db'] = ds.path_to_db if check_existing_ds(new_ds) is True: self.datasets.append(new_ds) new_datasets += 1 self.update_datasets() if new_datasets == 0: self.show_error( 'Error', 'No (new) data sets found with the specified experiment and sample name!' )
from qcodes import load_experiment from qcodes.dataset.data_set import load_by_id from plotting_functions import * print(qc.__version__) # qc.initialise_or_create_database_at('./2019-07-08-frays-final.db') configuration = qc.config print(f'Using config file from {configuration.current_config_path}') configuration['core']['db_location'] = '../2019-07-08-frays-Copy1.db' print(f'Database location: {configuration["core"]["db_location"]}') qc.initialise_database() # qc.initialise_or_create_database_at('../2019-07-08-frays-Copy1.db') # print(f'Database location: {configuration["core"]["db_location"]}') experimentsList = [exp.name for exp in exc.experiments()] lastSet = (qc.load_last_experiment()).last_data_set() types = [{ 'label': 'Counting', 'value': 'counting' }, { 'label': 'ODMR', 'value': 'odmr' }, { 'label': 'Pulsed ODMR', 'value': 'pulsedodmr' }, { 'label': 'Rabi', 'value': 'rabi' }, { 'label': 'Ramsey',