qiboteam / qibolab

Quantum hardware module and drivers for Qibo.
https://qibo.science
Apache License 2.0
43 stars 14 forks source link

MetaBackend #820

Closed BrunoLiegiBastonLiegi closed 5 months ago

BrunoLiegiBastonLiegi commented 7 months ago

This PR implements a MetaBackend to load the qibolab backend and list the available platforms.

Checklist:

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 66.64%. Comparing base (a514441) to head (92cc146). Report is 12 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #820 +/- ## ========================================== + Coverage 66.59% 66.64% +0.05% ========================================== Files 55 55 Lines 5942 5951 +9 ========================================== + Hits 3957 3966 +9 Misses 1985 1985 ``` | [Flag](https://app.codecov.io/gh/qiboteam/qibolab/pull/820/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/qiboteam/qibolab/pull/820/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | `66.64% <100.00%> (+0.05%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

BrunoLiegiBastonLiegi commented 5 months ago

@stavros11 @alecandido regarding the try/except in the list_available compared to the get_available_platforms, I believe there is a subtle difference, which we may want or not want to expose. I do not have any strong opinion on this and I am okay with both the options anyway. The get_available_platforms only checks which platform is found in the QIBOLAB_PLATFORMS directory, but it does not provide any information about whether the platform actually works and can be used. An empty file fake_platform/platform.py would still pass the get_available_platforms and be listed as available by the list_available_backends, even though it will certainly fail upon instantiation with the QibolabBackend. Therefore, it's just a matter of deciding what the list_available_backends function should produce, either the list of all the backends/platforms that we are sure (up to some point, because the instantiation of the backend alone is tested) are working, or just the list of the platforms that follow the required formatting.

alecandido commented 5 months ago

@BrunoLiegiBastonLiegi, I'm aware of that. But I'd say that, if there is a single function (and I'd keep a single one, to keep it simple), we should perform the simpler task, without extra computation.

Verifying that there is something that looks like a platform is enough, even because to test it is actually working you should attempt an execution, that would require a connection, and more. If there is an inconsistent platform installed in your Qibolab path, then you are responsible for that, or you could contact your sysadmin.

EDIT: moreover, the actual check could be implemented on top of the list_available function, since it's not MetaBackend-specific: you can iterate the result of list_available, load them, and then try to execute a minimal circuit, without any extra knowledge from the MetaBackend

BrunoLiegiBastonLiegi commented 5 months ago

Alright, then I'll drop the try/except here. Regarding the general minimal test circuit in the list_available_backends instead, it looks like a good idea, but, in the qibolab case for example, that would require you to have an accessible qubit everytime you call the function, which seems a little bit too expensive to me.

alecandido commented 5 months ago

In general, it could always be an expensive test, because running circuits always requires acquiring the resources needed. How much expensive definitely depends on the backend.