codecarbon 3.2.9__tar.gz → 3.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {codecarbon-3.2.9 → codecarbon-3.3.1}/PKG-INFO +46 -16
  2. {codecarbon-3.2.9 → codecarbon-3.3.1}/README.md +45 -15
  3. codecarbon-3.3.1/codecarbon/_version.py +1 -0
  4. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/cli/auth.py +10 -2
  5. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/cli/main.py +94 -22
  6. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/cli/monitor.py +8 -4
  7. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/api_client.py +59 -82
  8. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/config.py +85 -30
  9. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/cpu.py +80 -1
  10. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/hardware_cache.py +5 -0
  11. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/powermetrics.py +91 -48
  12. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/rapl.py +48 -0
  13. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/resource_tracker.py +26 -9
  14. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/util.py +1 -1
  15. codecarbon-3.3.1/codecarbon/core/windows_emi.py +606 -0
  16. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/hardware/cpu_power.csv +13 -0
  17. codecarbon-3.3.1/codecarbon/data/private_infra/nordic_emissions.json +89 -0
  18. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/emissions_tracker.py +44 -11
  19. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/hardware.py +13 -3
  20. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/ram.py +1 -3
  21. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/file.py +2 -1
  22. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/PKG-INFO +46 -16
  23. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/SOURCES.txt +2 -0
  24. {codecarbon-3.2.9 → codecarbon-3.3.1}/pyproject.toml +5 -6
  25. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_api_call.py +236 -16
  26. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_config.py +75 -28
  27. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_core_util.py +22 -0
  28. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_cpu.py +55 -0
  29. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_cpu_load.py +2 -0
  30. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_electricitymaps_config_backward_compatibility.py +4 -8
  31. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_emissions.py +4 -2
  32. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_emissions_tracker.py +45 -0
  33. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_emissions_tracker_constant.py +33 -0
  34. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_hardware_cache.py +18 -0
  35. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_logger.py +1 -1
  36. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_powermetrics.py +81 -8
  37. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_ram.py +21 -12
  38. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_rapl_mmio_scanning.py +179 -0
  39. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_resource_tracker.py +53 -2
  40. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_tracking_inference.py +4 -1
  41. codecarbon-3.3.1/tests/test_windows_emi.py +672 -0
  42. codecarbon-3.2.9/codecarbon/_version.py +0 -1
  43. codecarbon-3.2.9/codecarbon/data/private_infra/nordic_emissions.json +0 -69
  44. {codecarbon-3.2.9 → codecarbon-3.3.1}/LICENSE +0 -0
  45. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/__init__.py +0 -0
  46. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/cli/__init__.py +0 -0
  47. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/cli/cli_utils.py +0 -0
  48. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/__init__.py +0 -0
  49. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/cloud.py +0 -0
  50. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/electricitymaps_api.py +0 -0
  51. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/emissions.py +0 -0
  52. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/gpu.py +0 -0
  53. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/gpu_amd.py +0 -0
  54. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/gpu_device.py +0 -0
  55. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/gpu_nvidia.py +0 -0
  56. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/measure.py +0 -0
  57. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/schemas.py +0 -0
  58. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/telemetry_client.py +0 -0
  59. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/telemetry_schemas.py +0 -0
  60. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/core/units.py +0 -0
  61. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/canada_provinces.geojson +0 -0
  62. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/cloud/impact.csv +0 -0
  63. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/hardware/cpu_dataset_builder/amd_cpu_scrapper.py +0 -0
  64. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/hardware/cpu_dataset_builder/intel_cpu_scrapper.py +0 -0
  65. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/hardware/cpu_dataset_builder/merge_scrapped_cpu_power.py +0 -0
  66. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/private_infra/2016/usa_emissions.json +0 -0
  67. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/private_infra/2023/canada_energy_mix.json +0 -0
  68. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/private_infra/carbon_intensity_per_source.json +0 -0
  69. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/data/private_infra/global_energy_mix.json +0 -0
  70. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/__init__.py +0 -0
  71. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/geography.py +0 -0
  72. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/logger.py +0 -0
  73. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/scheduler.py +0 -0
  74. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/external/task.py +0 -0
  75. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/input.py +0 -0
  76. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/lock.py +0 -0
  77. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output.py +0 -0
  78. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/__init__.py +0 -0
  79. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/base_output.py +0 -0
  80. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/boamps/__init__.py +0 -0
  81. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/boamps/mapper.py +0 -0
  82. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/boamps/models.py +0 -0
  83. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/boamps/output.py +0 -0
  84. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/emissions_data.py +0 -0
  85. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/http.py +0 -0
  86. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/logger.py +0 -0
  87. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/metrics/__init__.py +0 -0
  88. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/metrics/logfire.py +0 -0
  89. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/metrics/metric_docs.py +0 -0
  90. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/output_methods/metrics/prometheus.py +0 -0
  91. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/py.typed +0 -0
  92. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/__init__.py +0 -0
  93. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/assets/__init__.py +0 -0
  94. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/assets/car_icon.png +0 -0
  95. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/assets/house_icon.png +0 -0
  96. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/assets/tv_icon.png +0 -0
  97. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/carbonboard.py +0 -0
  98. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/carbonboard_on_api.py +0 -0
  99. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/components.py +0 -0
  100. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/data.py +0 -0
  101. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon/viz/units.py +0 -0
  102. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/dependency_links.txt +0 -0
  103. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/entry_points.txt +0 -0
  104. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/requires.txt +0 -0
  105. {codecarbon-3.2.9 → codecarbon-3.3.1}/codecarbon.egg-info/top_level.txt +0 -0
  106. {codecarbon-3.2.9 → codecarbon-3.3.1}/setup.cfg +0 -0
  107. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_boamps_output.py +0 -0
  108. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_cloud.py +0 -0
  109. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_custom_handler.py +0 -0
  110. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_docs_examples.py +0 -0
  111. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_electricitymaps_api.py +0 -0
  112. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_electricitymaps_backward_compatibility.py +0 -0
  113. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_emissions_tracker_flush.py +0 -0
  114. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_energy.py +0 -0
  115. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_geography.py +0 -0
  116. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_gpu.py +0 -0
  117. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_gpu_amd.py +0 -0
  118. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_gpu_nvidia.py +0 -0
  119. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_input.py +0 -0
  120. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_lock.py +0 -0
  121. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_logging_output.py +0 -0
  122. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_offline_emissions_tracker.py +0 -0
  123. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_package_integrity.py +0 -0
  124. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_rapl_parameters.py +0 -0
  125. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_rapl_permissions.py +0 -0
  126. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_telemetry_client.py +0 -0
  127. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_unsupported_gpu.py +0 -0
  128. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_utilization_tracking.py +0 -0
  129. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_viz_data.py +0 -0
  130. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/test_viz_units.py +0 -0
  131. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/testdata.py +0 -0
  132. {codecarbon-3.2.9 → codecarbon-3.3.1}/tests/testutils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codecarbon
3
- Version: 3.2.9
3
+ Version: 3.3.1
4
4
  Author: Mila, DataForGood, BCG GAMMA, Comet.ml, Haverford College
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://codecarbon.io/
@@ -137,18 +137,19 @@ You can visualize your experiment emissions on the [dashboard](https://dashboard
137
137
 
138
138
  ## Quick links
139
139
 
140
- | Section | Description |
141
- |---------|-------------|
142
- | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
143
- | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
144
- | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
145
- | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
140
+ | Section | Description |
141
+ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------ |
142
+ | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
143
+ | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
144
+ | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
145
+ | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
146
146
  | [Comparing Model Efficiency](https://docs.codecarbon.io/latest/tutorials/comparing-model-efficiency/) | Measure carbon efficiency across ML models |
147
- | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
148
- | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
149
- | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
150
- | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
151
- | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
147
+ | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
148
+ | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
149
+ | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
150
+ | [When to use CodeCarbon vs EcoLogits](https://docs.codecarbon.io/latest/explanation/when-to-use/) | Choose the right tool |
151
+ | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
152
+ | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
152
153
 
153
154
  ## Links
154
155
 
@@ -156,6 +157,7 @@ You can visualize your experiment emissions on the [dashboard](https://dashboard
156
157
  - [Dashboard](https://dashboard.codecarbon.io/) to see your emissions.
157
158
  - [Documentation](https://docs.codecarbon.io/) to learn how to use the package and our methodology.
158
159
  - [EcoLogits](https://ecologits.ai/) to track emissions from GenAI API calls (OpenAI, Anthropic, etc.).
160
+ - [mlco2 on GitHub](https://github.com/mlco2) for our other open-source projects.
159
161
  - [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
160
162
  - [Discord](https://discord.gg/GS9js2XkJR) to chat with us.
161
163
 
@@ -210,7 +212,7 @@ If you find CodeCarbon useful for your research, you can find a citation under a
210
212
  MinervaBooks},
211
213
  title = {mlco2/codecarbon: v2.4.1},
212
214
  month = may,
213
- year = 2024,
215
+ year = {2024},
214
216
  publisher = {Zenodo},
215
217
  version = {v2.4.1},
216
218
  doi = {10.5281/zenodo.11171501},
@@ -228,6 +230,34 @@ Codecarbon was formerly developed by volunteers from [**Mila**](http://mila.queb
228
230
 
229
231
  Now CodeCarbon is supported by [**Code Carbon**](https://www.helloasso.com/associations/code-carbon), a French non-profit organization whose mission is to accelerate the development and adoption of CodeCarbon.
230
232
 
231
- ### Star History
232
-
233
- [![Star History Chart](https://api.star-history.com/svg?repos=mlco2/codecarbon,lfwa/carbontracker,sb-ai-lab/Eco2AI,fvaleye/tracarbon,Breakend/experiment-impact-tracker&type=Date)](https://star-history.com/#mlco2/codecarbon&lfwa/carbontracker&sb-ai-lab/Eco2AI&fvaleye/tracarbon&Breakend/experiment-impact-tracker&Date)
233
+ ## Sponsors
234
+
235
+ <div align="center">
236
+ <a href="https://www.clever-cloud.com/">
237
+ <picture>
238
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/clever_cloud.png">
239
+ <img src="https://cdn.clever-cloud.com/uploads/2023/03/logoonwhite.svg" alt="Clever Cloud" height="48">
240
+ </picture>
241
+ </a>
242
+ &nbsp;&nbsp;&nbsp;
243
+ <a href="https://dataforgood.fr/">
244
+ <picture>
245
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/dataforgood.png">
246
+ <img src="https://dataforgood.fr/images/dataforgood.svg" alt="Data For Good" height="48">
247
+ </picture>
248
+ </a>
249
+ &nbsp;&nbsp;&nbsp;
250
+ <a href="https://github.com/">
251
+ <picture>
252
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/GitHub.png">
253
+ <img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png" alt="GitHub" height="48">
254
+ </picture>
255
+ </a>
256
+ &nbsp;&nbsp;&nbsp;
257
+ <a href="https://www.mozilla.org/">
258
+ <picture>
259
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/mozilla.svg">
260
+ <img src="https://upload.wikimedia.org/wikipedia/commons/d/df/Mozilla_2024_logo.svg" alt="Mozilla" height="48">
261
+ </picture>
262
+ </a>
263
+ </div>
@@ -90,18 +90,19 @@ You can visualize your experiment emissions on the [dashboard](https://dashboard
90
90
 
91
91
  ## Quick links
92
92
 
93
- | Section | Description |
94
- |---------|-------------|
95
- | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
96
- | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
97
- | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
98
- | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
93
+ | Section | Description |
94
+ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------ |
95
+ | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
96
+ | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
97
+ | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
98
+ | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
99
99
  | [Comparing Model Efficiency](https://docs.codecarbon.io/latest/tutorials/comparing-model-efficiency/) | Measure carbon efficiency across ML models |
100
- | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
101
- | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
102
- | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
103
- | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
104
- | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
100
+ | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
101
+ | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
102
+ | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
103
+ | [When to use CodeCarbon vs EcoLogits](https://docs.codecarbon.io/latest/explanation/when-to-use/) | Choose the right tool |
104
+ | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
105
+ | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
105
106
 
106
107
  ## Links
107
108
 
@@ -109,6 +110,7 @@ You can visualize your experiment emissions on the [dashboard](https://dashboard
109
110
  - [Dashboard](https://dashboard.codecarbon.io/) to see your emissions.
110
111
  - [Documentation](https://docs.codecarbon.io/) to learn how to use the package and our methodology.
111
112
  - [EcoLogits](https://ecologits.ai/) to track emissions from GenAI API calls (OpenAI, Anthropic, etc.).
113
+ - [mlco2 on GitHub](https://github.com/mlco2) for our other open-source projects.
112
114
  - [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
113
115
  - [Discord](https://discord.gg/GS9js2XkJR) to chat with us.
114
116
 
@@ -163,7 +165,7 @@ If you find CodeCarbon useful for your research, you can find a citation under a
163
165
  MinervaBooks},
164
166
  title = {mlco2/codecarbon: v2.4.1},
165
167
  month = may,
166
- year = 2024,
168
+ year = {2024},
167
169
  publisher = {Zenodo},
168
170
  version = {v2.4.1},
169
171
  doi = {10.5281/zenodo.11171501},
@@ -181,6 +183,34 @@ Codecarbon was formerly developed by volunteers from [**Mila**](http://mila.queb
181
183
 
182
184
  Now CodeCarbon is supported by [**Code Carbon**](https://www.helloasso.com/associations/code-carbon), a French non-profit organization whose mission is to accelerate the development and adoption of CodeCarbon.
183
185
 
184
- ### Star History
185
-
186
- [![Star History Chart](https://api.star-history.com/svg?repos=mlco2/codecarbon,lfwa/carbontracker,sb-ai-lab/Eco2AI,fvaleye/tracarbon,Breakend/experiment-impact-tracker&type=Date)](https://star-history.com/#mlco2/codecarbon&lfwa/carbontracker&sb-ai-lab/Eco2AI&fvaleye/tracarbon&Breakend/experiment-impact-tracker&Date)
186
+ ## Sponsors
187
+
188
+ <div align="center">
189
+ <a href="https://www.clever-cloud.com/">
190
+ <picture>
191
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/clever_cloud.png">
192
+ <img src="https://cdn.clever-cloud.com/uploads/2023/03/logoonwhite.svg" alt="Clever Cloud" height="48">
193
+ </picture>
194
+ </a>
195
+ &nbsp;&nbsp;&nbsp;
196
+ <a href="https://dataforgood.fr/">
197
+ <picture>
198
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/dataforgood.png">
199
+ <img src="https://dataforgood.fr/images/dataforgood.svg" alt="Data For Good" height="48">
200
+ </picture>
201
+ </a>
202
+ &nbsp;&nbsp;&nbsp;
203
+ <a href="https://github.com/">
204
+ <picture>
205
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/GitHub.png">
206
+ <img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png" alt="GitHub" height="48">
207
+ </picture>
208
+ </a>
209
+ &nbsp;&nbsp;&nbsp;
210
+ <a href="https://www.mozilla.org/">
211
+ <picture>
212
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mlco2/codecarbon-landing-page/main/public/assets/partners/mozilla.svg">
213
+ <img src="https://upload.wikimedia.org/wikipedia/commons/d/df/Mozilla_2024_logo.svg" alt="Mozilla" height="48">
214
+ </picture>
215
+ </a>
216
+ </div>
@@ -0,0 +1 @@
1
+ __version__ = "3.3.1"
@@ -86,8 +86,15 @@ def _discover_endpoints():
86
86
 
87
87
  def _save_credentials(tokens):
88
88
  """Save OAuth tokens to the local credentials file."""
89
- with open(_CREDENTIALS_FILE, "w") as f:
90
- json.dump(tokens, f)
89
+ try:
90
+ with open(_CREDENTIALS_FILE, "w") as f:
91
+ json.dump(tokens, f)
92
+ except OSError as e:
93
+ raise ValueError(
94
+ f"Could not write the credentials file {_CREDENTIALS_FILE.resolve()} "
95
+ f"(error: {e}). Please run the command from a directory you can "
96
+ "write to."
97
+ )
91
98
 
92
99
 
93
100
  def _load_credentials():
@@ -169,6 +176,7 @@ def authorize():
169
176
  server = HTTPServer(("localhost", _REDIRECT_PORT), _CallbackHandler)
170
177
 
171
178
  print("Opening browser for authentication...")
179
+ print(f"If no browser opens, copy this URL into your browser:\n{uri}")
172
180
  webbrowser.open(uri)
173
181
 
174
182
  server.handle_request()
@@ -40,6 +40,20 @@ def main():
40
40
  raise sys.exit(1)
41
41
 
42
42
 
43
+ def _api_call(action: str, func, *args, **kwargs):
44
+ """
45
+ Run a call to the Code Carbon API, turning the errors it now raises into a
46
+ readable message and a clean exit instead of a traceback.
47
+
48
+ :action: what was being attempted, used as the first part of the message.
49
+ """
50
+ try:
51
+ return func(*args, **kwargs)
52
+ except Exception as e:
53
+ print(f"[yellow]{action}[/yellow]. (error: {e})")
54
+ raise typer.Exit(1)
55
+
56
+
43
57
  def _version_callback(value: bool) -> None:
44
58
  if value:
45
59
  print(f"{__app_name__} v{__version__}")
@@ -116,7 +130,7 @@ def api_get():
116
130
  api_endpoint = get_api_endpoint()
117
131
  api = ApiClient(endpoint_url=api_endpoint)
118
132
  api.set_access_token(get_access_token())
119
- organizations = api.get_list_organizations()
133
+ organizations = _api_call("API request failed", api.get_list_organizations)
120
134
  print(organizations)
121
135
 
122
136
 
@@ -130,7 +144,7 @@ def login():
130
144
  api = ApiClient(endpoint_url=api_endpoint)
131
145
  access_token = get_access_token()
132
146
  api.set_access_token(access_token)
133
- api.check_auth()
147
+ _api_call("Authentication check failed", api.check_auth)
134
148
 
135
149
 
136
150
  def get_api_key(project_id: str):
@@ -149,6 +163,7 @@ def get_api_key(project_id: str):
149
163
  },
150
164
  headers={"Authorization": f"Bearer {get_access_token()}"},
151
165
  )
166
+ req.raise_for_status()
152
167
  api_key = req.json()["token"]
153
168
  return api_key
154
169
 
@@ -212,7 +227,10 @@ def config():
212
227
  overwrite_local_config("api_endpoint", api_endpoint, path=file_path)
213
228
  api = ApiClient(endpoint_url=api_endpoint)
214
229
  api.set_access_token(get_access_token())
215
- organizations = api.get_list_organizations()
230
+ organizations = _api_call(
231
+ "Could not list organizations from API. Please check your login and API endpoint",
232
+ api.get_list_organizations,
233
+ )
216
234
  org = questionary_prompt(
217
235
  "Pick existing organization from list or Create new organization ?",
218
236
  [org["name"] for org in organizations] + ["Create New Organization"],
@@ -229,18 +247,23 @@ def config():
229
247
  name=org_name,
230
248
  description=org_description,
231
249
  )
232
- organization = api.create_organization(organization=organization_create)
233
- if organization is None:
234
- print("Error creating organization")
235
- return
250
+ organization = _api_call(
251
+ "Could not create the organization",
252
+ api.create_organization,
253
+ organization=organization_create,
254
+ )
236
255
  print(f"Created organization : {organization}")
237
256
  else:
238
257
  organization = [orga for orga in organizations if orga["name"] == org][0]
239
258
  org_id = organization["id"]
240
259
  overwrite_local_config("organization_id", org_id, path=file_path)
241
260
 
242
- projects = api.list_projects_from_organization(org_id)
243
- project_names = [project["name"] for project in projects] if projects else []
261
+ projects = _api_call(
262
+ "Could not list projects from API",
263
+ api.list_projects_from_organization,
264
+ org_id,
265
+ )
266
+ project_names = [project["name"] for project in projects]
244
267
  project = questionary_prompt(
245
268
  "Pick existing project from list or Create new project ?",
246
269
  project_names + ["Create New Project"],
@@ -256,17 +279,21 @@ def config():
256
279
  description=project_description,
257
280
  organization_id=org_id,
258
281
  )
259
- project = api.create_project(project=project_create)
282
+ project = _api_call(
283
+ "Could not create the project", api.create_project, project=project_create
284
+ )
260
285
  print(f"Created project : {project}")
261
286
  else:
262
287
  project = [p for p in projects if p["name"] == project][0]
263
288
  project_id = project["id"]
264
289
  overwrite_local_config("project_id", project_id, path=file_path)
265
290
 
266
- experiments = api.list_experiments_from_project(project_id)
267
- experiments_names = (
268
- [experiment["name"] for experiment in experiments] if experiments else []
291
+ experiments = _api_call(
292
+ "Could not list experiments from API",
293
+ api.list_experiments_from_project,
294
+ project_id,
269
295
  )
296
+ experiments_names = [experiment["name"] for experiment in experiments]
270
297
 
271
298
  experiment = questionary_prompt(
272
299
  "Pick existing experiment from list or Create new experiment ?",
@@ -313,13 +340,17 @@ def config():
313
340
  cloud_provider=cloud_provider,
314
341
  cloud_region=cloud_region,
315
342
  )
316
- experiment = api.add_experiment(experiment=experiment_create)
343
+ experiment = _api_call(
344
+ "Could not create the experiment",
345
+ api.add_experiment,
346
+ experiment=experiment_create,
347
+ )
317
348
 
318
349
  else:
319
350
  experiment = [e for e in experiments if e["name"] == experiment][0]
320
351
 
321
352
  overwrite_local_config("experiment_id", experiment["id"], path=file_path)
322
- api_key = get_api_key(project_id)
353
+ api_key = _api_call("Could not get the project API key", get_api_key, project_id)
323
354
  overwrite_local_config("api_key", api_key, path=file_path)
324
355
  show_config(file_path)
325
356
  print(
@@ -327,6 +358,34 @@ def config():
327
358
  )
328
359
 
329
360
 
361
+ def _cli_provided(ctx, name: str) -> bool:
362
+ """
363
+ Whether the option `name` was typed on the command line (or set through its
364
+ environment variable) rather than left at its Typer default.
365
+
366
+ Options left at their default must not be forwarded to the tracker: doing so
367
+ would silently override the values coming from `.codecarbon.config` and the
368
+ `CODECARBON_*` environment variables, which the tracker reads itself.
369
+ """
370
+ get_source = getattr(ctx, "get_parameter_source", None)
371
+ if get_source is None:
372
+ # `monitor` called directly from Python, not through Click: every value
373
+ # given is explicit.
374
+ return True
375
+ source = get_source(name)
376
+ return source is None or source.name in ("COMMANDLINE", "ENVIRONMENT")
377
+
378
+
379
+ def _external_config() -> dict:
380
+ """The configuration files and CODECARBON_* variables, as a plain dict."""
381
+ from codecarbon.core.config import get_hierarchical_config
382
+
383
+ try:
384
+ return dict(get_hierarchical_config())
385
+ except Exception:
386
+ return {}
387
+
388
+
330
389
  @codecarbon.command(
331
390
  "monitor",
332
391
  short_help="Monitor your machine's carbon emissions.",
@@ -362,15 +421,28 @@ def monitor(
362
421
  ):
363
422
  """Monitor your machine's carbon emissions."""
364
423
 
365
- # Shared tracker args so monitor and run_and_monitor behave the same
424
+ external_conf = _external_config()
425
+
426
+ # Shared tracker args so monitor and run_and_monitor behave the same.
427
+ # Only the options actually given are forwarded: the others are left to the
428
+ # tracker, which resolves them from the configuration file and environment.
429
+ cli_defaults = (
430
+ ("measure_power_secs", measure_power_secs),
431
+ ("api_call_interval", api_call_interval),
432
+ ("log_level", log_level),
433
+ )
366
434
  tracker_args = {
367
- "measure_power_secs": measure_power_secs,
368
- "api_call_interval": api_call_interval,
369
- "log_level": log_level,
435
+ name: value for name, value in cli_defaults if _cli_provided(ctx, name)
370
436
  }
437
+ for name, value in cli_defaults:
438
+ if name not in tracker_args and name not in external_conf:
439
+ # Nothing configures it: keep the defaults advertised by `--help`
440
+ # (and an unattended monitor quiet) instead of the tracker's own.
441
+ tracker_args[name] = value
442
+
371
443
  # Set up the tracker arguments based on mode (offline vs online) and validate required args for each mode
372
444
  if offline:
373
- if not country_iso_code:
445
+ if not country_iso_code and not external_conf.get("country_iso_code"):
374
446
  print(
375
447
  "ERROR: Country ISO code is required for offline mode. Add it to your configuration or provide it via the command line: `--country-iso-code FRA`",
376
448
  file=sys.stderr,
@@ -379,8 +451,8 @@ def monitor(
379
451
 
380
452
  tracker_args = {
381
453
  **tracker_args,
382
- "country_iso_code": country_iso_code,
383
- "region": region,
454
+ **({"country_iso_code": country_iso_code} if country_iso_code else {}),
455
+ **({"region": region} if region else {}),
384
456
  }
385
457
  else:
386
458
  experiment_id = get_existing_exp_id()
@@ -3,6 +3,7 @@
3
3
  import os
4
4
  import subprocess
5
5
  import sys
6
+ from typing import Optional
6
7
 
7
8
  import typer
8
9
  from rich import print
@@ -12,9 +13,9 @@ from typing_extensions import Annotated
12
13
  def run_and_monitor(
13
14
  ctx: typer.Context,
14
15
  log_level: Annotated[
15
- str,
16
+ Optional[str],
16
17
  typer.Option(help="Log level (critical, error, warning, info, debug)"),
17
- ] = "error",
18
+ ] = None,
18
19
  offline: bool = False,
19
20
  **tracker_args,
20
21
  ):
@@ -51,7 +52,11 @@ def run_and_monitor(
51
52
  from codecarbon.emissions_tracker import EmissionsTracker, OfflineEmissionsTracker
52
53
  from codecarbon.external.logger import set_logger_level
53
54
 
54
- set_logger_level(log_level)
55
+ # `log_level` is None when nothing set it: leave it to the tracker, which
56
+ # resolves it from the configuration file and the environment.
57
+ if log_level is not None:
58
+ set_logger_level(log_level)
59
+ tracker_args["log_level"] = log_level
55
60
 
56
61
  # Get the command from remaining args (strip nested subcommand / `--` leftovers)
57
62
  command = list(getattr(ctx, "args", None) or [])
@@ -67,7 +72,6 @@ def run_and_monitor(
67
72
 
68
73
  tracker_cls = OfflineEmissionsTracker if offline else EmissionsTracker
69
74
  tracker = tracker_cls(
70
- log_level=log_level,
71
75
  save_to_logger=False,
72
76
  tracking_mode="process",
73
77
  **tracker_args,