API Reference#

class expttools.Experiment(experiment_function, parameter_grid, name_func=None, parameter_string={}, name_format=None)[source]#
get_max_name_length()[source]#

get the max length of all names

get_name_list()[source]#

generate list of all names

Returns:

name_list – names of all folders to be created

Return type:

list of str

static param_string(parameter_value)[source]#

return a string based on the type

restart_batch(full_path=None, base_path=None, date_stamp_name=None, expt_name=None, verbose=False)[source]#

restart a run, uses default ‘results’ dir and most recent one that matches the experiment_function if no path is named or fills in from parts.

Parameters:
  • full_path (string or path) – use this to specify the full path to the results, specifying this overrides other input parameters of this method

  • date_stamp_name (string) – specify the particular previous run you want to re-start

  • base_path (string or path) – directory to search for previous runs

  • expt_name (string) – name to filter on; uses experiment_function.__name__ if None

run_batch(base_path='results', name_func=None, expt_name=None, datestamp_file=True, nested=False, verbose=False, restart=False, full_path=None)[source]#

run a batch of experiments over the parameter grid and save all results in a structured file system with naming conventions that protect from overwriting

Parameters:
  • base_path (path or string) – base path to create subfolders in for ths set of experiments

  • name_func (function or None) – a function that creates a file name from parameter values

  • expt_name (string, default None) – meaningful name for the batch to prepend to the date to, if None, uses the __name__ attribute of the experiment function

  • datestamp_file (boolean, default True) – flag to datestamp or not, typically should not be changed

  • nested (boolean, default false) – flag to treat parameters as nested

  • verbose (boolean, default False) – flag to display debugging output

  • restart (boolean, default False) – is this a restart

  • full_path (path or string, default None) – uesd for restart; generally should not be used

Returns:

  • success_list (list of string) – experiment names that succeed

  • failed_list (list of strings) – experiment names that threw an exception

run_test(param_i=None, verbose=False)[source]#

Call the function with a single (default first) value of each parameter and return the result. throws warnings if save format is incompatible with ExperimentResult

Parameters:
  • param_i (list) – list of ints to use as the index for each parameter in order they appear in the parameter grid

  • verbose (boolean) – display maximum outputs

Returns:

  • cur_name (string) – name of the tested case

  • expt_result ((df)) – what the experiment function returns

static save_failed(meta_df, name, path, err)[source]#

save metadata only when an experiment fails

static save_result(result_df, meta_df, name, path)[source]#

save results with good naming conventions

validate_name_func()[source]#

validate that the names will be unique

Returns:

unique_nams – True if all names are unique

Return type:

bool

class expttools.ExperimentResult(top_level_dir, is_info_df_list=False)[source]#
get_fail_df()[source]#

stack fails into a dataframe

get_info_df()[source]#

create a dataframe of only the parameters

get_named_tuples()[source]#
Returns:

result_tuple_list

Return type:

a list of named tuples (name, dataframe, and info) as attributes

get_result_df_list()[source]#

return a list of the result dfs with

get_result_dirs()[source]#

list of paths

stack_results()[source]#

stack all results with