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

Merged
merged 2 commits into from
Feb 24, 2025
Merged
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))
8 changes: 8 additions & 0 deletions tests/dummy_hardware/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Dummy platform to test loading via ``Hardware`` object."""

from qibolab import Hardware
from qibolab._core.dummy.platform import create_dummy_hardware


def create() -> Hardware:
return create_dummy_hardware()
20 changes: 18 additions & 2 deletions tests/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from qibo.models import Circuit
from qibo.result import CircuitResult

from qibolab import create_platform
from qibolab import create_platform, initialize_parameters
from qibolab._core.backends import QibolabBackend
from qibolab._core.components import AcquisitionConfig, IqConfig, OscillatorConfig
from qibolab._core.dummy import create_dummy
from qibolab._core.dummy.platform import FOLDER
from qibolab._core.dummy.platform import FOLDER, create_dummy_hardware
from qibolab._core.native import SingleQubitNatives, TwoQubitNatives
from qibolab._core.parameters import NativeGates, Parameters, update_configs
from qibolab._core.platform import Platform
Expand All @@ -35,6 +35,22 @@ def test_create_platform_error():
_ = create_platform("nonexistent")


@pytest.fixture
def dummy_hardware(monkeypatch):
parameters = initialize_parameters(hardware=create_dummy_hardware())
path = Path(__file__).parent / "dummy_hardware" / PARAMETERS
path.write_text(parameters.model_dump_json(indent=4))
monkeypatch.setenv(PLATFORMS, str(Path(__file__).parent))
yield
path.unlink()


def test_create_platform_from_hardware(dummy_hardware):
platform = create_platform("dummy_hardware")
assert isinstance(platform, Platform)
assert list(platform.qubits.keys()) == list(range(5))


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