carbonai.PowerMeter

class carbonai.PowerMeter(project_name='', program_name='', client_name='', user_name='', cpu_power_log_path='', powerlog_save_path='', get_country=True, location='', is_online=True, filepath=None, output_format='csv', api_endpoint=None)

PowerMeter is a general tool to monitor and log the power consumption of any given function.

Depending on the platform and hardware used, it allows to measure the power usage of the CPU,the DRAM and the GPU. The measure is, then, converted to CO2 emissions depending on the country set and the PUE of the machine (background on the PUE here). You can chose to log the results locally or send it to an endpoint.

Parameters
project_namestr, default current_directory_name

Name of the project you are working on.

program_namestr, optional

Name of the program you are working on.

client_namestr, optional

Name of the client you are working for.

user_namestr, default computer_user_name

The name of the user using the tool (for logging purpose).

cpu_power_log_pathstr, optional

The path to the tool “PowerLog” or “powercap” or “IntelPowerGadget”.

powerlog_save_path: str, optional

Path to the folder where we should find the logs provided by IntelPowerGadget.

get_countrybool, default True

Whether to retrieve user country location or not (uses the user IP).

locationstr, optional

Country ISO Code available here

Must be set if get_country is False.

is_onlineboolean, default True

Whether the machine is connected to the internet or not.

filepathstr, default .

Path of the file where all the carbon logs will be written.

output_format{‘csv’, ‘excel’}, default ‘csv’

Format of the carbon logs file produced.

api_endpointstr, optional

Endpoint of the API to upload the collected data to

Note: we provide an endpoint to collect data and contribute, with the community, towards greener algorithms. Here is the url : https://ngji0jx9dc.execute-api.eu-west-3.amazonaws.com/post_new_item

See also

PowerMeter.from_config

Create a power meter from a config file.

Notes

This package may log private data (username, country, project_name). If you do not provide any api_endpoint, we will never have access to this data.

On the other hand, if you chose to share your data with us (by using our endpoint: https://ngji0jx9dc.execute-api.eu-west-3.amazonaws.com/post_new_item ), we commit to anonymize any data shared.

Examples

Create a PowerMeter for the project MNIST Classifier while not being online.

>>> power_meter = PowerMeter(project_name="MNIST classifier",
...     is_online=False, location="FR")

Create a PowerMeter for the project Test and send the collected data to our endpoint.

>>> power_meter = PowerMeter(project_name="Test",
...     api_endpoint="https://ngji0jx9dc.execute-
api.eu-west-3.amazonaws.com/post_new_item")

Methods

__call__(package, algorithm[, step, …])

Measure the power usage using a with statement.

from_config(path)

Create a PowerMeter from a json config file.

measure_power(package, algorithm[, step, …])

A decorator to measure the power consumption of a given function

start_measure(package, algorithm[, step, …])

Starts mesuring the power consumption of a given sample of code

stop_measure()

Stops the measure started with PowerMeter.start_measure()