Skip to content

Commit

Permalink
Merge pull request #75 from Snailed/fix-parsing-error
Browse files Browse the repository at this point in the history
Fix parsing error
  • Loading branch information
Snailed authored Jul 23, 2024
2 parents 8fcb54a + 45449f7 commit c3d7238
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 71 deletions.
4 changes: 4 additions & 0 deletions carbontracker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ class FetcherNameError(Exception):

class MismatchedLogFilesError(Exception):
pass


class MismatchedEpochsError(Exception):
pass
7 changes: 6 additions & 1 deletion carbontracker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def parse_logs(log_dir, std_log_file=None, output_log_file=None):
if power_usages is None or durations is None:
energy_usages = None
else:
if power_usages.size != durations.size:
raise exceptions.MismatchedEpochsError(
f"Found {power_usages.size} power measurements and {durations.size} duration measurements. "
"Expected equal number of measurements."
)
energy_usages = (power_usages.T * durations).T
measurements = {
"avg_power_usages (W)": power_usages,
Expand Down Expand Up @@ -394,7 +399,7 @@ def get_avg_power_usages(std_log_data):
[component name]: list[list[float]]
}
"""
power_re = re.compile(r"Average power usage \(W\) for (.+): (\[.+\]|None)")
power_re = re.compile(r"Average power usage \(W\) for (.+): (\[?[0-9\.]+\]?|None)")
matches = re.findall(power_re, std_log_data)
components = list(set([comp for comp, _ in matches]))
avg_power_usages = {}
Expand Down
Loading

0 comments on commit c3d7238

Please sign in to comment.