def consolidate_experiments_with_options(exp_dict, sim_dict, batch_name=None): # if batch name exists, always save experiments if batch_name is None: return exp_dict, sim_dict batch = DataStore.get_batch_by_name(batch_name) if batch: batch_exp_id_list = batch.get_experiment_ids() batch_sim_id_list = batch.get_simulation_ids() exp_diff = not compare_two_ids_list(exp_dict.keys(), batch_exp_id_list) sim_diff = not compare_two_ids_list(sim_dict.keys(), batch_sim_id_list) if exp_diff or sim_diff: # confirm only if existing batch contains different experiments print("\nBatch with name {} already exists and contains the following:\n".format(batch_name)) print(batch) if exp_dict or sim_dict: var = input('\nDo you want to [O]verwrite, [M]erge, or [C]ancel: ') # print("You selected '%s'" % var) if var == 'O': # clear existing experiments associated with this Batch DataStore.clear_batch(batch) return exp_dict, sim_dict elif var == 'M': return exp_dict, sim_dict elif var == 'C': exit() else: logger.error("Option '%s' is invalid..." % var) exit() return exp_dict, sim_dict
def retrieve_item(itemid): """ Return the object identified by id. Can be an experiment, a suite or a batch. If it is a suite, all experiments with this suite_id will be returned. """ # First try to get an experiment from simtools.Utilities.Experiments import retrieve_experiment from simtools.DataAccess.DataStore import DataStore from simtools.Utilities.COMPSUtilities import exps_for_suite_id from simtools.Utilities.Experiments import retrieve_simulation # Try experiments first try: return retrieve_experiment(itemid) except: pass # This was not an experiment, maybe a batch ? batch = DataStore.get_batch_by_id(itemid) if batch: return batch batch = DataStore.get_batch_by_name(itemid) if batch: return batch # Still no item found -> test the suites exps = DataStore.get_experiments_by_suite(itemid) if exps: return exps # Still no item found -> test the simulations sim = DataStore.get_simulation(itemid) if sim: return sim # Still not -> last chance is a COMPS suite exps = exps_for_suite_id(itemid) if exps: return [retrieve_experiment(str(exp.id)) for exp in exps] # Nothing, consider COMPS simulation try: return retrieve_simulation(itemid) except: pass # Didnt find anything sorry raise (Exception('Could not find any item corresponding to %s' % itemid))
def save_batch(batch_name=None, exp_list=None, sim_list=None): # Try to get the batch based on name if provided batch = DataStore.get_batch_by_name(batch_name) if batch_name else None # No batches were found, need to create a new one if not batch: batch = Batch() batch.name = batch_name # add experiments batch.experiments.extend(exp_list) # add simulations batch.simulations.extend(sim_list) # Save DataStore.save_batch(batch) logger.info('\nBatch: %s (id=%s) saved!' % (batch.name, batch.id)) return batch