Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors #52

Closed
hrv897 opened this issue Feb 24, 2023 · 3 comments
Closed

Errors #52

hrv897 opened this issue Feb 24, 2023 · 3 comments
Labels
API bug Something isn't working

Comments

@hrv897
Copy link

hrv897 commented Feb 24, 2023

When running carbon tracker like this:

tracker = CarbonTracker(epochs=100)

correct = 0
wrong = 0
tracker.epoch_start()
for i in range(100):
true_label = id2label[val_labels[i].item()]
img = T.ToPILImage()(val_features[i].squeeze())
inputs = processor(images=img, return_tensors="pt").to(device)
pixel_values = inputs.pixel_values

outputs = model(pixel_values)
logits = outputs.logits
logits.shape
prediction = logits.argmax(-1)
prediction_str = model.config.id2label[prediction.item()]

display(img)
print("Predicted class:", prediction_str)
print("True class:", true_label)
if true_label == prediction_str:
correct += 1
print("correct")
else:
wrong += 1
print("wrong")

tracker.epoch_end()
tracker.stop()

On an Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz with 16 GB RAM, NVIDIA GeForce GTX 980 Ti and Windows 10 in Jupyter Notebook, I get the following output from CarbonTracker:

CarbonTracker:
Actual consumption for 1 epoch(s):
Time: 0:00:05
Energy: 0.000152 kWh
CO2eq: 0.006405 g
This is equivalent to:
0.000060 km travelled by car
CarbonTracker: INFO - Traceback (most recent call last):
File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\user\anaconda3\envs\gpu2\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\user\anaconda3\envs\gpu2\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\user\anaconda3\envs\gpu2\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\intensity.py", line 117, in carbon_intensity
carbon_intensity = fetcher.carbon_intensity(g_location, time_dur)
File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\fetchers\energidataservice.py", line 21, in carbon_intensity
ci = self._emission_prognosis(time_dur=time_dur)
File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\fetchers\energidataservice.py", line 48, in _emission_prognosis
raise exceptions.CarbonIntensityFetcherError(response.json())
File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

CarbonTracker:
Predicted consumption for 100 epoch(s):
Time: 0:08:26
Energy: 0.015250 kWh
CO2eq: 1.462028 g
This is equivalent to:
0.013600 km travelled by car
CarbonTracker: Finished monitoring.

@raghavian raghavian added bug Something isn't working API labels Mar 5, 2023
@raghavian
Copy link
Collaborator

raghavian commented Mar 5, 2023

Looks like the energiservice api which we use to query the carbon emissions changed their string format. We will release a bug fix. For now, if you change the query method in energidataservice.py in your local installation it should work. You can find this in your installation here C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\intensity.py

    def _emission_prognosis(self, time_dur):
        from_str, to_str = self._interval(time_dur=time_dur)
        from_str = from_str.replace(' ','T')
        to_str = to_str.replace(' ','T')
        url = "https://api.energidataservice.dk/dataset/CO2Emis?start=" + from_str + "&end=" + to_str + "&limit=4"
        response = requests.get(url)
        if not response.ok:
            raise exceptions.CarbonIntensityFetcherError(response.json())
        data = response.json()["records"]
        carbon_intensities = [record["CO2Emission"] for record in data]
        return np.mean(carbon_intensities)

@dmdequin
Copy link

dmdequin commented Apr 14, 2023

The function _emission_prognosis is found in carbontracker/emissions/intensity/fetchers/energidataservice.py. The path shown above is incorrect.

@PedramBakh
Copy link
Collaborator

This issue has been addressed in Release v1.2.0. We've phased out support for the energidataserviceapi and transitioned to the ElectricityMaps API. This change ensures better consistency and resolves the timeout issues previously encountered with consecutive requests. Thank you for bringing this to our attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants