Skip to content

Commit

Permalink
test: add test for create_platform when Hardware is used
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Feb 23, 2025
1 parent e12d6f5 commit 1f80378
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/qibolab/_core/dummy/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from qibolab._core.components import AcquisitionChannel, DcChannel, IqChannel
from qibolab._core.instruments.dummy import DummyInstrument, DummyLocalOscillator
from qibolab._core.parameters import Hardware
from qibolab._core.platform import Platform
from qibolab._core.qubits import Qubit

FOLDER = pathlib.Path(__file__).parent


def create_dummy() -> Platform:
"""Create a dummy platform using the dummy instrument."""
def create_dummy_hardware() -> Hardware:
"""Create dummy hardware configuration based on the dummy instrument."""
qubits = {}
channels = {}
# attach the channels
Expand Down Expand Up @@ -38,6 +39,10 @@ def create_dummy() -> Platform:
pump_name: DummyLocalOscillator(address="0.0.0.0"),
}

return Platform.load(
path=FOLDER, instruments=instruments, qubits=qubits, couplers=couplers
)
return Hardware(instruments=instruments, qubits=qubits, couplers=couplers)


def create_dummy() -> Platform:
"""Create a dummy platform using the dummy instrument."""
hardware = create_dummy_hardware()
return Platform.load(path=FOLDER, **vars(hardware))
16 changes: 16 additions & 0 deletions tests/dummy_hardware/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Dummy platform to test loading via ``Hardware`` object."""

from pathlib import Path

from qibolab import Hardware, initialize_parameters
from qibolab._core.dummy.platform import create_dummy_hardware
from qibolab._core.platform.platform import PARAMETERS


def create() -> Hardware:
hardware = create_dummy_hardware()
parameters = initialize_parameters(hardware=hardware)
(Path(__file__).parent / PARAMETERS).write_text(
parameters.model_dump_json(indent=4)
)
return hardware
8 changes: 8 additions & 0 deletions tests/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def test_create_platform_error():
_ = create_platform("nonexistent")


def test_create_platform_from_hardware():
original_value = os.environ.get(PLATFORMS)
os.environ[PLATFORMS] = str(Path(__file__).parent)
_ = create_platform("dummy_hardware")
os.remove(Path(__file__).parent / "dummy_hardware" / PARAMETERS)
os.environ[PLATFORMS] = original_value


def test_platform_basics():
platform = Platform(
name="ciao",
Expand Down

0 comments on commit 1f80378

Please sign in to comment.