mlco2 / mlco2/codecarbon

Feature Request: Cost to offset

Open
#276 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Python
Stars
1.9k
Forks
323
Avg merge
1d 12h
Merged PRs (30d)
12

Description

In addition to knowing how much carbon a computation emits, it can also be insightful and more importantly actionable to know how much it would cost to offset that emission. I have a small demo script that uses the rates reported by two services: terrapass and cotap.

"""
Requirements:
    pip install codecarbon pint
"""

# Use pint for easy unit conversion
import pint
from codecarbon import EmissionsTracker
reg = pint.UnitRegistry()
reg.define('CO2 = []')
reg.define('dollar = []')
CO2_ton = reg.CO2 * reg.metric_ton
CO2_kg = reg.CO2 * reg.kg
CO2_pound = reg.CO2 * reg.pound


# ====================
# Carbon tracking code
# ====================
tracker = EmissionsTracker()
tracker.start()

# GPU Intensive code goes here
for i in range(100):
    pass

# tracker returns CO2 emissions in kgs
emissions = tracker.stop() * CO2_kg

# Pretend that we did a lot more than we did
pretend_factor = 1000000000
compute_emissions = emissions * pretend_factor

# ========================================
# That's all there is too carbon tracking!
# ========================================

# Calculate cost to offset with one of these carbon capture services:
co2_offset_costs = {
    'terrapass': (100.75 * reg.dollars) / (20_191 * CO2_pound).to(CO2_ton),
    'cotap': (15 * reg.dollars) / (1 * CO2_ton),
}
service = 'cotap'  # cotap is non-profit, lets use them
dollar_per_co2ton = co2_offset_costs[service]

cost_to_offset = (compute_emissions * dollar_per_co2ton).to_base_units()
print(f'It will cost roughly ${cost_to_offset:.2f} to offset this emission')

I think gathering information on available carbon offsetting services and increasing awareness of them would be a great direction for this project.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python demo and its EmissionsTracker usage, then review how the terrapass and cotap rates are gathered and represented. Define what offset-service information the project should expose and how the cost calculation should be verified; done means the feature has a clear supported scope beyond the demo.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.