Skip to content

Commit

Permalink
feat: [QILI-81] Implement schema class (#5)
Browse files Browse the repository at this point in the history
* 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

* 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 #4

* 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 #4

* 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.

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

* fix: 🐛 Fix bugs of last commit.

* 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.

* feat: ✨ Add settings properties to each class

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

* 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: ♻️ Change method name.

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 committed Apr 26, 2022
1 parent b7c7c4f commit 101f8cf
Show file tree
Hide file tree
Showing 74 changed files with 1,875 additions and 557 deletions.
152 changes: 152 additions & 0 deletions examples/all_platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
platform:
id_: 0
name: platform
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:
id_: 0
name: qili_schema
category: schema
buses:
- id_: 0
name: bus
category: bus
elements:
- id_: 0
name: qblox_qcm
category: qubit_control
ip: 192.168.0.3
reference_clock: internal
sequencer: 0
sync_enabled: true
gain: 1
- id_: 0
name: rohde_schwarz
category: signal_generator
ip: 192.168.0.10
power: 15
frequency: 3644000000.0
- id_: 0
name: mixer
category: mixer
epsilon: 0
delta: 0
offset_i: 0
offset_q: 0
up_conversion: true
- id_: 0
name: resonator
category: resonator
qubits:
- id_: 0
name: qubit
category: qubit
pi_pulse_amplitude: 1
pi_pulse_duration: 100
pi_pulse_frequency: 100000000.0
qubit_frequency: 3544000000.0
min_voltage: 950
max_voltage: 1775
- id_: 1
name: bus
category: bus
elements:
- id_: 0
name: qblox_qrm
category: qubit_readout
ip: 192.168.0.4
reference_clock: external
sequencer: 0
sync_enabled: true
gain: 0.5
acquire_trigger_mode: sequencer
hardware_average_enabled: true
start_integrate: 130
sampling_rate: 1000000000
integration_length: 2000
integration_mode: ssb
sequence_timeout: 1
acquisition_timeout: 1
acquisition_name: single
- id_: 1
name: rohde_schwarz
category: signal_generator
ip: 192.168.0.7
power: 15
frequency: 7307720000.0
- id_: 0
name: resonator
category: resonator
qubits:
- id_: 0
name: qubit
category: qubit
pi_pulse_amplitude: 1
pi_pulse_duration: 100
pi_pulse_frequency: 100000000.0
qubit_frequency: 3544000000.0
min_voltage: 950
max_voltage: 1775
- id_: 1
name: mixer
category: mixer
epsilon: 0
delta: 0
offset_i: 0
offset_q: 0
up_conversion: true
- id_: 2
name: bus
category: bus
elements:
- id_: 0
name: qblox_qrm
category: qubit_readout
ip: 192.168.0.4
reference_clock: external
sequencer: 0
sync_enabled: true
gain: 0.5
acquire_trigger_mode: sequencer
hardware_average_enabled: true
start_integrate: 130
sampling_rate: 1000000000
integration_length: 2000
integration_mode: ssb
sequence_timeout: 1
acquisition_timeout: 1
acquisition_name: single
- id_: 1
name: rohde_schwarz
category: signal_generator
ip: 192.168.0.7
power: 15
frequency: 7307720000.0
- id_: 0
name: resonator
category: resonator
qubits:
- id_: 0
name: qubit
category: qubit
pi_pulse_amplitude: 1
pi_pulse_duration: 100
pi_pulse_frequency: 100000000.0
qubit_frequency: 3544000000.0
min_voltage: 950
max_voltage: 1775
- id_: 2
name: mixer
category: mixer
epsilon: 0
delta: 0
offset_i: 0
offset_q: 0
up_conversion: false
28 changes: 20 additions & 8 deletions examples/load_platform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pathlib import Path

import qibo

from qililab import PLATFORM_BUILDER
from qililab import PLATFORM_MANAGER_DB, PLATFORM_MANAGER_YAML
from qililab.constants import DEFAULT_PLATFORM_DUMP_FILENAME, DEFAULT_PLATFORM_NAME

# FIXME: Need to add backend in qibo's profiles.yml file
backend = {
Expand All @@ -13,15 +16,24 @@
# ------------------------------------------------------


def load_platform():
"""Load the platform 'platform_0' from the settings folder."""
def load_platform_from_database():
"""Load the platform 'platform_0' from the DB."""
# Using qibo (needed when using qibo circuits)
qibo.set_backend(backend="qililab", platform="platform_0")
qibo.set_backend(backend="qililab", platform=DEFAULT_PLATFORM_NAME)
print(f"Platform name: {qibo.K.platform}")
# Using PLATFORM_BUILDER
platform = PLATFORM_BUILDER.build(name="platform_0")
print(f"Platform name: {platform}")
# Using PLATFORM_MANAGER_DB
platform = PLATFORM_MANAGER_DB.build(platform_name=DEFAULT_PLATFORM_NAME)
PLATFORM_MANAGER_DB.dump(platform=platform) # save yaml file with all platform settings
print(f"Platform INFO: {platform}")


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}")


if __name__ == "__main__":
load_platform()
load_platform_from_database()
load_platform_from_yaml()
2 changes: 1 addition & 1 deletion src/qililab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .circuit import HardwareCircuit
from .gates import I, X, Y, Z
from .platforms import PLATFORM_BUILDER
from .platform import PLATFORM_MANAGER_DB, PLATFORM_MANAGER_YAML
6 changes: 3 additions & 3 deletions src/qililab/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qililab import gates
from qililab.circuit import HardwareCircuit
from qililab.platforms import PLATFORM_BUILDER, Platform
from qililab.platform import PLATFORM_MANAGER_DB, Platform


class QililabBackend(NumpyBackend):
Expand Down Expand Up @@ -32,14 +32,14 @@ def set_platform(self, platform: str):
Args:
name (str): Name of the platform.
"""
self.platform = PLATFORM_BUILDER.build(name=platform)
self.platform = PLATFORM_MANAGER_DB.build(platform_name=platform)

def get_platform(self) -> str:
"""
Returns:
str: Platform name.
"""
return str(self.platform)
return self.platform.name

def circuit_class(self, accelerators: dict = None, density_matrix: bool = False) -> Type[HardwareCircuit]:
"""
Expand Down
3 changes: 3 additions & 0 deletions src/qililab/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

DEFAULT_PLATFORM_FILENAME = "platform"
DEFAULT_SETTINGS_FOLDERNAME = "qili"
DEFAULT_SCHEMA_FILENAME = "schema"
DEFAULT_PLATFORM_DUMP_FILENAME = "all_platform.yml"
DEFAULT_PLATFORM_NAME = "platform_0"
1 change: 1 addition & 0 deletions src/qililab/instruments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .mixer import Mixer
from .qblox.qblox_pulsar_qcm import QbloxPulsarQCM
from .qblox.qblox_pulsar_qrm import QbloxPulsarQRM
from .qubit_control import QubitControl
Expand Down
57 changes: 52 additions & 5 deletions src/qililab/instruments/instrument.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Instrument class"""
from abc import ABC, abstractmethod
from dataclasses import dataclass
from functools import partial
from typing import Callable

Expand All @@ -12,11 +13,19 @@ class Instrument(ABC):
and methods for the instruments connected via TCP/IP.
Args:
name (str): Name of the instrument.
device (Device): Class used for connecting to the instrument.
settings (Settings): Class containing the settings of the instrument.
"""

device: Device # a subtype of device must be specified by the subclass
settings: Settings # a subtype of settings must be specified by the subclass
@dataclass
class InstrumentSettings(Settings):
"""Contains the settings of an instrument.
Args:
ip (str): IP address of the instrument.
"""

ip: str

class CheckConnected:
"""Property used to check if the instrument is connected."""
Expand All @@ -40,8 +49,10 @@ def __call__(self, ref: "Instrument", *args, **kwargs):
raise AttributeError("Instrument is not connected")
return self._method(ref, *args, **kwargs)

def __init__(self, name: str):
self.name = name
device: Device # a subtype of device must be specified by the subclass
settings: InstrumentSettings # a subtype of settings must be specified by the subclass

def __init__(self):
self._connected = False

def connect(self):
Expand Down Expand Up @@ -73,3 +84,39 @@ def stop(self):
@abstractmethod
def _initialize_device(self):
"""Initialize device attribute to the corresponding device class."""

@property
def id_(self):
"""Instrument 'id' property.
Returns:
int: settings.id_.
"""
return self.settings.id_

@property
def name(self):
"""Instrument 'name' property.
Returns:
str: settings.name.
"""
return self.settings.name

@property
def category(self):
"""Instrument 'category' property.
Returns:
str: settings.category.
"""
return self.settings.category

@property
def ip(self):
"""Instrument 'ip' property.
Returns:
str: settings.ip.
"""
return self.settings.ip
Loading

0 comments on commit 101f8cf

Please sign in to comment.