Skip to content

Commit

Permalink
test: [QILI-87] Create schema unit tests (#12)
Browse files Browse the repository at this point in the history
* feat: ✨ Add I, X, Y, Z gates.

* test: 🧪 Add backend tests

* refactor: ♻️ Remove dummy files and examples

* feat: ✨ Add QiliPlatform class.

* feat: ✨ Add Settings class.

* feat: ✨ Add SettingsLoader class.

* chore: 🔧 Add types-PyYAML to dev-requirements.txt

* ci: configure codecov

* refactor: ♻️ Create one python file for each gate

* fix: 🐛 Remove dummy import

* refactor: ♻️ Change file name

* test: 🧪 Add settings_manager tests. Fix backend tests.

* refactor: ♻️ Change class name

SettingsLoader to SettingsManager

* feat: ✨ Add platform and instrument setting files

* refactor: ♻️ Change gates file names

* build: 🔧 Add typeguard to requirements

* refactor: ♻️ Delete useless methods.

* refactor: ♻️ Change gate name in __init__.

* refactor: ♻️ Remove useless methods

* refactor: ♻️ Remove raise_error

* feat: ✨ Change SettingsManager to singleton

* feat: ✨ Add PlatformSettings class

* feat: ✨ Add AbstractSettings and SettingsLoader classes

* feat: ✨ Add QubitCalibrationSettings class

* refactor: ♻️ Remove Settings class

* refactor: ♻️ Move instrument settings file to single yaml file

* test: 🧪 Update backend and settings_manager tests.

* fix: 🐛 Add init file

* style: 🎨 Remove unused import

* refactor: ♻️ Change classes to dataclass

* style: 🎨 Remove unused import

* ci: 👷 Install requirements.txt before code quality check

* ci: 👷 Add MANIFEST.in file to install yaml files

* ci: 👷 Modify MANIFEST.in file

* fix: 🐛 Call __post_init__() of AbstractPlatform

* refactor: ♻️ Remove SettingsLoader class

* docs: 📝 Remove unused argument docs

* fix: 🐛 Add ClassVar to class variables inside a dataclass

* style: 🎨 Disable sort when dumping yaml file

* feat: ✨ Add buses in PlatformSettings

* style: 🎨 Declare platform attribute instead of setting it to None

* build: 🔧 Add qblox-instruments to requirements

* refactor: ♻️ Change settings files structure

* refactor: ♻️ Change platform class name

* refactor: ♻️ Remove raise error

* feat: ✨ Add PlatformBuilder. Add relative imports to __init__.py files.

* refactor: ♻️ Move settings loading to PlatformBuilder

* style: 🎨 Log message when instantiating SettingsManager class

* feat: ✨ Make PlatformBuilder a singleton

* docs: 📝 Add docs

* style: 🎨 Delete unused imports.

* style: 🎨 Delete unused imports.

* style: 🎨 Use match case statement.

* feat: ✨ Add instrument skeleton classes

* refactor: ♻️ Add SettingsHashTable

* Remove imports from __init__ to avoid circular imports

* refactor: ♻️ Remove typing of current class

* refactor: ♻️ Move all instrument files inside instrument/ folder

* feat: ✨ Add Singleton metaclass

* ci: 👷 Check with pylint only staged files

* refactor: ♻️ Use platform-specific settings

Move all the settings of a specific platform inside the same folder

* style: 🎨 Solve pylint issues.

* refactor: ♻️ Move settings category inside yaml file

* refactor: ♻️ Add category attribute to AbstractSettings

* style: 🎨 Remove abstract return type

* feat: ✨ Add Schema and SchemaSettings class

* refactor: ♻️ Remove 'abstract' from any file or class.

Solves comment https://github.com/qilimanjaro-tech/qililab/pull/4\#discussion_r841469545

* refactor: ♻️ Change name PB to PLATFORM_BUILDER

* refactor: ♻️ Remove dataclass from HardwareCircuit

* refactor: ♻️ Change name SM to SETTINGS_MANAGER

* refactor: ♻️ Rename 'platform' to 'platform_name'

* refactor: ♻️ Add constants.py file

* refactor: ♻️ Add DEFAULT_SETTINGS_FOLDERNAME to constants.py file

* refactor: ♻️ Use full name for variables

* docs: 📝 Delete TODO

* style: 🎨 Change settings type

* style: 🎨 Remove typing lsit

* refactor: ♻️ Check that dict has key before deleting it

* test: 🧪 Split tests

* fix: 🐛 Change backend attributes after parent init.

* chore: 📝 Add load_platform example

* refactor: ♻️ Remove 'settings' from filenames

* feat: ✨ Add instrument settings

* refactor: ♻️ Remove from __init__.py files all classes that won't be used by the user

* refactor: ♻️ Change class and file name

* feat: ✨ Add QbloxPulsar classes

* feat: ✨ Add QbloxPulsarSettings classes

* refactor: ♻️ Remove dependency from qibo

* style: 🎨 Add entry points

* chore: 📝 Add load_platform example using PLATFORM_BUILDER

* build: 🔧 Use new version of qblox_instruments

* style: 🎨 Fix settings type

* refactor: ♻️ Remove connect from __init__

* docs: 📝 Fix typo in docs

* feat: [QILI-48] Implement platform, backend and settings classes (#4)

* chore: 📝 Update requirements

Add qibo and pyyaml requirements

* chore: 🔊 Add raise_error function in config.py file

* feat: ✨ Add AbstractPlatform class.

* style: 🎨 Remove long line

* feat: ✨ Add HardwareCircuit class

* feat: ✨ Add QililabBackend class

* feat: ✨ Add gates.py file

* refactor: ♻️ Remove useless raise_error

* docs: 📝 Update docs of backend and platform classes

Add description of attributes

* feat: ✨ Add I, X, Y, Z gates.

* test: 🧪 Add backend tests

* refactor: ♻️ Remove dummy files and examples

* feat: ✨ Add QiliPlatform class.

* feat: ✨ Add Settings class.

* feat: ✨ Add SettingsLoader class.

* chore: 🔧 Add types-PyYAML to dev-requirements.txt

* ci: configure codecov

* refactor: ♻️ Create one python file for each gate

* fix: 🐛 Remove dummy import

* refactor: ♻️ Change file name

* test: 🧪 Add settings_manager tests. Fix backend tests.

* refactor: ♻️ Change class name

SettingsLoader to SettingsManager

* feat: ✨ Add platform and instrument setting files

* refactor: ♻️ Change gates file names

* build: 🔧 Add typeguard to requirements

* refactor: ♻️ Delete useless methods.

* refactor: ♻️ Change gate name in __init__.

* refactor: ♻️ Remove useless methods

* refactor: ♻️ Remove raise_error

* feat: ✨ Change SettingsManager to singleton

* feat: ✨ Add PlatformSettings class

* feat: ✨ Add AbstractSettings and SettingsLoader classes

* feat: ✨ Add QubitCalibrationSettings class

* refactor: ♻️ Remove Settings class

* refactor: ♻️ Move instrument settings file to single yaml file

* test: 🧪 Update backend and settings_manager tests.

* fix: 🐛 Add init file

* style: 🎨 Remove unused import

* refactor: ♻️ Change classes to dataclass

* style: 🎨 Remove unused import

* ci: 👷 Install requirements.txt before code quality check

* ci: 👷 Add MANIFEST.in file to install yaml files

* ci: 👷 Modify MANIFEST.in file

* fix: 🐛 Call __post_init__() of AbstractPlatform

* refactor: ♻️ Remove SettingsLoader class

* docs: 📝 Remove unused argument docs

* fix: 🐛 Add ClassVar to class variables inside a dataclass

* style: 🎨 Disable sort when dumping yaml file

* feat: ✨ Add buses in PlatformSettings

* style: 🎨 Declare platform attribute instead of setting it to None

* refactor: ♻️ Change settings files structure

* refactor: ♻️ Change platform class name

* refactor: ♻️ Remove raise error

* feat: ✨ Add PlatformBuilder. Add relative imports to __init__.py files.

* refactor: ♻️ Move settings loading to PlatformBuilder

* style: 🎨 Log message when instantiating SettingsManager class

* feat: ✨ Make PlatformBuilder a singleton

* docs: 📝 Add docs

* style: 🎨 Delete unused imports.

* style: 🎨 Delete unused imports.

* style: 🎨 Use match case statement.

* refactor: ♻️ Add SettingsHashTable

* Remove imports from __init__ to avoid circular imports

* refactor: ♻️ Remove typing of current class

* refactor: ♻️ Move all instrument files inside instrument/ folder

* feat: ✨ Add Singleton metaclass

* ci: 👷 Check with pylint only staged files

* refactor: ♻️ Use platform-specific settings

Move all the settings of a specific platform inside the same folder

* style: 🎨 Solve pylint issues.

* refactor: ♻️ Move settings category inside yaml file

* refactor: ♻️ Add category attribute to AbstractSettings

* refactor: ♻️ Remove 'abstract' from any file or class.

Solves comment https://github.com/qilimanjaro-tech/qililab/pull/4\#discussion_r841469545

* refactor: ♻️ Change name PB to PLATFORM_BUILDER

* refactor: ♻️ Remove dataclass from HardwareCircuit

* refactor: ♻️ Change name SM to SETTINGS_MANAGER

* refactor: ♻️ Rename 'platform' to 'platform_name'

* refactor: ♻️ Add constants.py file

* refactor: ♻️ Add DEFAULT_SETTINGS_FOLDERNAME to constants.py file

* refactor: ♻️ Use full name for variables

* docs: 📝 Delete TODO

* style: 🎨 Change settings type

* style: 🎨 Remove typing lsit

* refactor: ♻️ Check that dict has key before deleting it

* test: 🧪 Split tests

* fix: 🐛 Change backend attributes after parent init.

* chore: 📝 Add load_platform example

* refactor: ♻️ Remove dependency from qibo

* style: 🎨 Add entry points

* chore: 📝 Add load_platform example using PLATFORM_BUILDER

* docs: 📝 Fix typo in docs

Co-authored-by: Albert Solana <iamtxena@gmail.com>

* feat: 💩 Check connection before running class method.

We should find a way to avoid running _check_connected() every time

* fix: 🐛 Remove useless settings and change type of attribute.

* test: 🧪 Add tests for instruments

* fix: 🐛 Fix Pulsar connection

* bump: version 0.0.0 → 0.1.0

* revert: ⏪ Delete useless files added in last merge

* test: 🧪 Add more tests for instruments

* feat: ✨ Add upload() and get_acquisitions() methods

* test: 🧪 Fix yaml to pass all tests

* style: 🎨 Remove useless imports and types

* docs: 📝 Add arguments of parent classes also in its children

* feat: ✨ Add Rohde Schwartz SGS100A class

* refactor: ♻️ Move method to parent class.

* test: 🧪 Add tests for Rohde Schwarz

* refactor: ♻️ Structure settings/ and instruments/ directories

* refactor: ♻️ Move SGS100A inside rohde_schwarz folder

* refactor: ♻️ Create generic instruments

* refactor: ♻️ Create generic settings

* test: 🧪 Remove tests of private methods/attributes

* test: 🧪 Add scope to fixtures

* refactor: ♻️ Remove Pulse settings class

* refactor: ♻️ Set to None all un-defined attributes

* refactor: ♻️ Create class property to check connection

* docs: 📝 Fix doc typos.

* revert: ⏪ Remove None values added in commit 77ba88b

* style: 🎨 Remove useless return types

* refactor: ♻️ Move close method to Instrument class

* fix: 🐛 Fix bug added in merge

* refactor: ♻️ Use partial imports when using code from other module

* fix: 🐛 Fix circular import

* feat: ✨ Add Device, Pulsar and RohdeSchwarz typings

* refactor: ♻️ Remove location docs from settings classes

* refactor: ♻️ Create QbloxPulsarSettings class

* refactor: ♻️ Add dict argument to Instrument's init and cast it to corresponding settings class

* test: 🧪 Adapt tests to previous changes

* refactor: ♻️ Remove useless hashtable

* fix: 🐛 Add missing __init__

* refactor: ♻️ Remove useless constant

* refactor: ♻️ Move type declaration outside of init

* refactor: ♻️ Cast string attributes to Enum

* test: 🧪 Fix small bug in SettingsManager tests

* test: 🧪 Fix small bug in SettingsManager tests

* test: 🧪 Fix small bug in backend tests

* refactor: ♻️ Move CheckConnected decorator to child classes. Fix decorator.

* test: 🧪 Refactor

* test: 🧪 Add UNIT tests of instruments.

* ci: Check only src/ with mypy

* revert: ⏪ Remove src from mypy command. Add # type: ignore

* refactor: ♻️ Remove name attribute from instruments

The settings already have a name attribute

* refactor: ♻️ Add id and name in settings.

Category now corresponds to the 'general' name

* test: 🧪 Pass tests.

* feat: ✨ Add Buses, Bus, Qubit and Resonator classes

* refactor: ♻️ Move gain to QbloxPulsarSettings

* docs: 📝 Fix doc typos.

* feat: ✨ Build platform from schema

* refactor: ♻️ Add category in description of schema elements

* docs: 📝 Update instrument docs.

* style: 🎨 Use lists instead of dicts in YAML files

* refactor: ♻️ Edit ResonatorSettings

* refactor: ♻️ Cast elements of schema to Settings class

* refactor: ♻️ Remove name attribute from platform

* test: 🧪 Pass tests.

* style: 🎨 Fix return type of NameHashTable

* docs: 📝 Fix docs

* refactor: ♻️ Build Qubit classes before loading Resonator class.

Also changed 'id' variable to 'id_' to avoid pylint error

* refactor: ♻️ Load resonator qubits into settings before loading Resonator class

* refactor: ♻️ Move hash table inside platforms module

* refactor: ♻️ Remove load_buses and load_schema methods

* docs: 📝 Fix docs

* docs: 📝 Fix docs

* feat: ✨ Add dump() method to Platform class

* feat: ✨ Load platform from YAML file

* test: 🧪 Pass tests.

* test: 🧪 Pass tests randomly.

* refactor: ♻️ Separate YAML platform builder with DB builder.

* refactor: ♻️ Add abstract PlatformBuilder.

* docs: 📝 Add example with PlatformBuilderYAML

* docs: 📝 Fix Instrument docs

* feat: ✨ Add mixer class

* docs: 📝 Remove docstring from parent classes.

* test: 🧪 Pass tests.

* docs: 📝 Fix docs.

* test: 🧪 Add platform tests.

* test: 🧪 Add platform tests.

* test: 🧪 Run platform tests with both DB and YAML platforms.

* test: 🧪 Use argument in test to avoid pylint error

* test: 🧪 Delete useless import.

* refactor: ♻️ Load bus item Settings from yaml.

* refactor: ♻️ Change filename of qubit instruments.

* fix: 🐛 Fix bugs of last commit.

* test: 🧪 100% coverage.

* style: 🎨 Remove useless imports.

* style: 🎨 Remove useless import.

* refactor: ♻️ Load Schema and Buses before Platform.

* refactor: ♻️ Move Buses, Qubit, Resonator and Schema inside Components folder.

* refactor: ♻️ Move enum_dict_factory inside platform/utils.

* refactor: ♻️ Use sorcery to simplify code.

* refactor: ♻️ Change asdict method name to 'to_dict'.

* refactor: ♻️ Move dump into PlatformBuilder. Return platform dict in __str__.

* refactor: ♻️ Sourcery refactor.

* style: 🎨 Indent printed dict.

* fix: 🐛 Rename qblox files.

* test: 🧪 Fix tests.

* refactor: ♻️ Change PlatformBuilder to PlatformManager.

* docs: 📝 Fix docs.

* refactor: ♻️ Change ENUM comparison.

* fix: 🐛 Add init file.

* refactor: ♻️ Sourcery refactor.

* refactor: ♻️ Rename 'platforms' to 'platform'. Reorder settings files.

* refactor: ♻️ Sourcery refactor.

* refactor: ♻️ Change directory name 'platforms' to 'platform'.

* refactor: ♻️ Move Bus class to separate file.

* refactor: ♻️ Remove useless file.

* refactor: ♻️ Add qubit settings information in resonator settings

* refactor: ♻️ Load all elements from schema

Now schema contains all the settings of each element

* fix: 🐛 Add init file. Mypy fixes.

* feat: ✨ Add __iter__ magic method to Bus and Buses

* fix: 🐛 Fix platform dump and load.

* test: 🧪 Pass all tests.

* feat: ✨ Add settings properties to each class

* refactor: ♻️ Move all settings inside each corresponding class

* test: 🧪 Pass all tests.

* refactor: ♻️ Remove 'platform_name' attribute from SETTINGS_MANAGER

* refactor: ♻️ Remove 'foldername' attribute from SETTINGS_MANAGER

* style: 🎨 Change attribute name to 'data'.

* refactor: ♻️ Change 'append' method to 'add'.

* refactor: ♻️ Change enum name 'CategorySettings' to 'Category'.

Also add enum with draw options

* test: 🧪 Pass tests.

* refactor: ♻️ Remove string literals

* refactor: ♻️ Remove attributes from PlatformManager.

Create SingletonABC class.

* style: 🎨 Fix docs and imports.

* refactor: ♻️ Remove more literals. Add __getitem__ method in Bus and Buses.

* test: 🧪 Add tests.

* test: 🧪 Coverage 100%.

Co-authored-by: Albert Solana <iamtxena@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 26, 2022
1 parent 68a2b9b commit b21ead0
Show file tree
Hide file tree
Showing 23 changed files with 547 additions and 78 deletions.
4 changes: 2 additions & 2 deletions examples/load_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def load_platform_from_database():
def load_platform_from_yaml():
"""Load the platform configuration from the given yaml file."""
filepath = Path(__file__).parent / DEFAULT_PLATFORM_DUMP_FILENAME
platform = PLATFORM_MANAGER_YAML.build_from_yaml(filepath=filepath)
print(f"Platform INFO: {platform}")
platform = PLATFORM_MANAGER_YAML.build(filepath=filepath)
print(f"Platform name: {platform}")


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions src/qililab/platform/components/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ def qubit_readout(self):
def __iter__(self):
"""Redirect __iter__ magic method to iterate over bus elements."""
return self.settings.__iter__()

def __getitem__(self, key):
"""Redirect __get_item__ magic method."""
return self.settings.elements.__getitem__(key)
4 changes: 4 additions & 0 deletions src/qililab/platform/components/buses.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ def add(self, bus: Bus):
def __iter__(self):
"""Redirect __iter__ magic method to iterate over buses."""
return self.buses.__iter__()

def __getitem__(self, key):
"""Redirect __get_item__ magic method."""
return self.buses.__getitem__(key)
4 changes: 1 addition & 3 deletions src/qililab/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Platform:
"""Platform object that describes setup used to control quantum devices.
Args:
settings (Settings): Settings of the platform.
settings (PlatformSettings): Settings of the platform.
schema (Schema): Schema object.
buses (Buses): Container of Bus objects.
"""
Expand Down Expand Up @@ -73,8 +73,6 @@ def category(self):

def to_dict(self):
"""Return all platform information as a dictionary."""
if not hasattr(self, "schema") or not hasattr(self, "buses"):
raise AttributeError("Platform is not loaded.")
platform_dict = {Category.PLATFORM.value: asdict(self.settings, dict_factory=dict_factory)}
schema_dict = {Category.SCHEMA.value: self.schema.to_dict()}
return platform_dict | schema_dict
Expand Down
8 changes: 5 additions & 3 deletions src/qililab/platform/platform_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import yaml

from qililab.config import logger
from qililab.constants import DEFAULT_PLATFORM_DUMP_FILENAME
from qililab.platform.components.buses import Buses
from qililab.platform.components.schema import Schema
Expand All @@ -15,13 +16,14 @@
class PlatformManager(ABC, metaclass=SingletonABC):
"""Manager of platform objects."""

def build(self, **kwargs: str) -> Platform:
def build(self, *args, **kwargs: str) -> Platform:
"""Build platform.
Returns:
Platform: Platform object describing the setup used.
"""
settings = self._load_all_settings(**kwargs)
logger.info("Building platform")
settings = self._load_settings(**kwargs)
schema = Schema(settings=settings[YAMLNames.SCHEMA.value])
buses = Buses(buses=schema.buses)
return Platform(settings=settings[YAMLNames.PLATFORM.value], schema=schema, buses=buses)
Expand All @@ -37,7 +39,7 @@ def dump(self, platform: Platform):
yaml.safe_dump(data=platform.to_dict(), stream=file, sort_keys=False)

@abstractmethod
def _load_all_settings(self, **kwargs: str) -> dict:
def _load_settings(self, **kwargs: str) -> dict:
"""Load platform and schema settings.
Returns:
Expand Down
15 changes: 9 additions & 6 deletions src/qililab/platform/platform_manager_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
)
from qililab.platform.platform_manager import PlatformManager
from qililab.settings import SETTINGS_MANAGER
from qililab.typings import Category


class PlatformManagerDB(PlatformManager):
"""Manager of platform objects."""

def _load_all_settings(self, **kwargs: str) -> dict:
PLATFORM_NAME = "platform_name"

def _load_settings(self, *args, **kwargs: str) -> dict:
"""Load platform and schema settings.
Args:
Expand All @@ -19,14 +22,14 @@ def _load_all_settings(self, **kwargs: str) -> dict:
Returns:
dict: Dictionary with platform and schema settings.
"""
if "platform_name" not in kwargs:
raise ValueError("Please provide a 'platform_name' argument.")
platform_name = kwargs["platform_name"]
if self.PLATFORM_NAME not in kwargs:
raise ValueError(f"Please provide a '{self.PLATFORM_NAME}' keyword argument.")
platform_name = kwargs[self.PLATFORM_NAME]
return {
"platform": SETTINGS_MANAGER.load(
Category.PLATFORM.value: SETTINGS_MANAGER.load(
foldername=DEFAULT_SETTINGS_FOLDERNAME, platform_name=platform_name, filename=DEFAULT_PLATFORM_FILENAME
),
"schema": SETTINGS_MANAGER.load(
Category.SCHEMA.value: SETTINGS_MANAGER.load(
foldername=DEFAULT_SETTINGS_FOLDERNAME, platform_name=platform_name, filename=DEFAULT_SCHEMA_FILENAME
),
}
15 changes: 10 additions & 5 deletions src/qililab/platform/platform_manager_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
class PlatformManagerYAML(PlatformManager):
"""Manager of platform objects. Uses YAML file to get the corresponding settings."""

def _load_all_settings(self, **kwargs: str) -> dict:
FILEPATH = "filepath"

def _load_settings(self, *args, **kwargs: str) -> dict:
"""Load platform and schema settings.
Args:
Expand All @@ -16,9 +18,12 @@ def _load_all_settings(self, **kwargs: str) -> dict:
Returns:
dict: Dictionary with platform and schema settings.
"""
if "filepath" not in kwargs:
raise ValueError("Please provide a 'filepath' argument.")
filepath = kwargs["filepath"]
if self.FILEPATH not in kwargs:
raise ValueError(f"Please provide a '{self.FILEPATH}' keyword argument.")
filepath = kwargs[self.FILEPATH]
with open(file=filepath, mode="r", encoding="utf-8") as file:
data = yaml.safe_load(file)
return {"platform": data[Category.PLATFORM.value], "schema": data[Category.SCHEMA.value]}
return {
Category.PLATFORM.value: data[Category.PLATFORM.value],
Category.SCHEMA.value: data[Category.SCHEMA.value],
}
31 changes: 25 additions & 6 deletions tests/unit/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"max_voltage": 1775,
}

qcm_0_settings_sample = {
qblox_qcm_0_settings_sample = {
"id_": 0,
"name": "qblox_qcm",
"category": "qubit_control",
Expand All @@ -37,7 +37,7 @@
"gain": 1,
}

qrm_0_settings_sample = {
qblox_qrm_0_settings_sample = {
"id_": 0,
"name": "qblox_qrm",
"category": "qubit_readout",
Expand Down Expand Up @@ -137,7 +137,7 @@
"name": "bus",
"category": "bus",
"elements": [
qcm_0_settings_sample,
qblox_qcm_0_settings_sample,
rohde_schwarz_0_settings_sample,
mixer_0_settings_sample,
resonator_0_settings_sample,
Expand All @@ -148,7 +148,7 @@
"name": "bus",
"category": "bus",
"elements": [
qrm_0_settings_sample,
qblox_qrm_0_settings_sample,
rohde_schwarz_1_settings_sample,
mixer_1_settings_sample,
resonator_0_settings_sample,
Expand All @@ -169,12 +169,30 @@
}


all_platform_yaml_sample = {
"platform": {
"id_": 0,
"name": "platform_0",
"category": "platform",
"number_qubits": 1,
"hardware_average": 4096,
"software_average": 10,
"repetition_duration": 200000,
"delay_between_pulses": 0,
"delay_before_readout": 50,
"drag_coefficient": 0,
"number_of_sigmas": 4,
},
"schema": schema_settings_sample,
}


class MockedSettingsHashTable:
"""Hash table that relates settings files to mocked data."""

platform = platform_settings_sample
qblox_qcm_0 = qcm_0_settings_sample
qblox_qrm_0 = qrm_0_settings_sample
qblox_qcm_0 = qblox_qcm_0_settings_sample
qblox_qrm_0 = qblox_qrm_0_settings_sample
qubit_0 = qubit_0_settings_sample
resonator_0 = resonator_0_settings_sample
rohde_schwarz_0 = rohde_schwarz_0_settings_sample
Expand All @@ -183,6 +201,7 @@ class MockedSettingsHashTable:
mixer_0 = mixer_0_settings_sample
mixer_1 = mixer_1_settings_sample
mixer_2 = mixer_2_settings_sample
all_platform = all_platform_yaml_sample

@classmethod
def get(cls, name: str) -> dict:
Expand Down
41 changes: 0 additions & 41 deletions tests/unit/instruments/data.py

This file was deleted.

52 changes: 52 additions & 0 deletions tests/unit/instruments/test_mixer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from qililab.instruments import Mixer

from ..data import mixer_0_settings_sample


@pytest.fixture(name="mixer")
def fixture_mixer() -> Mixer:
"""Load Mixer.
Returns:
Mixer: Instance of the Mixer class.
"""

return Mixer(settings=mixer_0_settings_sample)


class TestMixer:
"""Unit tests checking the Mixer attributes and methods."""

def test_id_property(self, mixer: Mixer):
"""Test id property."""
assert mixer.id_ == mixer.settings.id_

def test_name_property(self, mixer: Mixer):
"""Test name property."""
assert mixer.name == mixer.settings.name

def test_category_property(self, mixer: Mixer):
"""Test category property."""
assert mixer.category == mixer.settings.category

def test_epsilon_property(self, mixer: Mixer):
"""Test epsilon property."""
assert mixer.epsilon == mixer.settings.epsilon

def test_delta_property(self, mixer: Mixer):
"""Test delta property."""
assert mixer.delta == mixer.settings.delta

def test_offset_i_property(self, mixer: Mixer):
"""Test offset_i property."""
assert mixer.offset_i == mixer.settings.offset_i

def test_offset_q_property(self, mixer: Mixer):
"""Test offset_q property."""
assert mixer.offset_q == mixer.settings.offset_q

def test_up_conversion_property(self, mixer: Mixer):
"""Test up_conversion_property."""
assert mixer.up_conversion == mixer.settings.up_conversion
20 changes: 18 additions & 2 deletions tests/unit/instruments/test_qblox_pulsar_qcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from qililab.instruments import QbloxPulsarQCM
from qililab.settings import SETTINGS_MANAGER

from .data import qcm_0_settings_sample
from ..data import qblox_qcm_0_settings_sample


@pytest.fixture(name="qcm")
@patch("qililab.instruments.qblox.qblox_pulsar.Pulsar", autospec=True)
@patch("qililab.settings.settings_manager.yaml.safe_load", return_value=qcm_0_settings_sample)
@patch("qililab.settings.settings_manager.yaml.safe_load", return_value=qblox_qcm_0_settings_sample)
def fixture_qcm(mock_load: MagicMock, mock_pulsar: MagicMock):
"""Return connected instance of QbloxPulsarQCM class"""
# add dynamically created attributes
Expand Down Expand Up @@ -81,3 +81,19 @@ def test_not_connected_attribute_error(self, qcm: QbloxPulsarQCM):
qcm.close()
with pytest.raises(AttributeError):
qcm.start()

def test_ip_property(self, qcm: QbloxPulsarQCM):
"""Test ip property."""
assert qcm.ip == qcm.settings.ip

def test_id_property(self, qcm: QbloxPulsarQCM):
"""Test id property."""
assert qcm.id_ == qcm.settings.id_

def test_name_property(self, qcm: QbloxPulsarQCM):
"""Test name property."""
assert qcm.name == qcm.settings.name

def test_category_property(self, qcm: QbloxPulsarQCM):
"""Test category property."""
assert qcm.category == qcm.settings.category
Loading

0 comments on commit b21ead0

Please # to comment.