← Back to Pull requests

[MAINT] Measuring CI energy consumption with CodeCarbon #843

Open
GrituX opened this pull request with 22 lines diff across 3 files
View on GitHub
GrituX GrituX commented on Oct 28, 2026 15:24 UTC
Author

Trying a few measures in a safe PR env.

Diff: 22 lines (+14 / -8) across 3 files Reviewer: bthirion Review duration: 52171m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.32) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.32 · 22 lines diff across 3 files
0.32
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
88%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.188
Real PR Conversation Timeline
17 items
codecov[bot] codecov[bot] commented on Oct 28, 2026 15:51 UTC
Bot

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>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    GrituX GrituX commented on Oct 28, 2026 15:55 UTC
    Author

    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 ...

    GrituX GrituX commented on Oct 28, 2026 16:07 UTC
    Author

    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.

    GrituX GrituX commented on Oct 29, 2026 11:08 UTC
    Author

    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.

    jpaillard jpaillard commented on Oct 29, 2026 14:36 UTC
    Contributor

    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.

    bthirion bthirion commented on Oct 30, 2026 07:44 UTC
    Contributor

    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.

    GrituX GrituX commented on Oct 30, 2026 12:56 UTC
    Author

    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.

    bthirion bthirion commented on Oct 30, 2026 17:18 UTC
    Contributor

    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.

    GrituX GrituX commented on Nov 10, 2026 12:13 UTC
    Author

    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

    bthirion bthirion approved these changes on Nov 10, 2026 22:22 UTC
    Approved Reviewer

    Thx for adding this !

    Remi-Gau Remi-Gau commented on code on Nov 27, 2026 11:02 UTC
    Code Review
    .github/workflows/call_test_package.yml:1
    @@ -61,6 +61,7 @@ jobs:
             if: ${{ inputs.skip_test == false }}
             run: |
               uv pip install -e ".[test]"
    +          uv pip install -e ".[energy]"

              uv pip install -e ".[test,energy]"
    

    Remi-Gau Remi-Gau commented on code on Nov 27, 2026 11:03 UTC
    Code Review
    tools/documentation/circleci/build_doc.sh:1

    that file is gone: let me change this

    Remi-Gau Remi-Gau commented on code on Nov 27, 2026 11:05 UTC
    Code Review
    pyproject.toml:1
    @@ -62,6 +62,7 @@ doc = [
         "sphinx-copybutton      >= 0.5.2",
         "sphinx-design          >= 0.5.0",
         "pyyaml                 >= 6.0",
    +    "codecarbon             >= 3.0.0",

    are you sure you want to add this to the dependency stack instead of just installing it by itself in CI?

    GrituX GrituX commented on Nov 27, 2026 11:10 UTC
    Author

    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.

    GrituX GrituX commented on code on Nov 27, 2026 11:10 UTC
    Code Review
    pyproject.toml:1
    @@ -62,6 +62,7 @@ doc = [
         "sphinx-copybutton      >= 0.5.2",
         "sphinx-design          >= 0.5.0",
         "pyyaml                 >= 6.0",
    +    "codecarbon             >= 3.0.0",

    wdym ?

    Remi-Gau Remi-Gau commented on code on Nov 27, 2026 11:20 UTC
    Code Review
    pyproject.toml:1
    @@ -62,6 +62,7 @@ doc = [
         "sphinx-copybutton      >= 0.5.2",
         "sphinx-design          >= 0.5.0",
         "pyyaml                 >= 6.0",
    +    "codecarbon             >= 3.0.0",

    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

    Reviewers
    Assignees
    GrituX GrituX
    Labels
    risk: low confidence: 88.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.7% (LOW) · Higher = larger blast radius
    31.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.8% · Lower = rushed or shallow review
    88.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.6% · Safe to merge
    3.6%