MCPcopy Create free account
hub / github.com/mlco2/codecarbon / OfflineEmissionsTracker

Class OfflineEmissionsTracker

codecarbon/emissions_tracker.py:1261–1366  ·  view source on GitHub ↗

Offline implementation of the `EmissionsTracker` In addition to the standard arguments, the following are required.

Source from the content-addressed store, hash-verified

1259
1260
1261class OfflineEmissionsTracker(BaseEmissionsTracker):
1262 """
1263 Offline implementation of the `EmissionsTracker`
1264 In addition to the standard arguments, the following are required.
1265 """
1266
1267 _country_iso_code = None
1268 _country_name, _region, country_2letter_iso_code = None, None, None
1269
1270 @suppress(Exception)
1271 def __init__(
1272 self,
1273 *args,
1274 country_iso_code: Optional[str] = _sentinel,
1275 region: Optional[str] = _sentinel,
1276 cloud_provider: Optional[str] = _sentinel,
1277 cloud_region: Optional[str] = _sentinel,
1278 country_2letter_iso_code: Optional[str] = _sentinel,
1279 **kwargs,
1280 ):
1281 """
1282 :param country_iso_code: 3-letter ISO code of the country where the experiment
1283 is being run. See global_energy_mix.json for available
1284 countries.
1285 :param region: Optional Province/State/City where the infrastructure is hosted.
1286 Supported for US States and Canada (e.g. California, New York).
1287 :param cloud_provider: The cloud provider specified for estimating emissions
1288 intensity, defaults to None.
1289 See https://github.com/mlco2/codecarbon/
1290 blob/master/codecarbon/data/cloud/impact.csv
1291 for a list of cloud providers
1292 :param cloud_region: The region of the cloud data center, defaults to None.
1293 See https://github.com/mlco2/codecarbon/
1294 blob/master/codecarbon/data/cloud/impact.csv
1295 for a list of cloud regions.
1296 :param country_2letter_iso_code: For use with the Electricity Maps emissions API.
1297 See http://api.electricitymap.org/v3/zones for
1298 a list of codes and their corresponding
1299 locations.
1300 """
1301 self._external_conf = get_hierarchical_config()
1302 self._set_from_conf(cloud_provider, "cloud_provider")
1303 self._set_from_conf(cloud_region, "cloud_region")
1304 self._set_from_conf(country_2letter_iso_code, "country_2letter_iso_code")
1305 self._set_from_conf(country_iso_code, "country_iso_code")
1306 self._set_from_conf(region, "region")
1307
1308 logger.info("offline tracker init")
1309
1310 if self._region is not None:
1311 assert isinstance(self._region, str)
1312 self._region: str = self._region.lower()
1313
1314 if self._cloud_provider:
1315 if self._cloud_region is None:
1316 logger.error(
1317 "Cloud Region must be provided " + " if cloud provider is set"
1318 )

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…