Skip to content

analyze

zeus.analyze

Utilities for result analysis.

HistoryEntry dataclass

Represents the config and result of a job run that may have failed.

Attributes:

Name Type Description
bs int

Batch size

pl int

Power limit

energy float

Energy consumption in Joules

reached bool

Whether the target metric was reached at the end

time float

Time consumption in seconds

Source code in zeus/analyze.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@dataclass
class HistoryEntry:
    """Represents the config and result of a job run that may have failed.

    Attributes:
        bs: Batch size
        pl: Power limit
        energy: Energy consumption in Joules
        reached: Whether the target metric was reached at the end
        time: Time consumption in seconds
    """

    bs: int
    pl: int
    energy: float
    reached: bool
    time: float

energy

1
energy(logfile, start=None, end=None)

Compute the energy consumption from the Zeus monitor power log file.

start and end are in units of seconds, relative to the beginning of the time window captured by the log file. Only the time window between start and end will be considered when computing energy.

start and end can be negative, in which case the pointers wrap around and effectively the absolute value is subtracted from the end of the window.

Parameters:

Name Type Description Default
logfile Path | str

Path to the power log file produced by the Zeus monitor.

required
start float | None

Start time of the window to consider.

None
end float | None

End time of the window to consider.

None
Source code in zeus/analyze.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def energy(
    logfile: Path | str,
    start: float | None = None,
    end: float | None = None,
) -> float:
    """Compute the energy consumption from the Zeus monitor power log file.

    `start` and `end` are in units of seconds, relative to the beginning of
    the time window captured by the log file. Only the time window between
    `start` and `end` will be considered when computing energy.

    `start` and `end` can be negative, in which case the pointers wrap around
    and effectively the absolute value is subtracted from the end of the window.

    Args:
        logfile: Path to the power log file produced by the Zeus monitor.
        start: Start time of the window to consider.
        end: End time of the window to consider.
    """
    df = cast(pd.DataFrame, pd.read_csv(logfile, engine="python", skipfooter=1))
    df["Time"] = pd.to_datetime(df["Time"])
    start_timestamp = df.iloc[0]["Time"]
    end_timestamp = df.iloc[-1]["Time"]
    if start is not None:
        origin = start_timestamp if start >= 0.0 else end_timestamp
        df = df.loc[df["Time"] >= origin + timedelta(seconds=start)]
    if end is not None:
        origin = start_timestamp if end >= 0.0 else end_timestamp
        df = df.loc[df["Time"] <= origin + timedelta(seconds=end)]
    seconds = _get_seconds(df)
    watts = _get_watts(df)
    return auc(seconds, watts)

avg_power

1
avg_power(logfile, start=None, end=None)

Compute the average power consumption from the Zeus monitor power log file.

start and end are in units of seconds, relative to the beginning of the time window captured by the log file. Only the time window between start and end will be considered when computing average power.

start and end can be negative, in which case the pointers wrap around and effectively the absolute value is subtracted from the end of the window.

Parameters:

Name Type Description Default
logfile Path | str

Path to the power log file produced by the Zeus monitor.

required
start float | None

Start time of the window to consider.

None
end float | None

End time of the window to consider.

None

Raises:

Type Description
ValueError

From sklearn.metrics.auc, when the duration of the profiling window is too small.

Source code in zeus/analyze.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def avg_power(
    logfile: Path | str,
    start: float | None = None,
    end: float | None = None,
) -> float:
    """Compute the average power consumption from the Zeus monitor power log file.

    `start` and `end` are in units of seconds, relative to the beginning of
    the time window captured by the log file. Only the time window between
    `start` and `end` will be considered when computing average power.

    `start` and `end` can be negative, in which case the pointers wrap around
    and effectively the absolute value is subtracted from the end of the window.

    Args:
        logfile: Path to the power log file produced by the Zeus monitor.
        start: Start time of the window to consider.
        end: End time of the window to consider.

    Raises:
        ValueError: From `sklearn.metrics.auc`, when the duration of the
            profiling window is too small.
    """
    df = cast(pd.DataFrame, pd.read_csv(logfile, engine="python", skipfooter=1))
    df["Time"] = pd.to_datetime(df["Time"])
    if start is not None:
        df = df.loc[df["Time"] >= df.iloc[0]["Time"] + timedelta(seconds=start)]
    if end is not None:
        df = df.loc[df["Time"] <= df.iloc[0]["Time"] + timedelta(seconds=end)]
    seconds = _get_seconds(df)
    watts = _get_watts(df)
    area = auc(seconds, watts)
    return area / (max(seconds) - min(seconds))