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

Drivers/move_params_and_alias_to_abc #698

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
10 changes: 0 additions & 10 deletions src/qililab/drivers/instruments/era_synth/era_synth_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,3 @@ def __init__(self, name: str, address: str, **kwargs: Any) -> None:
source=self.parameters["frequency"],
parameter_class=DelegateParameter,
)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name
20 changes: 0 additions & 20 deletions src/qililab/drivers/instruments/keithley/keithley_2600.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ def __init__(self, name: str, address: str, **kwargs):
self.add_submodule(ch_name, channel)
self.channels.append(channel)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


class Keithley2600Channel(QCodesKeithley2600Channel, VoltageSource, CurrentSource):
"""
Expand All @@ -67,16 +57,6 @@ class Keithley2600Channel(QCodesKeithley2600Channel, VoltageSource, CurrentSourc
channel (str): The name used by the Keithley, i.e. either 'smua' or 'smub'
"""

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name

def on(self) -> None:
"""Turn output on"""
self.set(param_name="output", value="on")
Expand Down
42 changes: 1 addition & 41 deletions src/qililab/drivers/instruments/qblox/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


@InstrumentDriverFactory.register
class Cluster(QcodesCluster, BaseInstrument): # pylint: disable=abstract-method
class Cluster(QcodesCluster, BaseInstrument):
"""Qililab's driver for QBlox-instruments Cluster.

Args:
Expand Down Expand Up @@ -65,16 +65,6 @@ def __init__(self, name: str, address: str | None = None, **kwargs):
old_module = old_submodules[f"module{slot_idx}"]
self.add_submodule(f"module{slot_idx}", old_module)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


class QcmQrm(QcodesQcmQrm, BaseInstrument):
"""Qililab's driver for QBlox-instruments QcmQrm
Expand Down Expand Up @@ -113,16 +103,6 @@ def __init__(self, parent: Instrument, name: str, slot_idx: int):
att = QcmQrmRfAtt(name=f"{name}_attenuator_{channel}", parent=self, channel=channel)
self.add_submodule(f"{name}_attenuator_{channel}", att)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


class QcmQrmRfLo(InstrumentModule, LocalOscillator):
"""LO driver for the QCM / QRM - RF instrument
Expand All @@ -148,16 +128,6 @@ def __init__(self, name: str, parent: QcmQrm, channel: str, **kwargs):
parameter_class=DelegateParameter,
)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name

def on(self):
self.set("status", True)

Expand All @@ -182,13 +152,3 @@ def __init__(self, name: str, parent: QcmQrm, channel: str, **kwargs):
source=parent.parameters[f"{channel}_att"],
parameter_class=DelegateParameter,
)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name
12 changes: 1 addition & 11 deletions src/qililab/drivers/instruments/qblox/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


@InstrumentDriverFactory.register
class Pulsar(QcodesPulsar, BaseInstrument): # pylint: disable=abstract-method
class Pulsar(QcodesPulsar, BaseInstrument):
"""Qililab's driver for QBlox-instruments Pulsar

Args:
Expand All @@ -44,13 +44,3 @@ def __init__(self, name: str, address: str | None = None, **kwargs):
for seq_idx in range(6):
seq = sequencer_class(parent=self, name=f"sequencer{seq_idx}", seq_idx=seq_idx) # type: ignore
self.add_submodule(f"sequencer{seq_idx}", seq)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name
10 changes: 0 additions & 10 deletions src/qililab/drivers/instruments/qblox/sequencer_qcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ def __init__(self, parent: Instrument, name: str, seq_idx: int):
super().__init__(parent=parent, name=name, seq_idx=seq_idx)
self.add_parameter(name="swap_paths", set_cmd=None, vals=vals.Bool(), initial_value=False)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name

def set(self, param_name: str, value: Any):
"""Sets a parameter value checking if is an output mapping.

Expand Down
52 changes: 1 addition & 51 deletions src/qililab/drivers/instruments/qblox/spi_rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# MAIN SpiRack CLASS
@InstrumentDriverFactory.register
class SpiRack(QcodesSpiRack, BaseInstrument): # pylint: disable=abstract-method
class SpiRack(QcodesSpiRack, BaseInstrument):
"""
Qililab's driver for the Qblox SpiRack.

Expand All @@ -48,16 +48,6 @@ def __init__(self, name: str, address: str, **kwargs):
self._MODULES_MAP["S4g"] = S4gModule
self._MODULES_MAP["D5a"] = D5aModule

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


# MODULE CLASSES that select the channels
class D5aModule(QcodesD5aModule, BaseInstrument):
Expand Down Expand Up @@ -86,16 +76,6 @@ def __init__(self, parent: Instrument, name: str, address: int, **kwargs):
self._channels[dac] = new_channel
self.add_submodule(old_channel._chan_name, new_channel)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


class S4gModule(QcodesS4gModule, BaseInstrument):
"""
Expand Down Expand Up @@ -124,16 +104,6 @@ def __init__(self, parent: Instrument, name: str, address: int, **kwargs):
self._channels[dac] = new_channel
self.add_submodule(old_channel._chan_name, new_channel)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name


# CHANNELS CLASSES that act as the corresponding Voltage/Current sources.
class D5aDacChannel(QcodesD5aDacChannel, VoltageSource):
Expand All @@ -148,16 +118,6 @@ class D5aDacChannel(QcodesD5aDacChannel, VoltageSource):
dac (int): Number of the dac that this channel corresponds to
"""

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name

def on(self) -> None:
"""Start D5aDacChannel"""

Expand All @@ -178,16 +138,6 @@ class S4gDacChannel(QcodesS4gDacChannel, CurrentSource):
dac (int): Number of the dac that this channel corresponds to
"""

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name

def on(self) -> None:
"""Start S4gDacChannel"""

Expand Down
10 changes: 0 additions & 10 deletions src/qililab/drivers/instruments/rohde_schwarz/sgs100a.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,3 @@ def __init__(self, name: str, address: str, **kwargs: Any) -> None:
source=self.parameters["frequency"],
parameter_class=DelegateParameter,
)

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name
10 changes: 0 additions & 10 deletions src/qililab/drivers/instruments/yokogawa/yokogawa_gs200.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,3 @@ def __init__(self, name: str, address: str, **kwargs):
self.add_submodule("measure", QCodesGS200Monitor(self, name="measure", present=True))
# Add the Program to the instrument
self.add_submodule("program", QCodesGS200Program(self, name="program"))

@property
def params(self):
"""return the parameters of the instrument"""
return self.parameters

@property
def alias(self):
"""return the alias of the instrument, which corresponds to the QCodes name attribute"""
return self.name
2 changes: 1 addition & 1 deletion src/qililab/drivers/interfaces/attenuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@


@InstrumentInterfaceFactory.register
class Attenuator(BaseInstrument): # pylint: disable=abstract-method
class Attenuator(BaseInstrument):
"""Interface of an attenuator."""
11 changes: 1 addition & 10 deletions src/qililab/drivers/interfaces/base_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@
from typing import Any


# pylint: disable=no-member
class BaseInstrument(ABC):
"""Base Interface for all instruments."""

@property
@abstractmethod
def params(self):
"""parameters property."""

@property
@abstractmethod
def alias(self):
"""alias property."""

@abstractmethod
def set(self, param_name: str, value: Any) -> None:
"""Set instrument parameter.
Expand Down
19 changes: 11 additions & 8 deletions src/qililab/platform/components/bus_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from qililab.pulse import PulseBusSchedule, PulseDistortion


# mypy: disable-error-code="attr-defined"
class BusDriver(ABC):
"""Derived: :class:`DriveBus`, :class:`FluxBus` and :class:`ReadoutBus`

Expand Down Expand Up @@ -85,7 +86,9 @@ def set(self, param_name: str, value: Any) -> None:
raise NotImplementedError("Setting distortion parameters of a bus is not yet implemented..")
else:
candidates: list[BaseInstrument | None] = [
instrument for instrument in self.instruments.values() if instrument and param_name in instrument.params
instrument
for instrument in self.instruments.values()
if instrument and param_name in instrument.parameters
]
if len(candidates) == 1 and isinstance(candidates[0], BaseInstrument):
candidates[0].set(param_name, value)
Expand Down Expand Up @@ -116,7 +119,7 @@ def get(self, param_name: str) -> Any:
if param_name == "distortions":
raise NotImplementedError("Getting distortion parameters of a bus is not yet implemented.")
candidates: list[BaseInstrument | None] = [
instrument for instrument in self.instruments.values() if instrument and param_name in instrument.params
instrument for instrument in self.instruments.values() if instrument and param_name in instrument.parameters
]
if len(candidates) == 1 and isinstance(candidates[0], BaseInstrument):
return candidates[0].get(param_name)
Expand Down Expand Up @@ -274,7 +277,7 @@ def __convert_instruments_strings_to_classes_and_set_params(
# If the alias and the interface of the dictionary coincide with one of the given instruments:
if (
issubclass(instrument.__class__, InstrumentInterfaceFactory.get(key))
and instrument.alias == instrument_dict["alias"]
and instrument.name == instrument_dict["name"]
):
# Set parameters of the initialized instrument
if "parameters" in instrument_dict:
Expand Down Expand Up @@ -329,14 +332,14 @@ def __convert_instruments_classes_to_strings_and_get_params(
for instrument in instruments:
if issubclass(instrument.__class__, InstrumentInterfaceFactory.get(key)):
# Add alias of the instrument to the dictionary
instruments_dict[key] = {"alias": instrument.alias}
instruments_dict[key] = {"name": instrument.name}

# This ensures that instruments with multiple interfaces, don't write the same parameters two times
if instrument.alias not in saved_instruments and instrument.params:
if instrument.name not in saved_instruments and instrument.parameters:
# Add parameters of the instrument to the dictionary
instruments_dict[key]["parameters"] = {
parameter: instrument.get(parameter)
for parameter in instrument.params.keys()
for parameter in instrument.parameters.keys()
if parameter
not in (
"IDN",
Expand All @@ -345,7 +348,7 @@ def __convert_instruments_classes_to_strings_and_get_params(
}

# Save already saved instruments, to not write same parameters twice (in different interfaces)
saved_instruments.add(instrument.alias)
saved_instruments.add(instrument.name)
break

return instruments_dict
Expand Down Expand Up @@ -375,6 +378,6 @@ def __str__(self):
"""String representation of a Bus."""
return (
f"{self.alias} ({self.__class__.__name__}): "
+ "".join(f"--|{instrument.alias}|" for instrument in self.instruments.values())
+ "".join(f"--|{instrument.name}|" for instrument in self.instruments.values())
+ f"--> port {self.port}"
)
8 changes: 0 additions & 8 deletions tests/drivers/instruments/era_synth/test_era_synth_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,3 @@ def test_init(self, era_synth_plus):
era_synth_plus.set("frequency", 2)
assert era_synth_plus.get("lo_frequency") == 2
assert era_synth_plus.lo_frequency.label == "Delegated parameter for local oscillator frequency"

def test_params(self, era_synth_plus):
"""Unittest to test the params property."""
assert era_synth_plus.params == era_synth_plus.parameters

def test_alias(self, era_synth_plus):
"""Unittest to test the alias property."""
assert era_synth_plus.alias == era_synth_plus.name
Loading
Loading