Skip to content

Commit

Permalink
Add a test for carbon footprint estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
tlestang committed Mar 18, 2024
1 parent 989a7e0 commit d6bf0c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cats/carbonFootprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ def get_footprint_reduction_estimate(
PUE: float,
jobinfo: list[tuple[int, float]],
runtime: datetime.timedelta,
average_best_ci: float,
average_best_ci: float, # in gCO2/kWh
average_now_ci: float,
) -> Estimates:
# energy in kWh
energy = (
PUE
* (runtime.total_seconds() / 3600)
* sum([(nunits * power) / 1000 for nunits, power in jobinfo])
* sum([(nunits * power) for nunits, power in jobinfo])
/ 1000
)
best = energy * average_best_ci
now = energy * average_now_ci
Expand Down
17 changes: 17 additions & 0 deletions tests/test_footprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import datetime

from cats.carbonFootprint import Estimates, get_footprint_reduction_estimate

JOBINFO = [(1, 2.0), (2, 3.0), (8, 1.0)]


def test_get_footprint_reduction_estimate():
expected = Estimates(now="3 gCO2e", best="2 gCO2e", savings="gCO2e")
est = get_footprint_reduction_estimate(
PUE=1.0,
jobinfo=JOBINFO,
runtime=datetime.timedelta(minutes=60),
average_best_ci=150, # gCO2/kWh
average_now_ci=200, # gCO2/kWh
)
assert est == expected

0 comments on commit d6bf0c8

Please sign in to comment.