Source code for qcodes.dataset.experiment_settings
"""Settings that are indirectly related to experiments."""from__future__importannotationsfromqcodes.dataset.sqlite.connectionimportConnectionPlus,path_to_dbfilefromqcodes.dataset.sqlite.queriesimportget_last_experiment_default_experiment:dict[str,int|None]={}def_set_default_experiment_id(db_path:str,exp_id:int)->None:""" Sets the default experiment with the exp_id of a created/ loaded experiment for the database that this experiment belongs to. Args: db_path: The database that a created/ loaded experiment belongs to. exp_id: The exp_id of a created/ loaded experiment. """global_default_experiment_default_experiment[db_path]=exp_iddef_get_latest_default_experiment_id(db_path:str)->int|None:""" Gets the latest created or loaded experiment's exp_id. If no experiment is set None will be returned. Args: db_path: Database path. Returns: The latest created/ loaded experiment's exp_id. """global_default_experimentreturn_default_experiment.get(db_path,None)
[docs]defreset_default_experiment_id(conn:ConnectionPlus|None=None)->None:""" Resets the default experiment id to to the last experiment in the db. """global_default_experimentifconnisNone:_default_experiment={}else:db_path=path_to_dbfile(conn)_default_experiment[db_path]=None
[docs]defget_default_experiment_id(conn:ConnectionPlus)->int:""" Returns the latest created/ loaded experiment's exp_id as the default experiment. If it is not set the maximum exp_id returned as the default. If no experiment is found in the database, a ValueError is raised. Args: conn: Open connection to the db in question. Returns: exp_id of the default experiment. Raises: ValueError: If no experiment exists in the given db. """db_path=path_to_dbfile(conn)exp_id=_get_latest_default_experiment_id(db_path)ifexp_idisNone:exp_id=get_last_experiment(conn)ifexp_idisNone:raiseValueError("No experiments found."" You can create one with:"" new_experiment(name, sample_name)")returnexp_id