mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.12k stars 173 forks source link

Feature Request: Cost to offset #276

Open Erotemic opened 2 years ago

Erotemic commented 2 years ago

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.

vict0rsch commented 2 years ago

Thank you for your message!

I personally think this is a great next step, action after information and we don't want people being stuck and satisfied with info only.

However I'm not sure whether we should include offsetting as a part of the package, or at least not associated with any particular organisation.

We can also discuss the opportunity for even recommending offsetting. While I agree with the intention I know some people have reservations, + sobriety is probably the actual goal (re: Jevons paradox) and some infrastructures (such as cloud services) already offset emissions linked to computations.

It is not my area of expertise, so if you want to help and contribute something like a Wiki page that would be great :)

benoit-cty commented 2 years ago

Maybe we could add it in Dashboard, with a common interface to allow other offsetting partner to add their services.

And, yes, offsetting is not sustainable. But still better than nothing ?