Skip to content

Compute emissions based on ongoing carbon intensity#1050

Merged
benoit-cty merged 4 commits intomasterfrom
feature/issue-994
Feb 8, 2026
Merged

Compute emissions based on ongoing carbon intensity#1050
benoit-cty merged 4 commits intomasterfrom
feature/issue-994

Conversation

@cianc
Copy link
Contributor

@cianc cianc commented Feb 4, 2026

Description

Compute emissions based on ongoing carbon intensity samples, rather than just taking the latest value and applying it to all energy consumption every time.

Related Issue

Please link to the issue this PR resolves: #994

Motivation and Context

Improves emission accuracy over long runs.

How Has This Been Tested?

Added a new test and ran all existing tests.

Screenshots (if appropriate):

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.73%. Comparing base (abcaf04) to head (cc62d32).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1050      +/-   ##
==========================================
+ Coverage   68.51%   68.73%   +0.21%     
==========================================
  Files          41       41              
  Lines        3862     3873      +11     
==========================================
+ Hits         2646     2662      +16     
+ Misses       1216     1211       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cianc cianc marked this pull request as ready for review February 4, 2026 17:50
@cianc cianc requested a review from a team as a code owner February 4, 2026 17:50
@benoit-cty
Copy link
Contributor

Thank you !
Because some people are using CodeCarbon with short tasks, the potential problem I see is the time it will take to do it. Maybe it will be better to have something like a cache with a 5 minutes duration, what do you think ?

@cianc
Copy link
Contributor Author

cianc commented Feb 6, 2026

Thank you ! Because some people are using CodeCarbon with short tasks, the potential problem I see is the time it will take to do it. Maybe it will be better to have something like a cache with a 5 minutes duration, what do you think ?

Could you elaborate on this, I think I'm missing something? Are you referring to the time it takes to call electricitymaps_api.get_emissions? I don't think this PR changes the number of these calls, it just changes the accounting.

@benoit-cty
Copy link
Contributor

Sorry, you are absolutely right, the def _update_emissions is just calling the same function as before.

Perf improvement is another subject.

@benoit-cty benoit-cty merged commit e38dfb3 into master Feb 8, 2026
10 checks passed
@benoit-cty benoit-cty deleted the feature/issue-994 branch February 8, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Co2 Signal] compute emissions on a regular basis

2 participants