diff --git a/src/qibolab/_core/platform/__init__.py b/src/qibolab/_core/platform/__init__.py index 2302ab60e..15b665f43 100644 --- a/src/qibolab/_core/platform/__init__.py +++ b/src/qibolab/_core/platform/__init__.py @@ -1,4 +1,7 @@ -from .load import create_platform -from .platform import Platform +from . import load, platform +from .load import * +from .platform import * -__all__ = ["Platform", "create_platform"] +__all__ = [] +__all__ += load.__all__ +__all__ += platform.__all__ diff --git a/src/qibolab/_core/platform/load.py b/src/qibolab/_core/platform/load.py index 2c941e3c6..effe85e5d 100644 --- a/src/qibolab/_core/platform/load.py +++ b/src/qibolab/_core/platform/load.py @@ -1,11 +1,14 @@ import importlib.util import os from pathlib import Path +from typing import Optional from qibo.config import raise_error from .platform import Platform +__all__ = ["create_platform", "locate_platform"] + PLATFORM = "platform.py" PLATFORMS = "QIBOLAB_PLATFORMS" @@ -24,7 +27,7 @@ def _platforms_paths() -> list[Path]: def _search(name: str, paths: list[Path]) -> Path: """Search paths for given platform name.""" - for path in _platforms_paths(): + for path in paths: platform = path / name if platform.exists(): return platform @@ -44,6 +47,20 @@ def _load(platform: Path) -> Platform: return module.create() +def locate_platform(name: str, paths: Optional[list[Path]] = None) -> Path: + """Locate platform's path. + + The ``name`` corresponds to the name of the folder in which the platform is defined, + i.e. the one containing the ``platform.py`` file. + + If ``paths`` are specified, the environment is ignored, and the folder search + happens only in the specified paths. + """ + if paths is None: + paths = _platforms_paths() + return _search(name, paths) + + def create_platform(name: str) -> Platform: """A platform for executing quantum algorithms. diff --git a/src/qibolab/_core/platform/platform.py b/src/qibolab/_core/platform/platform.py index 48278dab4..d39031c7e 100644 --- a/src/qibolab/_core/platform/platform.py +++ b/src/qibolab/_core/platform/platform.py @@ -19,6 +19,8 @@ from ..sweeper import ParallelSweepers from ..unrolling import Bounds, batch +__all__ = ["Platform"] + QubitMap = dict[QubitId, Qubit] QubitPairMap = list[QubitPairId] InstrumentMap = dict[InstrumentId, Instrument]