-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add fallback for when CPU count can't be determined #1214
Conversation
84b6588
to
2a93e30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good.
Should I put something in changelog? Not really sure what warrants going in changelog and what doesn't. |
Yeah. Just say you fixed an issue with finding num processes |
2a93e30
to
6045e7f
Compare
@nonhermitian Thanks, done. Did you see my question in the issue thread?
|
In setting logical to False, we are looking for only physical cpus. Things like hyperthreads do not greatly contribute to the parallel power, and increase the memory count. So we try to avoid them. Not sure why the arm processor says no physical cpus. |
I'm able to reproduce psutil() returning None on one of my arm devices (not a raspberry pi, don't have one handy right now). Looking at the psutil code for getting the physical cpu count: https://github.com/giampaolo/psutil/blob/master/psutil/_pslinux.py#L624-L646 it's expecting a certain format from /proc/cpuinfo (what x86 CPUs have) but the arm format is different, and it doesn't have the 'physical id' key that psutil is searching for. So it fails to parse and returns None. Looking at the code for the logical cpu count they had a similar issue there and fixed it by parsing /proc/stat instead. I'll submit a bug to psutil and work on a fix later. Other than the merge conflict on the changelog, this LGTM. A unit test would be nice, but it's not worth blocking over for something this simple. |
@mtreinish Yeah I found the same thing when I looked. I came across this closed issue first and stopped at that I'm afraid! Will fix merge conflict now. Thought about trying to add test but didn't know how I would do it I'm afraid. |
6045e7f
to
765a346
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, fwiw you could do something like:
@mock.patch('platform.system', return_value='Linux')
@mock.patch('psutil.virtual_memory')
@mock.patch('psutil.cpu_count', return_value=None)
def test_local_hardware_None_cpu_count(self, cpu_count_mock, vmem_mock,
platform_mock):
result = _util.local_hardware_info()
self.assertEqual(1, result['cpus'])
In test/python/test_util.py
. But it's not worth blocking over, we can always add it later too.
6511700
to
5c70c18
Compare
@mtreinish Thanks! I had no idea about mock so didn't know where to begin for writing a test. Added test as suggested with some minor adjustments for linting. |
@charlesastaylor Sigh, well it looks like test_util.py file was removed in #1198 (since it removed the need for the only test that was in there in the patch) so you'll have to just add the file back with only the new test that you're adding here. |
1c1b777
to
e6ce07a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One CPU seems like a good fallback. :p
Thank you.
*Fallback to 1 when cpu_count returns None *Create test_util.py and add test Fixes Qiskit#1212
e6ce07a
to
3f810ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @charlesastaylor for the neat fix and for the quick adjustments in this high-activity phase! I'm clicking the approve button and merging, but the real credit for the review is to @nonhermitian, @mtreinish and @delapuente - thanks everyone, and looking forward to more contributions!
Dismissing due to github bureocracy - the changes requested have been performed
…skit#1214) *Fallback to 1 when cpu_count returns None *Create test_util.py and add test Fixes Qiskit#1212
Summary
psutil.cpu_count(logical=False)
returns None when the true count can't be determined. #1212 found this happening on a raspberry pi.