[MAINT] Measuring CI energy consumption with CodeCarbon #843
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 97.42%. Comparing base (
6d3bd70) to head (e77af60).:warning: Report is 4 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #843 +/- ##
=======================================
Coverage 97.42% 97.42%
=======================================
Files 37 37
Lines 2600 2600
=======================================
Hits 2533 2533
Misses 67 67
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Ok, so doc building only is 1.6324 g CO2eq, given that CircleCI servers are based in the US. That's the equivalent of 12L of water being used (source). That's a lot more than on my computer, which was around 1L. But also, their energy mix is way different than the French ...
So the test execution fails because CodeCarbon directly outputs the Seedling emoji (unicode \U0001f331) at launch in the command line which makes the Github Action terminal crash apparently. Looking for a workaround.
So the total amount of carbon emitted from the energy consumption for tests is up to 2.04 g CO2eq (Github Actions servers are also located in the US)
macos machines consume much more energy (~6x more) than ubuntu or windows machines (macos runtimes are longer). Also, failing tests consume as much energy as the doc building for some reason, which can be a good incentive to test things locally before pushing commits.
Doc building + tests amount to an equivalent of consuming ~28L of tap water. That's not counting all other processes surrounding those tasks. I'll try to see if I can do measures for the entire pipeline.
Thx for opening this!
- Why don't we trigger the doc build only when we pass a specific tag? We could keep the doc build as a requirement for merging, but switch from building the doc by default to building it only when the commit message contains a chosen pattern?
- Similarly, why not run a single test by default (e.g. Ubuntu latest) and only trigger the full test array when the commit msg contains a chosen pattern?
- If we document this, IMO, the water example is not the clearest. I guess the ADEME data quantifies the carbon footprint of the energy needed to treat water and pump it to people's taps, like "the footprint of our CI corresponds to the footprint needed to treat x liters of tap water". But in this context, it could be mistaken for actual water usage in data centers, which could lead to conflict of use, but isn't what we quantify, IIUC. Something like you could charge your phone x times may be more intuitive.
Thx for the assessment !
First, it's not completely clear to me how we should interpret these numbers. For instance, should we define a target for these metrics ?
One problem with having less systematic doc build or tests is that we may miss some of the issues and fight with all of them at release time.
What we could do is to disable the doc build by default, but at least one has to be triggered and validated before the PR is approved and merged.
As for the tests, we could have a tag that disables them if not needed, and a tag for minimal tests (only Ubuntu 3.10). But similarly, at least a full range of tests has to be triggered before approval and merge. Also, there is a "minimal test" that is always launched with Ubuntu and Python 3.10 but one is already included in the test-grid across all OS and Python versions (3.10 and 3.14). We can start with getting rid of that duplicate IMO.
I should have explained a bit more, but indeed, the measures from the ADEME correspond to the "footprint needed to treat x liters of tap water" as stated by @jpaillard . Since using the grams of CO2 equivalence is subject to different interpretations and impacts depending on the country, I agree that a more straightforward measure could be the kWh drainage (with a reference that makes more sense to people), maybe provide the carbon footprint in the US and what it would be in France, and that could be it. This could easily be documented in a separate page.
First, it's not completely clear to me how we should interpret these numbers. For instance, should we define a target for these metrics ?
I'm not sure I understand what the target would be used for. Would it be to determine when to trigger tests / doc build or not ? I think that this could be a case to case decision according to the code submitted in the PR.
My question is to compare hidimstat impact with that of other libraries of the same kind.
If the total impact on a yearly basis is of the order of Kgs of CO2, this looks rather small (?)
For instance, estimating what has been the impact in the last three months would be interesting.
I looked over the past 2 months, we had 242 pushes that triggered tests and doc build. I didn't manually check all, but not all pushes were valid, and so not all triggered a doc build. This is going to over-estimate the consumption.
By taking an average of 3.6 g CO2eq according to previous measures, that's 5.2kg CO2eq over a year, which is pretty small for a library imho.
I have not found measures of environmental impact from sklearn nor pandas. I'd be curious to see what are the numbers for nilearn's CI @Remi-Gau
Thx for adding this !
uv pip install -e ".[test,energy]"
that file is gone: let me change this
are you sure you want to add this to the dependency stack instead of just installing it by itself in CI?
I didn't plan on merging this PR initially, the goal was just to measure the energy consumption once. But maybe we could have this as a scheduled workflow once a month to evaluate the changes in energy consumption.
wdym ?
codecarbon is not needed to run the tests or build the doc, so I would just install the package in CI rather than make it a dependency of hidimstat
bthirion
GrituX
Trying a few measures in a safe PR env.