def eval(self, rdb): db_entry = rdb.query_results_one(branch=self.branch, date=self.date, commit=self.commit) dtu.dt_check_isinstance("db_entry", db_entry, ResultDBEntry) # print('Results= %s' % db_entry.__repr__()) results = db_entry.results dtu.check_is_in("analyzer", self.analyzer, results, EvaluationError) logs = results[self.analyzer] dtu.check_is_in("log", self.log, logs, EvaluationError) forlog = logs[self.log] val = eval_name(forlog, self.statistic) return val
def interpret_instance_spec(filename, data): dtu.dt_check_isinstance("data", data, dict) basename = os.path.basename(filename) instance_name = dtu.id_from_basename_pattern( basename, c.instances_pattern) if c.default_constructor is not None and not "constructor" in data: description = "(not given)" constructor = c.default_constructor parameters = dict(data) else: description = data.pop("description") dtu.dt_check_isinstance("description", description, str) constructor = data.pop("constructor") dtu.dt_check_isinstance("constructor", constructor, str) parameters = data.pop("parameters") dtu.dt_check_isinstance("parameters", parameters, (dict, NoneType)) if parameters is None: parameters = {} return EasyAlgoInstance( family_name=c.family_name, instance_name=instance_name, description=description, filename=filename, constructor=constructor, parameters=parameters, valid=True, error_if_invalid=None, )
def _parse_inline_spec(x: dict) -> Tuple[str, SpecValues]: dtu.check_isinstance(x, dict) if len(x) != 1: msg = f"Invalid spec: length is {len(x)}" dtu.raise_desc(ValueError, msg, x=x) key = list(x)[0] value = x[key] value = copy.deepcopy(value) if "description" in value: description = value.pop("description") dtu.dt_check_isinstance("description", description, str) else: description = None constructor = value.pop("constructor") dtu.dt_check_isinstance("constructor", constructor, str) parameters = value.pop("parameters") dtu.dt_check_isinstance("parameters", parameters, (dict, type(None))) if parameters is None: parameters = {} res = SpecValues(constructor=constructor, parameters=parameters, description=description) return key, res
def interpret_easy_algo_config(filename: str, data: dict) -> EasyAlgoFamily: """ Interprets the family config """ basename = os.path.basename(filename) family_name = dtu.id_from_basename_pattern(basename, EasyAlgoDB.pattern) instances_pattern = f"*.{family_name}.yaml" # tests_pattern = '*.%s_test.yaml' % family_name data0 = dict(data) try: dtu.dt_check_isinstance("contents", data, dict) description = data.pop("description") dtu.dt_check_isinstance("description", description, str) interface = data.pop("interface") dtu.dt_check_isinstance("interface", interface, str) locations = data.pop("locations", None) default_constructor = data.pop("default_constructor", None) except Exception as e: msg = f"Cannot interpret data: \n\n{data0}" raise Exception(msg) from e if data: msg = f'Extra keys in configuration: {list(data)}' raise dtu.DTConfigException(msg) return EasyAlgoFamily( interface=interface, family_name=family_name, filename=filename, instances=None, instances_pattern=instances_pattern, description=description, valid=True, locations=locations, default_constructor=default_constructor, error_if_invalid=False, )