braket.jobs.metrics_data.log_metrics_parser module

class braket.jobs.metrics_data.log_metrics_parser.LogMetricsParser(logger: ~logging.Logger = <Logger braket.jobs.metrics_data.log_metrics_parser (WARNING)>)[source]

Bases: object

This class is used to parse metrics from log lines, and return them in a more convenient format.

METRICS_DEFINITIONS = re.compile('(\\w+)\\s*=\\s*([^;]+)\\s*;')
TIMESTAMP = 'timestamp'
ITERATION_NUMBER = 'iteration_number'
NODE_ID = 'node_id'
NODE_TAG = re.compile('^\\[([^\\]]*)\\]')
parse_log_message(timestamp: str, message: str) None[source]

Parses a line from logs, adding all the metrics that have been logged on that line. The timestamp is also added to match the corresponding values.

Parameters:
  • timestamp (str) – A formatted string representing the timestamp for any found metrics.

  • message (str) – A log line from a log.

get_columns_and_pivot_indices(pivot: str) tuple[dict[str, list[str | float | int]], dict[tuple[int, str], int]][source]

Parses the metrics to find all the metrics that have the pivot column. The values of the pivot column are paired with the node_id and assigned a row index, so that all metrics with the same pivot value and node_id are stored in the same row.

Parameters:

pivot (str) – The name of the pivot column. Must be TIMESTAMP or ITERATION_NUMBER.

Returns:

tuple[dict[str, list[Union[str, float, int]]], dict[tuple[int, str], int]] – Contains: The dict[str, list[Any]] is the result table with all the metrics values initialized to None. The dict[tuple[int, str], int] is the list of pivot indices, where the value of a pivot column and node_id is mapped to a row index.

get_metric_data_with_pivot(pivot: str, statistic: MetricStatistic) dict[str, list[str | float | int]][source]

Gets the metric data for a given pivot column name. Metrics without the pivot column are not included in the results. Metrics that have the same value in the pivot column from the same node are returned in the same row. Metrics from different nodes are stored in different rows. If the metric has multiple values for the row, the statistic is used to determine which value is returned. For example, for the metrics: “iteration_number” : 0, “metricA” : 2, “metricB” : 1, “iteration_number” : 0, “metricA” : 1, “no_pivot_column” : 0, “metricA” : 0, “iteration_number” : 1, “metricA” : 2, “iteration_number” : 1, “node_id” : “nodeB”, “metricB” : 0,

The result with iteration_number as the pivot, statistic of MIN the result will be:

iteration_number node_id metricA metricB 0 None 1 1 1 None 2 None 1 nodeB None 0

Parameters:
  • pivot (str) – The name of the pivot column. Must be TIMESTAMP or ITERATION_NUMBER.

  • statistic (MetricStatistic) – The statistic to determine which value to use.

Returns:

dict[str, list[Union[str, float, int]]] – The metrics data.

get_parsed_metrics(metric_type: MetricType, statistic: MetricStatistic) dict[str, list[str | float | int]][source]

Gets all the metrics data, where the keys are the column names and the values are a list containing the values in each row.

Parameters:
  • metric_type (MetricType) – The type of metrics to get.

  • statistic (MetricStatistic) – The statistic to determine which metric value to use when there is a conflict.

Returns:

dict[str, list[Union[str, float, int]]] – The metrics data.

Example

timestamp energy

0 0.1 1 0.2

would be represented as: { “timestamp” : [0, 1], “energy” : [0.1, 0.2] } values may be integers, floats, strings or None.