Emissions tracker plugin
amltk.scheduling.plugins.emissions_tracker_plugin
#
Emissions Tracker Plugin Module.
This module defines a plugin for tracking carbon emissions using the codecarbon library.
For usage examples, refer to the docstring of the EmissionsTrackerPlugin class.
EmissionsTrackerPlugin
#
Bases: Plugin
A plugin that tracks carbon emissions using codecarbon library.
Usage Example:
from concurrent.futures import ThreadPoolExecutor
from amltk.scheduling import Scheduler
from amltk.scheduling.plugins.emissions_tracker_plugin import EmissionsTrackerPlugin
def some_function(x: int) -> int:
return x * 2
executor = ThreadPoolExecutor(max_workers=1)
# Create a Scheduler instance with the executor
scheduler = Scheduler(executor=executor)
# Create a task with the emissions tracker plugin
task = scheduler.task(some_function, plugins=[
# Pass any codecarbon parameters as args here
EmissionsTrackerPlugin(log_level="info", save_to_file=False)
])
@scheduler.on_start
def on_start():
task.submit(5) # Submit any args here
@task.on_submitted
def on_submitted(future, *args, **kwargs):
print(f"Task was submitted", future, args, kwargs)
@task.on_done
def on_done(future):
# Result is the return value of the function
print("Task done: ", future.result())
scheduler.run()
PARAMETER | DESCRIPTION |
---|---|
*args |
Additional arguments to pass to codecarbon library.
TYPE:
|
**kwargs |
Additional keyword arguments to pass to codecarbon library.
TYPE:
|
You can pass any codecarbon parameters as args to EmissionsTrackerPlugin. Please refer to the official codecarbon documentation for more details: mlco2.github.io/codecarbon/parameters.html
Source code in src/amltk/scheduling/plugins/emissions_tracker_plugin.py
name
class-attribute
instance-attribute
#
name: ClassVar = 'emissions-tracker'
The name of the plugin.
__rich__
#
Return a rich panel.
Source code in src/amltk/scheduling/plugins/emissions_tracker_plugin.py
copy
#
events
#
Return a list of events that this plugin emits.
Likely no need to override this method, as it will automatically return all events defined on the plugin.