fix(hardware_utils): get_akida_device only checks the first device - #24
Merged
dmclellandbc merged 1 commit intoSep 2, 2026
Merged
Conversation
dmclellandbc
requested review from
dmclellandbc,
jmejia-brainchip and
nguilbaud-brainchip
September 1, 2026 08:33
jmejia-brainchip
approved these changes
Sep 1, 2026
Comment on lines
+12
to
+27
| def test_matching_device_after_the_first_is_found(monkeypatch): | ||
| """A device matching target_version must be found wherever it sits in the list.""" | ||
| first, second = _FakeDevice(akida.IpVersion.v2), _FakeDevice(akida.IpVersion.v1) | ||
| monkeypatch.setattr(akida, "devices", lambda: [first, second]) | ||
| assert get_akida_device(target_version=akida.IpVersion.v1) is second | ||
|
|
||
|
|
||
| def test_returns_none_when_no_device_matches(monkeypatch): | ||
| monkeypatch.setattr(akida, "devices", lambda: [_FakeDevice(akida.IpVersion.v2)]) | ||
| assert get_akida_device(target_version=akida.IpVersion.v1) is None | ||
|
|
||
|
|
||
| def test_returns_first_device_when_no_target_requested(monkeypatch): | ||
| first = _FakeDevice(akida.IpVersion.v1) | ||
| monkeypatch.setattr(akida, "devices", lambda: [first, _FakeDevice(akida.IpVersion.v2)]) | ||
| assert get_akida_device() is first |
There was a problem hiding this comment.
Not mandatory but you are able to parametrize the test
Suggested change
| def test_matching_device_after_the_first_is_found(monkeypatch): | |
| """A device matching target_version must be found wherever it sits in the list.""" | |
| first, second = _FakeDevice(akida.IpVersion.v2), _FakeDevice(akida.IpVersion.v1) | |
| monkeypatch.setattr(akida, "devices", lambda: [first, second]) | |
| assert get_akida_device(target_version=akida.IpVersion.v1) is second | |
| def test_returns_none_when_no_device_matches(monkeypatch): | |
| monkeypatch.setattr(akida, "devices", lambda: [_FakeDevice(akida.IpVersion.v2)]) | |
| assert get_akida_device(target_version=akida.IpVersion.v1) is None | |
| def test_returns_first_device_when_no_target_requested(monkeypatch): | |
| first = _FakeDevice(akida.IpVersion.v1) | |
| monkeypatch.setattr(akida, "devices", lambda: [first, _FakeDevice(akida.IpVersion.v2)]) | |
| assert get_akida_device() is first | |
| import pytest | |
| _device_ip_v1=_FakeDevice(akida.IpVersion.v1) | |
| _device_ip_v2=_FakeDevice(akida.IpVersion.v2) | |
| @pytest.mark.parametrize("list_devices, target_version, expected", | |
| [([_device_ip_v1, _device_ip_v2], akida.IpVersion.v1, _device_ip_v2), ...]) | |
| def test_returns_first_device_when_no_target_requested(monkeypatch, list_devices, target_version, expected): | |
| monkeypatch.setattr(akida, "devices", lambda: list_devices) | |
| assert get_akida_device(target_version=target_version) is expected |
GuilbaudNicolas
approved these changes
Sep 1, 2026
| print('Connected Akida Device does not match the requested IPVersion.') | ||
| print('Calls to akida will run on the software backend.') | ||
| return None | ||
| print('Connected Akida Device does not match the requested IPVersion.') |
There was a problem hiding this comment.
Not the fix, but we could improve error message.
available_versions = [dd.ip_version for dd in devices]
print(f'Connected Akida Device does not match the requested IPVersion. '
f'Requested: {target_version}, available: {available_versions}')
dmclellandbc
approved these changes
Sep 2, 2026
dmclellandbc
left a comment
Collaborator
There was a problem hiding this comment.
Great, thanks.
And I'll take care of extending the CI to include the test/ directory in some follow-up work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
get_akida_device(), thereturn Nonein thetarget_versionbranch is insidethe
forloop, so only the first enumerated device is ever compared against therequested IP version:
On a host with more than one Akida device, a matching device in any position after
the first is never found, and the caller silently falls back to the software
backend — which is easy to miss, because the printed message looks like a normal
"no matching hardware" result.
This moves the fallback after the loop, and reuses the
deviceslist alreadyfetched at the top of the function instead of enumerating a second time.
Added
test/test_hardware_utils.pywith three cases (match after the first device,no match, no target requested). They stub
akida.devices, so they need no hardware.Verified locally: the first test fails against the unmodified function (returns
None)and all three pass with the fix applied.
One thing to flag:
ci.ymlandhardware.ymlboth invoke pytest againsttest/test_models.pyspecifically rather than thetest/directory, so this newfile wouldn't be collected as-is. Happy to add it to the CI target in this PR if
you'd like, or leave that to you.