From 33f4519cdf28b9958278a1b80be09ecae16e9350 Mon Sep 17 00:00:00 2001 From: Stavros Efthymiou <35475381+stavros11@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:02:12 +0400 Subject: [PATCH] refactor: Review comments --- src/qibolab/dummy.py | 7 ++++++- src/qibolab/native.py | 8 ++++---- tests/test_platform.py | 7 +++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/qibolab/dummy.py b/src/qibolab/dummy.py index b6e16bd6fc..07ebd44d04 100644 --- a/src/qibolab/dummy.py +++ b/src/qibolab/dummy.py @@ -21,6 +21,11 @@ def remove_couplers(runcard): return runcard +def load_dummy_runcard(): + """Loads the runcard YAML of the dummy platform.""" + return load_runcard(pathlib.Path(__file__).parent / "dummy.yml") + + def create_dummy(with_couplers: bool = True): """Create a dummy platform using the dummy instrument. @@ -35,7 +40,7 @@ def create_dummy(with_couplers: bool = True): twpa_pump.frequency = 1e9 twpa_pump.power = 10 - runcard = load_runcard(pathlib.Path(__file__).parent / "dummy.yml") + runcard = load_dummy_runcard() if not with_couplers: runcard = remove_couplers(runcard) diff --git a/src/qibolab/native.py b/src/qibolab/native.py index 5cb4612076..b411cc9de2 100644 --- a/src/qibolab/native.py +++ b/src/qibolab/native.py @@ -354,10 +354,10 @@ class TwoQubitNatives: def symmetric(self): """Check if the defined two-qubit gates are symmetric between target and control qubits.""" - for fld in fields(self): - if not fld.metadata["symmetric"] and getattr(self, fld.name) is not None: - return False - return True + return all( + fld.metadata["symmetric"] or getattr(self, fld.name) is None + for fld in fields(self) + ) @classmethod def from_dict(cls, qubits, couplers, native_gates): diff --git a/tests/test_platform.py b/tests/test_platform.py index 74164123f2..2780fee062 100644 --- a/tests/test_platform.py +++ b/tests/test_platform.py @@ -11,6 +11,7 @@ from qibolab import create_platform from qibolab.backends import QibolabBackend +from qibolab.dummy import load_dummy_runcard from qibolab.execution_parameters import ExecutionParameters from qibolab.instruments.qblox.controller import QbloxController from qibolab.instruments.rfsoc.driver import RFSoC @@ -64,14 +65,12 @@ def test_dump_runcard(platform): dump_runcard(platform, path) final_runcard = load_runcard(path) if platform.name == "dummy" or platform.name == "dummy_couplers": - target_path = ( - pathlib.Path(__file__).parent.parent / "src" / "qibolab" / "dummy.yml" - ) + target_runcard = load_dummy_runcard() else: target_path = ( pathlib.Path(__file__).parent / "dummy_qrc" / f"{platform.name}.yml" ) - target_runcard = load_runcard(target_path) + target_runcard = load_runcard(target_path) # for the characterization section the dumped runcard may contain # some default ``Qubit`` parameters target_char = target_runcard.pop("characterization")["single_qubit"]