Skip to content

Commit 5e90ef2

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 62653e7 + 014e239 commit 5e90ef2

9 files changed

Lines changed: 1262 additions & 913 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"british columbia": {
3+
"naturalGas": 2.8,
4+
"nuclear": 0.0,
5+
"petroleum": 0.1,
6+
"biomass": 6.7,
7+
"coal": 0.0,
8+
"other": 0.0,
9+
"solar": 0.6,
10+
"tidal": 0.0,
11+
"total": 99.9,
12+
"wind": 2.9,
13+
"hydro": 86.8
14+
},
15+
"newfoundland and labrador": {
16+
"naturalGas": 0.2,
17+
"nuclear": 0.0,
18+
"petroleum": 0.4,
19+
"biomass": 0.0,
20+
"coal": 0.0,
21+
"other": 0.0,
22+
"solar": 0.0,
23+
"tidal": 0.0,
24+
"total": 100.0,
25+
"wind": 0.4,
26+
"hydro": 99.0
27+
},
28+
"saskatchewan": {
29+
"naturalGas": 50.7,
30+
"nuclear": 0.0,
31+
"petroleum": 0.0,
32+
"biomass": 1.2,
33+
"coal": 27.9,
34+
"other": 0.0,
35+
"solar": 0.6,
36+
"tidal": 0.0,
37+
"total": 100.0,
38+
"wind": 3.0,
39+
"hydro": 16.6
40+
},
41+
"prince edward island": {
42+
"naturalGas": 0.0,
43+
"nuclear": 0.0,
44+
"petroleum": 2.2,
45+
"biomass": 0.6,
46+
"coal": 0.0,
47+
"other": 0.0,
48+
"solar": 0.1,
49+
"tidal": 0.0,
50+
"total": 100.2,
51+
"wind": 97.3,
52+
"hydro": 0.0
53+
},
54+
"ontario": {
55+
"naturalGas": 8.6,
56+
"nuclear": 50.1,
57+
"petroleum": 0.1,
58+
"biomass": 1.0,
59+
"coal": 0.0,
60+
"other": 0.0,
61+
"solar": 5.2,
62+
"tidal": 0.0,
63+
"total": 100.1,
64+
"wind": 11.7,
65+
"hydro": 23.4
66+
},
67+
"nova scotia": {
68+
"naturalGas": 13.9,
69+
"nuclear": 0.0,
70+
"petroleum": 0.0,
71+
"biomass": 3.5,
72+
"coal": 47.5,
73+
"other": 0.0,
74+
"solar": 0.02,
75+
"tidal": 0,
76+
"total": 100.02,
77+
"wind": 24.2,
78+
"hydro": 10.9
79+
},
80+
"quebec": {
81+
"naturalGas": 0.2,
82+
"nuclear": 0.0,
83+
"petroleum": 0.3,
84+
"biomass": 0.7,
85+
"coal": 0.0,
86+
"other": 0.0,
87+
"solar": 0.01,
88+
"tidal": 0.0,
89+
"total": 100.01,
90+
"wind": 6.7,
91+
"hydro": 92.1
92+
},
93+
"alberta": {
94+
"naturalGas": 73.5,
95+
"nuclear": 0.0,
96+
"petroleum": 0.02,
97+
"biomass": 2.0,
98+
"coal": 8.0,
99+
"other": 0.0,
100+
"solar": 3.2,
101+
"tidal": 0.0,
102+
"total": 99.82,
103+
"wind": 11.3,
104+
"hydro": 1.8
105+
},
106+
"manitoba": {
107+
"naturalGas": 0.6,
108+
"nuclear": 0.0,
109+
"petroleum": 0.1,
110+
"biomass": 0.2,
111+
"coal": 0.0,
112+
"other": 0.0,
113+
"solar": 0.1,
114+
"tidal": 0.0,
115+
"total": 100.1,
116+
"wind": 1.7,
117+
"hydro": 97.4
118+
},
119+
"northwest territories": {
120+
"naturalGas": 7.3,
121+
"nuclear": 0.0,
122+
"petroleum": 10.5,
123+
"biomass": 0.0,
124+
"coal": 0.0,
125+
"other": 0.0,
126+
"solar": 0.9,
127+
"tidal": 0.0,
128+
"total": 100.0,
129+
"wind": 7.1,
130+
"hydro": 74.2
131+
},
132+
"new brunswick": {
133+
"naturalGas": 16.6,
134+
"nuclear": 39.9,
135+
"petroleum": 0.3,
136+
"biomass": 1.3,
137+
"coal": 12.1,
138+
"other": 0.0,
139+
"solar": 0.0,
140+
"tidal": 0.0,
141+
"total": 99.9,
142+
"wind": 8.7,
143+
"hydro": 21.0
144+
},
145+
"nunavut": {
146+
"naturalGas": 0.0,
147+
"nuclear": 0.0,
148+
"petroleum": 99.8,
149+
"biomass": 0.0,
150+
"coal": 0.0,
151+
"other": 0.0,
152+
"solar": 0.2,
153+
"tidal": 0.0,
154+
"total": 100.0,
155+
"wind": 0.0,
156+
"hydro": 0.0
157+
},
158+
"yukon": {
159+
"naturalGas": 20.2,
160+
"nuclear": 0.0,
161+
"petroleum": 15.0,
162+
"biomass": 0.5,
163+
"coal": 0.0,
164+
"other": 0.0,
165+
"solar": 0.1,
166+
"tidal": 0.0,
167+
"total": 100.1,
168+
"wind": 0.2,
169+
"hydro": 64.1
170+
}
171+
}

codecarbon/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self):
2424
"geo_js_url": "https://get.geojs.io/v1/ip/geo.json",
2525
"cloud_emissions_path": "data/cloud/impact.csv",
2626
"usa_emissions_data_path": "data/private_infra/2016/usa_emissions.json",
27-
"can_energy_mix_data_path": "data/private_infra/2016/canada_energy_mix.json", # noqa: E501
27+
"can_energy_mix_data_path": "data/private_infra/2023/canada_energy_mix.json", # noqa: E501
2828
"global_energy_mix_data_path": "data/private_infra/global_energy_mix.json", # noqa: E501
2929
"carbon_intensity_per_source_path": "data/private_infra/carbon_intensity_per_source.json",
3030
"cpu_power_path": "data/hardware/cpu_power.csv",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ codecarbon = [
6161
"data/private_infra/global_energy_mix.json",
6262
"data/private_infra/carbon_intensity_per_source.json",
6363
"data/private_infra/2016/usa_emissions.json",
64-
"data/private_infra/2016/canada_energy_mix.json",
64+
"data/private_infra/2023/canada_energy_mix.json",
6565
]
6666

6767
[project.urls]

tests/test_cpu_load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from codecarbon.core.units import Power
66
from codecarbon.emissions_tracker import OfflineEmissionsTracker
7-
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD
7+
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD, AppleSiliconChip
88

99

1010
@mock.patch("codecarbon.core.cpu.is_psutil_available", return_value=True)
@@ -57,7 +57,9 @@ def test_cpu_load_detection(
5757
):
5858
tracker = OfflineEmissionsTracker(country_iso_code="FRA")
5959
for hardware in tracker._hardware:
60-
if isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD:
60+
if (
61+
isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD
62+
) or isinstance(hardware, AppleSiliconChip):
6163
break
6264
else:
6365
raise Exception("No CPU load !!!")

tests/test_emissions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ def test_get_emissions_PRIVATE_INFRA_CANADA_WITH_REGION(self):
154154
country_iso_code="CAN", country_name="Canada", region="ontario"
155155
),
156156
)
157+
manually_computed_emissions = (
158+
3 * (0.995725971 * 0.0 + 0.8166885263 * 0.1 + 0.7438415916 * 8.6) / 100.1
159+
)
157160

158161
# THEN
159162
assert isinstance(emissions, float)
160-
self.assertAlmostEqual(emissions, 0.12, places=2)
163+
self.assertAlmostEqual(emissions, manually_computed_emissions, places=2)
161164

162165
def test_get_emissions_PRIVATE_INFRA_unknown_country(self):
163166
"""

tests/test_unsupported_gpu.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import unittest
34
from unittest.mock import MagicMock, patch
45

@@ -18,6 +19,10 @@ def tearDown(self):
1819
if os.path.exists(self.output_csv):
1920
os.remove(self.output_csv)
2021

22+
# If we run this on macOS, NVMLError_NotSupported has no effect
23+
# and we end up with non-zero values for GPU energy and power because
24+
# we use the non-NVML code-path in hardware.AppleSiliconChip().
25+
@unittest.skipIf(sys.platform == "darwin", "NVML not available on macOS")
2126
@patch("codecarbon.core.gpu.pynvml")
2227
def test_emissions_tracker_unsupported_gpu(self, mock_pynvml):
2328
mock_pynvml.NVMLError_NotSupported = self.NVMLError_NotSupported

0 commit comments

Comments
 (0)