xplogger.parser package

Submodules

xplogger.parser.base module

Base class that all parsers extend.

class xplogger.parser.base.Parser(parse_line: Callable[[str], Optional[Dict[str, Any]]] = <function parse_json>)[source]

Bases: abc.ABC

Base class that all parsers extend.

xplogger.parser.config module

Implementation of Parser to parse config from logs.

class xplogger.parser.config.Parser(parse_line: Callable[[str], Optional[Dict[str, Any]]] = <function parse_json_and_match_value>)[source]

Bases: xplogger.parser.log.Parser

Class to parse config from the logs.

xplogger.parser.config.parse_json_and_match_value(line: str)Optional[Dict[str, Any]][source]

Parse a line as JSON log and check if it a valid config log.

xplogger.parser.log module

Implementation of Parser to parse the logs.

class xplogger.parser.log.Parser(parse_line: Callable[[str], Optional[Dict[str, Any]]] = <function parse_json>)[source]

Bases: xplogger.parser.base.Parser

Class to parse the log files.

parse(filepath_pattern: str)Iterator[Dict[str, Any]][source]

Open a log file, parse its contents and return logs.

Parameters

filepath_pattern (str) – filepath pattern to glob

Returns

Iterator over the logs

Return type

Iterator[LogType]

Yields

Iterator[LogType] – Iterator over the logs

parse_first_log(filepath_pattern: str)Optional[Dict[str, Any]][source]

Return the first log from a file.

The method will return after finding the first log. Unlike parse() method, it will not iterate over the entire log file (thus saving memory and time).

Parameters

filepath_pattern (str) – filepath pattern to glob

Returns

First instance of a log

Return type

LogType

parse_last_log(filepath_pattern: str)Optional[Dict[str, Any]][source]

Return the last log from a file.

Like parse() method, it will iterate over the entire log file but will not keep all the logs in memory (thus saving memory).

Parameters

filepath_pattern (str) – filepath pattern to glob

Returns

Last instance of a log

Return type

LogType

xplogger.parser.log.parse_json_and_match_value(line: str, value: str)Optional[Dict[str, Any]][source]

Parse a line as JSON log and check if it a valid log.

xplogger.parser.metric module

Implementation of Parser to parse metrics from logs.

class xplogger.parser.metric.Parser(parse_line: Callable[[str], Optional[Dict[str, Any]]] = <function parse_json_and_match_value>)[source]

Bases: xplogger.parser.log.Parser

Class to parse the metrics from the logs.

parse_as_df(filepath_pattern: str, group_metrics: Callable[[list[LogType]], dict[str, list[LogType]]] = <function group_metrics>, aggregate_metrics: Callable[[list[LogType]], list[LogType]] = <function aggregate_metrics>)dict[str, pd.DataFrame][source]

Create a dict of (metric_name, dataframe).

Method that: (i) reads metrics from the filesystem (ii) groups metrics (iii) aggregates all the metrics within a group, (iv) converts the aggregate metrics into dataframes and returns a dictionary of dataframes

Parameters
  • filepath_pattern (str) – filepath pattern to glob

  • group_metrics (Callable[[list[LogType]], dict[str, list[LogType]]], optional) – Function to group a list of metrics into a dictionary of (key, list of grouped metrics). Defaults to group_metrics.

  • aggregate_metrics (Callable[[list[LogType]], list[LogType]], optional) – Function to aggregate a list of metrics. Defaults to aggregate_metrics.

xplogger.parser.metric.aggregate_metrics(metrics: list[MetricType])list[MetricType][source]

Aggregate a list of metrics.

Parameters

metrics (list[MetricType]) – list of metrics to aggregate

Returns

list of aggregated metrics

Return type

list[MetricType]

xplogger.parser.metric.group_metrics(metrics: list[MetricType])dict[str, list[MetricType]][source]

Group a list of metrics.

Group a list of metrics into a dictionary of

(key, list of grouped metrics)

Parameters

metrics (list[MetricType]) – list of metrics to group

Returns

Dictionary of (key,

list of grouped metrics)

Return type

dict[str, list[MetricType]]

xplogger.parser.metric.metrics_to_df(metric_logs: list[LogType], group_metrics: Callable[[list[LogType]], dict[str, list[LogType]]] = <function group_metrics>, aggregate_metrics: Callable[[list[LogType]], list[LogType]] = <function aggregate_metrics>)dict[str, pd.DataFrame][source]

Create a dict of (metric_name, dataframe).

Method that: (i) groups metrics (ii) aggregates all the metrics within a group, (iii) converts the aggregate metrics into dataframes and returns a dictionary of dataframes

Parameters
  • metric_logs (list[LogType]) – list of metrics

  • group_metrics (Callable[[list[LogType]], dict[str, list[LogType]]], optional) – Function to group a list of metrics into a dictionary of (key, list of grouped metrics). Defaults to group_metrics.

  • aggregate_metrics (Callable[[list[LogType]], list[LogType]], optional) – Function to aggregate a list of metrics. Defaults to aggregate_metrics.

Returns

[description]

Return type

dict[str, pd.DataFrame]

xplogger.parser.metric.parse_json_and_match_value(line: str)Optional[Dict[str, Any]][source]

Parse a line as JSON log and check if it a valid metric log.

xplogger.parser.utils module

Utility functions for the parser module.

xplogger.parser.utils.compare_logs(first_log: LogType, second_log: LogType, verbose: bool = False)tuple[list[str], list[str], list[str]][source]

Compare two logs.

Return list of keys that are either missing or have different valus in the two logs.

Parameters
  • first_log (LogType) – First Log

  • second_log (LogType) – Second Log

  • verbose (bool) – Defaults to False

Returns

tuple of [

list of keys with different values, list of keys with values missing in first log, list of keys with values missing in the second log,]

Return type

tuple[list[str], list[str], list[str]]

xplogger.parser.utils.flatten_log(d: Dict[str, Any], parent_key: str = '', sep: str = '#')Dict[str, Any][source]

Flatten a log using a separator.

Taken from https://stackoverflow.com/a/6027615/1353861

Parameters
  • d (LogType) – [description]

  • parent_key (str, optional) – [description]. Defaults to “”.

  • sep (str, optional) – [description]. Defaults to “#”.

Returns

[description]

Return type

LogType

xplogger.parser.utils.get_param_groups(configs: Iterable[ConfigType], params_to_exclude: Iterable[str])tuple[ConfigType, dict[str, set[Any]]][source]

Return two groups of params, one which is fixed across the experiments and one which varies.

This function is useful when understanding the effect of different parameters on the model’s performance. One could plot the performance of the different experiments, as a function of the parameters that vary.

Parameters
  • configs (Iterable[ConfigType]) – Collection of configs, to extract params from.

  • params_to_exclude (Iterable[str]) – These parameters are not returned in either group. This is useful for ignoring parameters like time when the experiment was started since these parameters should not affect the performance. In absence of this argument, all such parameters will likely be returned with the group of varying parameters.

Returns

The first group/config contains the params which are fixed across the experiments.

It maps these params to their default values, hence it should be a subset of any config. The second group/config contains the params which vary across the experiments. It maps these params to the set of values they take.

Return type

tuple[ConfigType, dict[str, set[Any]]]

xplogger.parser.utils.parse_json(line: str)Optional[Dict[str, Any]][source]

Parse a line as JSON string.

Module contents