Skip to content

Commit 79c0cec

Browse files
author
Kevin Cortacero
committed
new carbon tracker
1 parent c5d9c56 commit 79c0cec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/kartezio/callback.py

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import matplotlib.pyplot as plt
88
import numpy as np
9+
from codecarbon import EmissionsTracker
910

1011
from kartezio.helpers import Observer
1112
from kartezio.utils.json_handler import json_write
@@ -83,6 +84,19 @@ def on_evolution_end(self, iteration: int, event_content):
8384
pass
8485

8586

87+
class CarbonCallback(Callback):
88+
def __init__(self):
89+
super().__init__()
90+
self.tracker = EmissionsTracker()
91+
92+
def on_evolution_start(self, _, __):
93+
self.tracker.start()
94+
95+
def on_evolution_end(self, _, __):
96+
self.tracker.stop()
97+
print(self.tracker.final_emissions_data)
98+
99+
86100
class CallbackVerbose(Callback):
87101
def _compute_metrics(self, e_content):
88102
_, fitness, time = e_content.get_best_fitness()

0 commit comments

Comments
 (0)