def parameters(self) -> str: if self.pristine: psnames = [ps.name for ps in self.description.interdeps.paramspecs] return ','.join(psnames) else: return select_one_where(self.conn, "runs", "parameters", "run_id", self.run_id)
def completed(conn: ConnectionPlus, run_id) -> bool: """ Check if the run scomplete Args: conn: database connection run_id: id of the run to check """ return bool( select_one_where(conn, "runs", "is_completed", "run_id", run_id))
def get_guid_from_run_id(conn: ConnectionPlus, run_id: int) -> str: """ Get the guid of the given run Args: conn: database connection run_id: id of the run """ return select_one_where(conn, "runs", "guid", "run_id", run_id)
def get_run_counter(conn: ConnectionPlus, exp_id: int) -> int: """ Get the experiment run counter Args: conn: the connection to the sqlite database exp_id: experiment identifier Returns: the exepriment run counter """ return select_one_where(conn, "experiments", "run_counter", where_column="exp_id", where_value=exp_id)
def get_completed_timestamp_from_run_id(conn: ConnectionPlus, run_id: int) -> float: """ Retrieve the timestamp when the given measurement run was completed If the measurement run has not been marked as completed, then the returned value is None. Args: conn: database connection run_id: id of the run Returns: timestamp in seconds since the Epoch, or None """ return select_one_where(conn, "runs", "completed_timestamp", "run_id", run_id)
def fix_wrong_run_descriptions(conn: ConnectionPlus, run_ids: Sequence[int]) -> None: """ NB: This is a FIX function. Do not use it unless your database has been diagnosed with the problem that this function fixes. Overwrite faulty run_descriptions by using information from the layouts and dependencies tables. If a correct description is found for a run, that run is left untouched. Args: conn: The connection to the database run_ids: The runs to (potentially) fix """ user_version = get_user_version(conn) if not user_version == 3: raise RuntimeError('Database of wrong version. Will not apply fix. ' 'Expected version 3, found version {user_version}') log.info('[*] Fixing run descriptions...') for run_id in run_ids: trusted_paramspecs = _get_parameters(conn, run_id) trusted_desc = v0.RunDescriber( v0.InterDependencies(*trusted_paramspecs)) actual_desc_str = select_one_where(conn, "runs", "run_description", "run_id", run_id) trusted_json = serial.to_json_as_version(trusted_desc, 0) if actual_desc_str == trusted_json: log.info(f'[+] Run id: {run_id} had an OK description') else: log.info(f'[-] Run id: {run_id} had a broken description. ' f'Description found: {actual_desc_str}') update_run_description(conn, run_id, trusted_json) log.info(f' Run id: {run_id} has been updated.')
def counter(self): return select_one_where(self.conn, "runs", "result_counter", "run_id", self.run_id)
def snapshot_raw(self) -> Optional[str]: """Snapshot of the run as a JSON-formatted string (or None)""" return select_one_where(self.conn, "runs", "snapshot", "run_id", self.run_id)
def table_name(self): return select_one_where(self.conn, "runs", "result_table_name", "run_id", self.run_id)
def name(self): return select_one_where(self.conn, "runs", "name", "run_id", self.run_id)
def started_at(self) -> int: return select_one_where(self.conn, "experiments", "start_time", "exp_id", self.exp_id)
def format_string(self) -> str: return select_one_where(self.conn, "experiments", "format_string", "exp_id", self.exp_id)
def finished_at(self) -> int: return select_one_where(self.conn, "experiments", "end_time", "exp_id", self.exp_id)
def format_string(self) -> str: format_str = select_one_where(self.conn, "experiments", "format_string", "exp_id", self.exp_id) assert isinstance(format_str, str) return format_str
def finished_at(self) -> Optional[float]: finish_time = select_one_where(self.conn, "experiments", "end_time", "exp_id", self.exp_id) assert isinstance(finish_time, (float, type(None))) return finish_time
def captured_counter(self): return select_one_where(self.conn, "runs", "captured_counter", "run_id", self.run_id)
def get_run_timestamp_from_run_id(conn: ConnectionPlus, run_id: int) -> Optional[float]: return select_one_where(conn, "runs", "run_timestamp", "run_id", run_id)
def get_sample_name_from_experiment_id(conn: ConnectionPlus, exp_id: int) -> str: return select_one_where(conn, "experiments", "sample_name", "exp_id", exp_id)
def get_metadata(conn: ConnectionPlus, tag: str, table_name: str): """ Get metadata under the tag from table """ return select_one_where(conn, "runs", tag, "result_table_name", table_name)
def get_run_description(conn: ConnectionPlus, run_id: int) -> str: """ Return the (JSON string) run description of the specified run """ return select_one_where(conn, "runs", "run_description", "run_id", run_id)
def exp_id(self) -> int: return select_one_where(self.conn, "runs", "exp_id", "run_id", self.run_id)
def started_at(self) -> float: start_time = select_one_where(self.conn, "experiments", "start_time", "exp_id", self.exp_id) assert isinstance(start_time, float) return start_time