Skip to content

Commit

Permalink
fix: improved get_available_platforms and moved error inside create_p…
Browse files Browse the repository at this point in the history
…latform
  • Loading branch information
BrunoLiegiBastonLiegi committed Apr 25, 2024
1 parent 9507424 commit 823e8e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/qibolab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def create_platform(name, path: Path = None) -> Platform:

platform = get_platforms_path() / f"{name}"
if not platform.exists():
raise_error(ValueError, f"Platform {name} does not exist.")
raise_error(
ValueError,
f"Platform {name} does not exist. Please pick one within the platforms found available {get_available_platforms()}.",
)

spec = importlib.util.spec_from_file_location("platform", platform / PLATFORM)
module = importlib.util.module_from_spec(spec)
Expand Down Expand Up @@ -86,7 +89,8 @@ def get_available_platforms() -> list[str]:
return [
d.name
for d in get_platforms_path().iterdir()
if d.is_dir() and not (d.name.startswith("_") or d.name.startswith("."))
if d.is_dir()
and Path(f"{os.environ.get(PLATFORMS)}/{d.name}/platform.py") in d.iterdir()
]


Expand All @@ -104,14 +108,7 @@ def load(platform: str):
"""
from qibolab.backends import QibolabBackend

platforms = get_available_platforms()
if platform in platforms:
return QibolabBackend(platform=platform)
else:
raise_error(
ValueError,
f"Unsupported platform, please use one among {platforms}.",
)
return QibolabBackend(platform=platform)

def list_available(self) -> dict:
"""Lists all the available qibolab platforms."""
Expand All @@ -122,4 +119,9 @@ def list_available(self) -> dict:
available_platforms[platform] = True
except:
available_platforms[platform] = False
if len(available_platforms):
raise_error(
RuntimeError,
f"No valid platform found in the QIBOLAB_PLATFORMS directory: {os.environ.get(PLATFORMS)}. Please make sure that each platform has its corresponding `platform.py` file.",
)
return available_platforms
2 changes: 1 addition & 1 deletion tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ def test_superposition_for_all_qubits(connected_backend):
# TODO: test_circuit_result_tensor
# TODO: test_circuit_result_representation

@pytest.mark.qpu

def test_metabackend(connected_backend):
assert MetaBackend().list_available()[connected_backend]

0 comments on commit 823e8e5

Please sign in to comment.