2020from codecarbon .core .units import Energy , Power , Time
2121from codecarbon .core .util import count_cpus , count_physical_cpus , suppress
2222from codecarbon .external .geography import CloudMetadata , GeoMetadata
23- from codecarbon .external .hardware import CPU , GPU , RAM , AppleSiliconChip
23+ from codecarbon .external .hardware import CPU , GPU , AppleSiliconChip
2424from codecarbon .external .logger import logger , set_logger_format , set_logger_level
25+ from codecarbon .external .ram import RAM
2526from codecarbon .external .scheduler import PeriodicScheduler
2627from codecarbon .external .task import Task
2728from codecarbon .input import DataSource
@@ -171,7 +172,8 @@ def __init__(
171172 log_level : Optional [Union [int , str ]] = _sentinel ,
172173 on_csv_write : Optional [str ] = _sentinel ,
173174 logger_preamble : Optional [str ] = _sentinel ,
174- default_cpu_power : Optional [int ] = _sentinel ,
175+ force_cpu_power : Optional [int ] = _sentinel ,
176+ force_ram_power : Optional [int ] = _sentinel ,
175177 pue : Optional [int ] = _sentinel ,
176178 force_mode_cpu_load : Optional [bool ] = _sentinel ,
177179 allow_multiple_runs : Optional [bool ] = _sentinel ,
@@ -227,7 +229,8 @@ def __init__(
227229 Accepts one of "append" or "update". Default is "append".
228230 :param logger_preamble: String to systematically include in the logger.
229231 messages. Defaults to "".
230- :param default_cpu_power: cpu power to be used as default if the cpu is not known.
232+ :param force_cpu_power: cpu power to be used instead of automatic detection.
233+ :param force_ram_power: ram power to be used instead of automatic detection.
231234 :param pue: PUE (Power Usage Effectiveness) of the datacenter.
232235 :param force_mode_cpu_load: Force the addition of a CPU in MODE_CPU_LOAD
233236 :param allow_multiple_runs: Allow multiple instances of codecarbon running in parallel. Defaults to False.
@@ -277,7 +280,8 @@ def __init__(
277280 self ._set_from_conf (tracking_mode , "tracking_mode" , "machine" )
278281 self ._set_from_conf (on_csv_write , "on_csv_write" , "append" )
279282 self ._set_from_conf (logger_preamble , "logger_preamble" , "" )
280- self ._set_from_conf (default_cpu_power , "default_cpu_power" )
283+ self ._set_from_conf (force_cpu_power , "force_cpu_power" )
284+ self ._set_from_conf (force_ram_power , "force_ram_power" )
281285 self ._set_from_conf (pue , "pue" , 1.0 , float )
282286 self ._set_from_conf (force_mode_cpu_load , "force_mode_cpu_load" , False )
283287 self ._set_from_conf (
@@ -521,6 +525,15 @@ def flush(self) -> Optional[float]:
521525 but keep running the experiment.
522526 :return: CO2 emissions in kgs
523527 """
528+ # if another instance of codecarbon is already running, Nothing to do here
529+ if (
530+ hasattr (self , "_another_instance_already_running" )
531+ and self ._another_instance_already_running
532+ ):
533+ logger .warning (
534+ "Another instance of codecarbon is already running. Exiting."
535+ )
536+ return
524537 if self ._start_time is None :
525538 logger .error ("You first need to start the tracker." )
526539 return None
@@ -996,15 +1009,16 @@ def track_emissions(
9961009 log_level : Optional [Union [int , str ]] = _sentinel ,
9971010 on_csv_write : Optional [str ] = _sentinel ,
9981011 logger_preamble : Optional [str ] = _sentinel ,
999- default_cpu_power : Optional [int ] = _sentinel ,
1000- pue : Optional [int ] = _sentinel ,
1001- allow_multiple_runs : Optional [bool ] = _sentinel ,
10021012 offline : Optional [bool ] = _sentinel ,
10031013 country_iso_code : Optional [str ] = _sentinel ,
10041014 region : Optional [str ] = _sentinel ,
10051015 cloud_provider : Optional [str ] = _sentinel ,
10061016 cloud_region : Optional [str ] = _sentinel ,
10071017 country_2letter_iso_code : Optional [str ] = _sentinel ,
1018+ force_cpu_power : Optional [int ] = _sentinel ,
1019+ force_ram_power : Optional [int ] = _sentinel ,
1020+ pue : Optional [int ] = _sentinel ,
1021+ allow_multiple_runs : Optional [bool ] = _sentinel ,
10081022):
10091023 """
10101024 Decorator that supports both `EmissionsTracker` and `OfflineEmissionsTracker`
@@ -1057,8 +1071,6 @@ def track_emissions(
10571071 Accepts one of "append" or "update". Default is "append".
10581072 :param logger_preamble: String to systematically include in the logger.
10591073 messages. Defaults to "".
1060- :param default_cpu_power: cpu power to be used as default if the cpu is not known.
1061- :param pue: PUE (Power Usage Effectiveness) of the datacenter.
10621074 :param allow_multiple_runs: Prevent multiple instances of codecarbon running. Defaults to False.
10631075 :param offline: Indicates if the tracker should be run in offline mode.
10641076 :param country_iso_code: 3 letter ISO Code of the country where the experiment is
@@ -1078,6 +1090,10 @@ def track_emissions(
10781090 See http://api.electricitymap.org/v3/zones for
10791091 a list of codes and their corresponding
10801092 locations.
1093+ :param force_cpu_power: cpu power to be used instead of automatic detection.
1094+ :param force_ram_power: ram power to be used instead of automatic detection.
1095+ :param pue: PUE (Power Usage Effectiveness) of the datacenter.
1096+ :param allow_multiple_runs: Prevent multiple instances of codecarbon running. Defaults to False.
10811097
10821098 :return: The decorated function
10831099 """
@@ -1109,14 +1125,16 @@ def wrapped_fn(*args, **kwargs):
11091125 log_level = log_level ,
11101126 on_csv_write = on_csv_write ,
11111127 logger_preamble = logger_preamble ,
1112- default_cpu_power = default_cpu_power ,
11131128 pue = pue ,
1114- allow_multiple_runs = allow_multiple_runs ,
11151129 country_iso_code = country_iso_code ,
11161130 region = region ,
11171131 cloud_provider = cloud_provider ,
11181132 cloud_region = cloud_region ,
11191133 country_2letter_iso_code = country_2letter_iso_code ,
1134+ force_cpu_power = force_cpu_power ,
1135+ force_ram_power = force_ram_power ,
1136+ pue = pue ,
1137+ allow_multiple_runs = allow_multiple_runs ,
11201138 )
11211139 else :
11221140 tracker = EmissionsTracker (
@@ -1144,7 +1162,8 @@ def wrapped_fn(*args, **kwargs):
11441162 log_level = log_level ,
11451163 on_csv_write = on_csv_write ,
11461164 logger_preamble = logger_preamble ,
1147- default_cpu_power = default_cpu_power ,
1165+ force_cpu_power = force_cpu_power ,
1166+ force_ram_power = force_ram_power ,
11481167 pue = pue ,
11491168 allow_multiple_runs = allow_multiple_runs ,
11501169 )
0 commit comments