def get_oneline_result_string(record, truncate_to=None, array_float_format='.3g', array_print_threshold=8): """ Get a string that describes the result of the record in one line. This can optionally be specified by experiment.one_liner_function. :param record: An ExperimentRecord. :param truncate_to: :param array_float_format: :param array_print_threshold: :return: A string with no newlines briefly describing the result of the record. """ if isinstance(record, string_types): record = load_experiment_record(record) if not is_experiment_loadable(record.get_experiment_id()): one_liner_function = str else: one_liner_function = record.get_experiment().one_liner_function if one_liner_function is None: one_liner_function = str return get_record_result_string( record, func=one_liner_function, truncate_to=truncate_to, array_print_threshold=array_print_threshold, array_float_format=array_float_format, oneline=True)
def get_record_invalid_arg_string(record, recursive=True, ignore_valid_keys=(), note_version = 'full'): """ Return a string identifying ig the arguments for this experiment are still valid. :return: """ assert note_version in ('full', 'short') experiment_id = record.get_experiment_id() if is_experiment_loadable(experiment_id): if record.info.has_field(ExpInfoFields.ARGS): last_run_args = OrderedDict([(k,v) for k,v in record.get_args().items() if k not in ignore_valid_keys]) current_args = OrderedDict([(k,v) for k,v in record.get_experiment().get_args().items() if k not in ignore_valid_keys]) if recursive: last_run_args = OrderedDict(flatten_struct(last_run_args, first_dict_is_namespace=True, primatives = PRIMATIVE_TYPES + (UnPicklableArg, ))) last_run_args = OrderedDict([(k, v) for k, v in last_run_args.items() if k not in ignore_valid_keys]) current_args = OrderedDict(flatten_struct(current_args, first_dict_is_namespace=True)) current_args = OrderedDict([(k, v) for k, v in current_args.items() if k not in ignore_valid_keys]) validity = record.args_valid(last_run_args=last_run_args, current_args=current_args) if validity is False: common, (old_args, new_args) = separate_common_items([list(last_run_args.items()), list(current_args.items())]) if len(old_args)+len(new_args)==0: raise Exception('Error displaying different args. Bug Peter.') all_changed_arg_names = remove_duplicates(list(name for name, _ in old_args)+list(name for name, _ in new_args)) changestr = ', '.join("{}:{}->{}".format(k, last_run_args[k] if k in last_run_args else '<N/A>', current_args[k] if k in current_args else '<N/A>') for k in all_changed_arg_names) notes = ("Change: " if note_version=='full' else "") + changestr elif validity is None: notes = "Cannot Determine: Unhashable Args" if note_version=='full' else '<Unhashable Args>' else: notes = "<No Change>" else: notes = "Cannot Determine: Inconsistent Experiment Record" if note_version == 'full' else '<Inconsistent Record>' else: notes = "Cannot Determine: Experiment Not Imported" if note_version=='full' else '<Not Imported>' return notes
def get_record_invalid_arg_string(record, recursive=True): """ Return a string identifying ig the arguments for this experiment are still valid. :return: """ experiment_id = record.get_experiment_id() if is_experiment_loadable(experiment_id): if record.info.has_field(ExpInfoFields.ARGS): last_run_args = record.get_args() current_args = record.get_experiment().get_args() validity = record.args_valid(last_run_args=last_run_args, current_args=current_args) if validity is False: if recursive: last_run_args = OrderedDict(flatten_struct(last_run_args, first_dict_is_namespace=True)) current_args = OrderedDict(flatten_struct(current_args, first_dict_is_namespace=True)) last_arg_str, this_arg_str = [['{}:{}'.format(k, v) for k, v in argdict.iteritems()] for argdict in (last_run_args, current_args)] common, (old_args, new_args) = separate_common_items([last_arg_str, this_arg_str]) notes = "No: Args changed!: {{{}}}->{{{}}}".format(','.join(old_args), ','.join(new_args)) elif validity is None: notes = "Cannot Determine: Unhashable Args" else: notes = "Yes" else: notes = "Cannot Determine: Inconsistent Experiment Record" else: notes = "Cannot Determine: Experiment Not Imported" return notes
def get_record_invalid_arg_string(record, recursive=True, ignore_valid_keys=(), note_version='full'): """ Return a string identifying ig the arguments for this experiment are still valid. :return: """ assert note_version in ('full', 'short') experiment_id = record.get_experiment_id() if is_experiment_loadable(experiment_id): if record.info.has_field(ExpInfoFields.ARGS): last_run_args = OrderedDict([(k, v) for k, v in record.get_args().items() if k not in ignore_valid_keys]) current_args = OrderedDict([ (k, v) for k, v in record.get_experiment().get_args().items() if k not in ignore_valid_keys ]) if recursive: last_run_args = OrderedDict( flatten_struct(last_run_args, first_dict_is_namespace=True)) last_run_args = OrderedDict([(k, v) for k, v in last_run_args.items() if k not in ignore_valid_keys]) current_args = OrderedDict( flatten_struct(current_args, first_dict_is_namespace=True)) current_args = OrderedDict([(k, v) for k, v in current_args.items() if k not in ignore_valid_keys]) validity = record.args_valid(last_run_args=last_run_args, current_args=current_args) if validity is False: last_arg_str, this_arg_str = [[ '{}:{}'.format(k, v) for k, v in argdict.items() ] for argdict in (last_run_args, current_args)] common, (old_args, new_args) = separate_common_items( [last_arg_str, this_arg_str]) if len(old_args) + len(new_args) == 0: raise Exception( 'Error displaying different args. Bug Peter.') changestr = "{{{}}}->{{{}}}".format(','.join(old_args), ','.join(new_args)) notes = ("Change: " if note_version == 'full' else "") + changestr elif validity is None: notes = "Cannot Determine: Unhashable Args" if note_version == 'full' else '<Unhashable Args>' else: notes = "<No Change>" else: notes = "Cannot Determine: Inconsistent Experiment Record" if note_version == 'full' else '<Inconsistent Record>' else: notes = "Cannot Determine: Experiment Not Imported" if note_version == 'full' else '<Not Imported>' return notes
def get_oneline_result_string(record, truncate_to=None, array_float_format='.3g', array_print_threshold=8): """ Get a string that describes the result of the record in one line. This can optionally be specified by experiment.one_liner_function. :param record: An ExperimentRecord. :param truncate_to: :param array_float_format: :param array_print_threshold: :return: A string with no newlines briefly describing the result of the record. """ if isinstance(record, string_types): record = load_experiment_record(record) if not is_experiment_loadable(record.get_experiment_id()): one_liner_function=str else: one_liner_function = record.get_experiment().one_liner_function if one_liner_function is None: one_liner_function = str return get_record_result_string(record, func=one_liner_function, truncate_to=truncate_to, array_print_threshold=array_print_threshold, array_float_format=array_float_format, oneline=True)
def get_record_invalid_arg_string(record, recursive=True, ignore_valid_keys=(), note_version='full'): """ Return a string identifying ig the arguments for this experiment are still valid. :return: """ assert note_version in ('full', 'short') experiment_id = record.get_experiment_id() if is_experiment_loadable(experiment_id): if record.info.has_field(ExpInfoFields.ARGS): last_run_args = OrderedDict([(k, v) for k, v in record.get_args().items() if k not in ignore_valid_keys]) current_args = OrderedDict([ (k, v) for k, v in record.get_experiment().get_args().items() if k not in ignore_valid_keys ]) if recursive: last_run_args = OrderedDict( flatten_struct(last_run_args, first_dict_is_namespace=True, primatives=PRIMATIVE_TYPES + (UnPicklableArg, ))) last_run_args = OrderedDict([(k, v) for k, v in last_run_args.items() if k not in ignore_valid_keys]) current_args = OrderedDict( flatten_struct(current_args, first_dict_is_namespace=True)) current_args = OrderedDict([(k, v) for k, v in current_args.items() if k not in ignore_valid_keys]) validity = record.args_valid(last_run_args=last_run_args, current_args=current_args) if validity is False: common, (old_args, new_args) = separate_common_items( [list(last_run_args.items()), list(current_args.items())]) if len(old_args) + len(new_args) == 0: raise Exception( 'Error displaying different args. Bug Peter.') all_changed_arg_names = remove_duplicates( list(name for name, _ in old_args) + list(name for name, _ in new_args)) changestr = ', '.join("{}:{}->{}".format( k, last_run_args[k] if k in last_run_args else '<N/A>', current_args[k] if k in current_args else '<N/A>') for k in all_changed_arg_names) notes = ("Change: " if note_version == 'full' else "") + changestr elif validity is None: notes = "Cannot Determine: Unhashable Args" if note_version == 'full' else '<Unhashable Args>' else: notes = "<No Change>" else: notes = "Cannot Determine: Inconsistent Experiment Record" if note_version == 'full' else '<Inconsistent Record>' else: notes = "Cannot Determine: Experiment Not Imported" if note_version == 'full' else '<Not Imported>' return notes