Skip to content

Add types to Instrument classes #6087

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

Merged
merged 12 commits into from
May 21, 2024
4 changes: 2 additions & 2 deletions docs/changes/newsfragments/6012.breaking
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ This also means that the these arguments **must** be passed as keyword arguments
This specifically includeds passing ``label`` and ``metadata`` to direct subclasses of ``Instrument`` as well as
``terminator`` to subclasses of ``VisaInstrument``.

All drivers shipping with qcodes for Vendors from A-K have been updated.
The remaining drivers will be updated in a subsequent pull request.
All drivers shipping with qcodes for Vendors from A-K have been updated in this pr.
The remaining drivers were updated in (:pr:`6087`).
63 changes: 44 additions & 19 deletions src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
cast,
)

from qcodes.instrument import ChannelList, InstrumentChannel, VisaInstrument
from qcodes.instrument import (
ChannelList,
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)
from qcodes.parameters import Group, GroupParameter
from qcodes.validators import Enum, Numbers

if TYPE_CHECKING:
from collections.abc import Iterable

from typing_extensions import Buffer, Self
from typing_extensions import Buffer, Self, Unpack


def _read_curve_file(curve_file: TextIO) -> dict[Any, Any]:
Expand Down Expand Up @@ -154,11 +160,15 @@
valid_sensor_units = ("mV", "V", "Ohm", "log Ohm")
temperature_key = "Temperature (K)"

def __init__(self, parent: "LakeshoreModel325", index: int) -> None:

def __init__(
self,
parent: "LakeshoreModel325",
index: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
self._index = index
name = f"curve_{index}"
super().__init__(parent, name)
super().__init__(parent, name, **kwargs)

Check warning on line 171 in src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py#L171

Added line #L171 was not covered by tests

self.add_parameter("serial_number", parameter_class=GroupParameter)

Expand Down Expand Up @@ -288,8 +298,13 @@
inp (str): Either "A" or "B"
"""

def __init__(self, parent: "LakeshoreModel325", name: str, inp: str) -> None:

def __init__(
self,
parent: "LakeshoreModel325",
name: str,
inp: str,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
if inp not in ["A", "B"]:
raise ValueError("Please either specify input 'A' or 'B'")

Expand Down Expand Up @@ -365,21 +380,27 @@


class LakeshoreModel325Heater(InstrumentChannel):
"""
InstrumentChannel for heater control on a Lakeshore Model 325.

Args:
parent (LakeshoreModel325): The instrument this heater belongs to
name (str)
loop (int): Either 1 or 2
"""
def __init__(
self,
parent: "LakeshoreModel325",
name: str,
loop: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
"""
InstrumentChannel for heater control on a Lakeshore Model 325.

def __init__(self, parent: "LakeshoreModel325", name: str, loop: int) -> None:
Args:
parent: The instrument this heater belongs to
name: Name of the Channel
loop: Either 1 or 2
**kwargs: Forwarded to baseclass.
"""

if loop not in [1, 2]:
raise ValueError("Please either specify loop 1 or 2")

super().__init__(parent, name)
super().__init__(parent, name, **kwargs)

Check warning on line 403 in src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py#L403

Added line #L403 was not covered by tests
self._loop = loop

self.add_parameter(
Expand Down Expand Up @@ -514,8 +535,12 @@
QCoDeS driver for Lakeshore Model 325 Temperature Controller.
"""

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
super().__init__(name, address, terminator="\r\n", **kwargs)
default_terminator = "\r\n"

def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

Check warning on line 543 in src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_325.py#L543

Added line #L543 was not covered by tests

sensors = ChannelList(
self, "sensor", LakeshoreModel325Sensor, snapshotable=False
Expand Down
37 changes: 29 additions & 8 deletions src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_336.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from typing import Any, ClassVar
from typing import TYPE_CHECKING, ClassVar

import qcodes.validators as vals
from qcodes.parameters import Group, GroupParameter

from .lakeshore_base import BaseOutput, BaseSensorChannel, LakeshoreBase

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import InstrumentBaseKWArgs, VisaInstrumentKWArgs

# There are 4 sensors channels (a.k.a. measurement inputs) in Model 336.
# Unlike other Lakeshore models, Model 336 refers to the channels using
# letters, and not numbers
Expand Down Expand Up @@ -42,9 +47,13 @@ class LakeshoreModel336CurrentSource(BaseOutput):
}

def __init__(
self, parent: "LakeshoreModel336", output_name: str, output_index: int
self,
parent: "LakeshoreModel336",
output_name: str,
output_index: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
):
super().__init__(parent, output_name, output_index, has_pid=True)
super().__init__(parent, output_name, output_index, has_pid=True, **kwargs)

self.P.vals = vals.Numbers(0.1, 1000)
self.I.vals = vals.Numbers(0.1, 1000)
Expand All @@ -71,9 +80,13 @@ class LakeshoreModel336VoltageSource(BaseOutput):
RANGES: ClassVar[dict[str, int]] = {"off": 0, "low": 1, "medium": 2, "high": 3}

def __init__(
self, parent: "LakeshoreModel336", output_name: str, output_index: int
self,
parent: "LakeshoreModel336",
output_name: str,
output_index: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
):
super().__init__(parent, output_name, output_index, has_pid=False)
super().__init__(parent, output_name, output_index, has_pid=False, **kwargs)


class LakeshoreModel336Channel(BaseSensorChannel):
Expand All @@ -91,8 +104,14 @@ class LakeshoreModel336Channel(BaseSensorChannel):
128: "Sensor Units Overrange",
}

def __init__(self, parent: "LakeshoreModel336", name: str, channel: str):
super().__init__(parent, name, channel)
def __init__(
self,
parent: "LakeshoreModel336",
name: str,
channel: str,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
):
super().__init__(parent, name, channel, **kwargs)

# Parameters related to Input Type Parameter Command (INTYPE)
self.add_parameter(
Expand Down Expand Up @@ -174,7 +193,9 @@ class LakeshoreModel336(LakeshoreBase):
_channel_name_to_command_map
)

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

self.output_1 = LakeshoreModel336CurrentSource(self, "output_1", 1)
Expand Down
29 changes: 23 additions & 6 deletions src/qcodes/instrument_drivers/Lakeshore/Lakeshore_model_372.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, ClassVar
from typing import TYPE_CHECKING, Any, ClassVar

import qcodes.validators as vals
from qcodes.instrument_drivers.Lakeshore.lakeshore_base import (
Expand All @@ -8,6 +8,11 @@
)
from qcodes.parameters import Group, GroupParameter

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import InstrumentBaseKWArgs, VisaInstrumentKWArgs

# There are 16 sensors channels (a.k.a. measurement inputs) in Model 372
_n_channels = 16

Expand Down Expand Up @@ -43,9 +48,13 @@ class LakeshoreModel372Output(BaseOutput):
}

def __init__(
self, parent: "LakeshoreModel372", output_name: str, output_index: int
self,
parent: "LakeshoreModel372",
output_name: str,
output_index: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
super().__init__(parent, output_name, output_index, has_pid=True)
super().__init__(parent, output_name, output_index, has_pid=True, **kwargs)

# Add more parameters for OUTMODE command
# and redefine the corresponding group
Expand Down Expand Up @@ -111,8 +120,14 @@ class LakeshoreModel372Channel(BaseSensorChannel):
128: "T. UNDER",
}

def __init__(self, parent: "LakeshoreModel372", name: str, channel: str):
super().__init__(parent, name, channel)
def __init__(
self,
parent: "LakeshoreModel372",
name: str,
channel: str,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
):
super().__init__(parent, name, channel, **kwargs)

# Parameters related to Input Channel Parameter Command (INSET)
self.add_parameter(
Expand Down Expand Up @@ -298,7 +313,9 @@ class LakeshoreModel372(LakeshoreBase):

CHANNEL_CLASS = LakeshoreModel372Channel

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

heaters = {"sample_heater": 0, "warmup_heater": 1, "analog_heater": 2}
Expand Down
22 changes: 17 additions & 5 deletions src/qcodes/instrument_drivers/Lakeshore/Model_325.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
from collections.abc import Iterable
from enum import IntFlag
from itertools import takewhile
from typing import Any, Optional, TextIO, cast

from qcodes.instrument import ChannelList, InstrumentChannel, VisaInstrument
from typing import TYPE_CHECKING, Any, Optional, TextIO, cast

from qcodes.instrument import (
ChannelList,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)
from qcodes.parameters import Group, GroupParameter
from qcodes.validators import Enum, Numbers

Expand All @@ -19,14 +24,21 @@
from .Lakeshore_model_325 import _get_sanitize_data as get_sanitize_data
from .Lakeshore_model_325 import _read_curve_file as read_curve_file

if TYPE_CHECKING:
from typing_extensions import Unpack


class Model_325(VisaInstrument):
"""
Lakeshore Model 325 Temperature Controller Driver
"""

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
super().__init__(name, address, terminator="\r\n", **kwargs)
default_terminator = "\r\n"

def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

Check warning on line 41 in src/qcodes/instrument_drivers/Lakeshore/Model_325.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Lakeshore/Model_325.py#L41

Added line #L41 was not covered by tests

sensors = ChannelList(
self, "sensor", Model_325_Sensor, snapshotable=False)
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Lakeshore/Model_336.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
It will eventually be deprecated and removed
"""

from typing import Any, ClassVar
from typing import TYPE_CHECKING, Any, ClassVar

import qcodes.validators as vals
from qcodes.parameters import Group, GroupParameter
Expand All @@ -18,6 +18,11 @@
)
from .Lakeshore_model_336 import _channel_name_to_command_map

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class Model_336(LakeshoreBase):
"""
Expand All @@ -31,7 +36,9 @@ class Model_336(LakeshoreBase):
input_channel_parameter_values_to_channel_name_on_instrument = \
_channel_name_to_command_map

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

self.output_1 = Output_336_CurrentSource(self, "output_1", 1) # type: ignore[arg-type]
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Lakeshore/Model_372.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
It will eventually be deprecated and removed
"""

from typing import Any, ClassVar
from typing import TYPE_CHECKING, Any, ClassVar

import qcodes.validators as vals
from qcodes.instrument_drivers.Lakeshore.lakeshore_base import (
Expand All @@ -16,6 +16,11 @@
from .Lakeshore_model_372 import LakeshoreModel372Channel as Model_372_Channel
from .Lakeshore_model_372 import LakeshoreModel372Output as Output_372

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs

# There are 16 sensors channels (a.k.a. measurement inputs) in Model 372
_n_channels = 16

Expand All @@ -37,7 +42,9 @@ class Model_372(LakeshoreBase):

CHANNEL_CLASS = Model_372_Channel

def __init__(self, name: str, address: str, **kwargs: Any) -> None:
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)

heaters = {'sample_heater': 0, 'warmup_heater': 1, 'analog_heater': 2}
Expand Down
Loading
Loading