powerapi-ng / pyRAPL

a library to measure the python energy consumption of python code
MIT License
100 stars 9 forks source link

Measurements error #17

Open manceaur opened 1 year ago

manceaur commented 1 year ago

I tried to run a simple following example with pyRAPL but something went wrong when measurement ends :

I'm using Fedora 35, python 3.9.12

Here the code :

import pyRAPL

pyRAPL.setup()

csv_output = pyRAPL.outputs.CSVOutput('results.csv')

@pyRAPL.measureit(output=csv_output)
def test(N):
    a = 0
    for i in range(N):
        a += 1
    return a

test(1000)

csv_output.save()

TypeError                                 Traceback (most recent call last)
~/test_measurement.ipynb Cellule 6 in <cell line: 14>()
     [11]        a += 1
     [12]    return a
---> [14] test(1000)
     [17] csv_output.save()

File ~/.conda/envs/exp_env/lib/python3.9/site-packages/pyRAPL/measurement.py:123, in measureit.<locals>.decorator_measure_energy.<locals>.wrapper_measure(*args, **kwargs)
    121     val = func(*args, **kwargs)
    122 sensor.end()
--> 123 sensor._results = sensor._results / number
    124 sensor.export()
    125 return val

File ~/.conda/envs/exp_env/lib/python3.9/site-packages/pyRAPL/result.py:53, in Result.__truediv__(self, number)
     51 _duration = self.duration / number
     52 _pkg = [j / number for j in self.pkg]
---> 53 _dram = [j / number for j in self.dram]
     54 return Result(self.label, self.timestamp, _duration, _pkg, _dram)

TypeError: 'NoneType' object is not iterable
bekiroguzhan commented 1 year ago

I am having the same issue with Ubuntu 16.04 TLS and python 3.7.

sohanpatil1 commented 10 months ago

I got the same error, did anyone figure it out? Using Ubuntu 20.04 and python 3.8. I changed the code to this, _pkg = [j / number for j in self.pkg] if self.pkg else None _dram = [j / number for j in self.dram] if self.dram else None But I haven't studied it enough to know if this is correct.

kinow commented 6 months ago

Had the same, in my case it looks like the dram metrics/list is not populated. The class attribute is Optional (thanks for the type hints!), but the code doesn't seem to take that into consideration when iterating it. I fixed it locally to ignore the dram for now (couldn't find if I have to enable something on Ubuntu) with this code:

_dram = [] if self.dram is None else [j / number for j in self.dram]