Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for create_platform when Hardware is used #1153

Open
wants to merge 1 commit into
base: hardware-instruments-load
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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