From ae551fc524c40e80a0152b549c9cd33e70181d8b Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Sat, 18 May 2024 08:50:28 +0200 Subject: [PATCH] Add types to tektronix drivers --- .../instrument_drivers/tektronix/AWG5014.py | 35 ++++-- .../instrument_drivers/tektronix/AWG5208.py | 21 ++-- .../instrument_drivers/tektronix/AWG70000A.py | 32 ++++-- .../instrument_drivers/tektronix/AWG70002A.py | 17 ++- .../instrument_drivers/tektronix/DPO7200xx.py | 100 +++++++++--------- .../instrument_drivers/tektronix/TPS2012.py | 30 ++++-- .../tektronix/Tektronix_70001A.py | 17 ++- .../tektronix/Tektronix_70001B.py | 17 ++- .../tektronix/Tektronix_70002B.py | 17 ++- 9 files changed, 188 insertions(+), 98 deletions(-) diff --git a/src/qcodes/instrument_drivers/tektronix/AWG5014.py b/src/qcodes/instrument_drivers/tektronix/AWG5014.py index ac7ba3e9af87..18daddab6e48 100644 --- a/src/qcodes/instrument_drivers/tektronix/AWG5014.py +++ b/src/qcodes/instrument_drivers/tektronix/AWG5014.py @@ -6,13 +6,25 @@ from collections.abc import Sequence from io import BytesIO from time import localtime, sleep -from typing import Any, ClassVar, Literal, NamedTuple, Optional, Union, cast +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, + Literal, + NamedTuple, + Optional, + Union, + cast, +) import numpy as np from pyvisa.errors import VisaIOError from qcodes import validators as vals -from qcodes.instrument import VisaInstrument +from qcodes.instrument import VisaInstrument, VisaInstrumentKWArgs + +if TYPE_CHECKING: + from typing_extensions import Unpack log = logging.getLogger(__name__) @@ -135,25 +147,26 @@ class TektronixAWG5014(VisaInstrument): 'DC_OUTPUT_LEVEL_N': 'd', # V } + default_timeout = 180 + def __init__( - self, - name: str, - address: str, - timeout: int = 180, - num_channels: int = 4, - **kwargs: Any): + self, + name: str, + address: str, + *, + num_channels: int = 4, + **kwargs: "Unpack[VisaInstrumentKWArgs]", + ): """ Initializes the AWG5014. Args: name: name of the instrument address: GPIB or ethernet address as used by VISA - timeout: visa timeout, in secs. long default (180) - to accommodate large waveforms num_channels: number of channels on the device **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, timeout=timeout, **kwargs) + super().__init__(name, address, **kwargs) self._address = address self.num_channels = num_channels diff --git a/src/qcodes/instrument_drivers/tektronix/AWG5208.py b/src/qcodes/instrument_drivers/tektronix/AWG5208.py index 27580d2b4057..22d071377232 100644 --- a/src/qcodes/instrument_drivers/tektronix/AWG5208.py +++ b/src/qcodes/instrument_drivers/tektronix/AWG5208.py @@ -1,25 +1,34 @@ -from typing import Any +from typing import TYPE_CHECKING from .AWG70000A import AWG70000A +if TYPE_CHECKING: + from typing_extensions import Unpack + + from qcodes.instrument import VisaInstrumentKWArgs + class TektronixAWG5208(AWG70000A): """ The QCoDeS driver for Tektronix AWG5208 """ - def __init__(self, name: str, address: str, - timeout: float = 10, **kwargs: Any) -> None: + default_timeout = 10 + + def __init__( + self, + name: str, + address: str, + **kwargs: "Unpack[VisaInstrumentKWArgs]", + ) -> None: """ Args: name: The name used internally by QCoDeS in the DataSet address: The VISA resource name of the instrument - timeout: The VISA timeout time (in seconds). **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, num_channels=8, - timeout=timeout, **kwargs) + super().__init__(name, address, num_channels=8, **kwargs) class AWG5208(TektronixAWG5208): diff --git a/src/qcodes/instrument_drivers/tektronix/AWG70000A.py b/src/qcodes/instrument_drivers/tektronix/AWG70000A.py index 73db1d04060f..996c8a8175e2 100644 --- a/src/qcodes/instrument_drivers/tektronix/AWG70000A.py +++ b/src/qcodes/instrument_drivers/tektronix/AWG70000A.py @@ -14,12 +14,21 @@ from broadbean.sequence import InvalidForgedSequenceError, fs_schema from qcodes import validators as vals -from qcodes.instrument import ChannelList, Instrument, InstrumentChannel, VisaInstrument +from qcodes.instrument import ( + ChannelList, + Instrument, + InstrumentBaseKWArgs, + InstrumentChannel, + VisaInstrument, + VisaInstrumentKWArgs, +) from qcodes.parameters import create_on_off_val_mapping if TYPE_CHECKING: from collections.abc import Mapping, Sequence + from typing_extensions import Unpack + log = logging.getLogger(__name__) ################################################## @@ -157,16 +166,23 @@ class Tektronix70000AWGChannel(InstrumentChannel): Class to hold a channel of the AWG. """ - def __init__(self, parent: Instrument, name: str, channel: int) -> None: + def __init__( + self, + parent: Instrument, + name: str, + channel: int, + **kwargs: Unpack[InstrumentBaseKWArgs], + ) -> None: """ Args: parent: The Instrument instance to which the channel is to be attached. name: The name used in the DataSet channel: The channel number, either 1 or 2. + **kwargs: Forwarded to base class. """ - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self.channel = channel @@ -413,27 +429,27 @@ class AWG70000A(VisaInstrument): subclasses of this general class. """ + default_terminator = "\n" + default_timeout = 10 + def __init__( self, name: str, address: str, num_channels: int, - timeout: float = 10, - **kwargs: Any, + **kwargs: Unpack[VisaInstrumentKWArgs], ) -> None: """ Args: name: The name used internally by QCoDeS in the DataSet address: The VISA resource name of the instrument - timeout: The VISA timeout time (in seconds) num_channels: Number of channels on the AWG **kwargs: kwargs are forwarded to base class. """ self.num_channels = num_channels - super().__init__(name, address, timeout=timeout, terminator='\n', - **kwargs) + super().__init__(name, address, **kwargs) # The 'model' value begins with 'AWG' self.model = self.IDN()['model'][3:] diff --git a/src/qcodes/instrument_drivers/tektronix/AWG70002A.py b/src/qcodes/instrument_drivers/tektronix/AWG70002A.py index 18ace056e829..76b7aa658e93 100644 --- a/src/qcodes/instrument_drivers/tektronix/AWG70002A.py +++ b/src/qcodes/instrument_drivers/tektronix/AWG70002A.py @@ -1,7 +1,12 @@ -from typing import Any +from typing import TYPE_CHECKING from .AWG70000A import AWG70000A +if TYPE_CHECKING: + from typing_extensions import Unpack + + from qcodes.instrument import VisaInstrumentKWArgs + class TektronixAWG70002A(AWG70000A): """ @@ -10,8 +15,13 @@ class TektronixAWG70002A(AWG70000A): All the actual driver meat is in the superclass AWG70000A. """ + default_timeout = 10 + def __init__( - self, name: str, address: str, timeout: float = 10, **kwargs: Any + self, + name: str, + address: str, + **kwargs: "Unpack[VisaInstrumentKWArgs]", ) -> None: """ Args: @@ -21,8 +31,7 @@ def __init__( **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, num_channels=2, - timeout=timeout, **kwargs) + super().__init__(name, address, num_channels=2, **kwargs) class AWG70002A(TektronixAWG70002A): diff --git a/src/qcodes/instrument_drivers/tektronix/DPO7200xx.py b/src/qcodes/instrument_drivers/tektronix/DPO7200xx.py index e98c656df3a0..0e39d182d8dc 100644 --- a/src/qcodes/instrument_drivers/tektronix/DPO7200xx.py +++ b/src/qcodes/instrument_drivers/tektronix/DPO7200xx.py @@ -9,9 +9,17 @@ from typing import Any, Callable, ClassVar, Union, cast import numpy as np -from typing_extensions import deprecated - -from qcodes.instrument import ChannelList, Instrument, InstrumentChannel, VisaInstrument +from typing_extensions import Unpack, deprecated + +from qcodes.instrument import ( + ChannelList, + Instrument, + InstrumentBase, + InstrumentBaseKWArgs, + InstrumentChannel, + VisaInstrument, + VisaInstrumentKWArgs, +) from qcodes.parameters import ( Parameter, ParameterWithSetpoints, @@ -52,15 +60,12 @@ class TektronixDPO7000xx(VisaInstrument): number_of_channels = 4 number_of_measurements = 8 # The number of available # measurements does not change. + default_terminator = "\n" def __init__( - self, - name: str, - address: str, - **kwargs: Any + self, name: str, address: str, **kwargs: Unpack[VisaInstrumentKWArgs] ) -> None: - - super().__init__(name, address, terminator="\n", **kwargs) + super().__init__(name, address, **kwargs) self.add_submodule( "horizontal", @@ -146,12 +151,9 @@ class TektronixDPOData(InstrumentChannel): """ def __init__( - self, - parent: Union[Instrument, InstrumentChannel], - name: str + self, parent: InstrumentBase, name: str, **kwargs: Unpack[InstrumentBaseKWArgs] ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) # We can choose to retrieve data from arbitrary # start and stop indices of the buffer. self.add_parameter( @@ -213,13 +215,13 @@ class TektronixDPOWaveform(InstrumentChannel): ] def __init__( - self, - parent: Union[Instrument, InstrumentChannel], - name: str, - identifier: str, + self, + parent: InstrumentBase, + name: str, + identifier: str, + **kwargs: Unpack[InstrumentBaseKWArgs], ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) if identifier not in self.valid_identifiers: raise ValueError( @@ -376,12 +378,9 @@ class TektronixDPOWaveformFormat(InstrumentChannel): """ def __init__( - self, - parent: Union[Instrument, InstrumentChannel], - name: str + self, parent: InstrumentBase, name: str, **kwargs: Unpack[InstrumentBaseKWArgs] ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self.add_parameter( "data_format", @@ -430,13 +429,13 @@ class TektronixDPOChannel(InstrumentChannel): the instrument display. """ def __init__( - self, - parent: Union[Instrument, InstrumentChannel], - name: str, - channel_number: int, + self, + parent: Union[Instrument, InstrumentChannel], + name: str, + channel_number: int, + **kwargs: Unpack[InstrumentBaseKWArgs], ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self._identifier = f"CH{channel_number}" self.add_submodule( @@ -526,12 +525,12 @@ class TektronixDPOHorizontal(InstrumentChannel): """ def __init__( - self, - parent: Union[Instrument, InstrumentChannel], - name: str + self, + parent: Union[Instrument, InstrumentChannel], + name: str, + **kwargs: Unpack[InstrumentBaseKWArgs], ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self.add_parameter( "mode", @@ -643,12 +642,13 @@ class TektronixDPOTrigger(InstrumentChannel): https://download.tek.com/manual/MSO70000C-DX-DPO70000C-DX-MSO-DPO7000C-MSO-DPO5000B-Oscilloscope-Quick-Start-User-Manual-071298006.pdf """ def __init__( - self, - parent: Instrument, - name: str, - delayed_trigger: bool = False + self, + parent: Instrument, + name: str, + delayed_trigger: bool = False, + **kwargs: Unpack[InstrumentBaseKWArgs], ): - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self._identifier = "B" if delayed_trigger else "A" trigger_types = ["edge", "logic", "pulse"] @@ -834,13 +834,13 @@ class TektronixDPOMeasurement(InstrumentChannel): ] def __init__( - self, - parent: Instrument, - name: str, - measurement_number: int + self, + parent: Instrument, + name: str, + measurement_number: int, + **kwargs: Unpack[InstrumentBaseKWArgs], ) -> None: - - super().__init__(parent, name) + super().__init__(parent, name, **kwargs) self._measurement_number = measurement_number self._adjustment_time = time.perf_counter() @@ -909,8 +909,10 @@ def wait_adjustment_time(self) -> None: class TektronixDPOMeasurementStatistics(InstrumentChannel): - def __init__(self, *args: Any, **kwargs: Any): - super().__init__(*args, **kwargs) + def __init__( + self, parent: InstrumentBase, name: str, **kwargs: Unpack[InstrumentBaseKWArgs] + ): + super().__init__(parent=parent, name=name, **kwargs) self.add_parameter( "mode", diff --git a/src/qcodes/instrument_drivers/tektronix/TPS2012.py b/src/qcodes/instrument_drivers/tektronix/TPS2012.py index be6ab92bb441..5ed2bb886eb2 100644 --- a/src/qcodes/instrument_drivers/tektronix/TPS2012.py +++ b/src/qcodes/instrument_drivers/tektronix/TPS2012.py @@ -5,10 +5,16 @@ import numpy as np from pyvisa.errors import VisaIOError -from typing_extensions import TypedDict +from typing_extensions import TypedDict, Unpack from qcodes import validators as vals -from qcodes.instrument import ChannelList, InstrumentChannel, VisaInstrument +from qcodes.instrument import ( + ChannelList, + InstrumentBaseKWArgs, + InstrumentChannel, + VisaInstrument, + VisaInstrumentKWArgs, +) from qcodes.parameters import ArrayParameter, ParamRawDataType log = logging.getLogger(__name__) @@ -213,7 +219,11 @@ def _curveparameterparser( class TektronixTPS2012Channel(InstrumentChannel): def __init__( - self, parent: "TektronixTPS2012", name: str, channel: int, **kwargs: Any + self, + parent: "TektronixTPS2012", + name: str, + channel: int, + **kwargs: Unpack[InstrumentBaseKWArgs], ): super().__init__(parent, name, **kwargs) @@ -263,20 +273,24 @@ class TektronixTPS2012(VisaInstrument): This is the QCoDeS driver for the Tektronix 2012B oscilloscope. """ - def __init__(self, name: str, address: str, - timeout: float = 20, **kwargs: Any): + default_timeout = 20 + + def __init__( + self, + name: str, + address: str, + **kwargs: Unpack[VisaInstrumentKWArgs], + ): """ Initialises the TPS2012. Args: name: Name of the instrument used by QCoDeS address: Instrument address as used by VISA - timeout: visa timeout, in secs. long default (180) - to accommodate large waveforms **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, timeout=timeout, **kwargs) + super().__init__(name, address, **kwargs) self.connect_message() # Scope trace boolean diff --git a/src/qcodes/instrument_drivers/tektronix/Tektronix_70001A.py b/src/qcodes/instrument_drivers/tektronix/Tektronix_70001A.py index 44f38d153ff0..404d02110c3e 100644 --- a/src/qcodes/instrument_drivers/tektronix/Tektronix_70001A.py +++ b/src/qcodes/instrument_drivers/tektronix/Tektronix_70001A.py @@ -1,7 +1,12 @@ -from typing import Any +from typing import TYPE_CHECKING from .AWG70000A import AWG70000A +if TYPE_CHECKING: + from typing_extensions import Unpack + + from qcodes.instrument import VisaInstrumentKWArgs + class TektronixAWG70001A(AWG70000A): """ @@ -10,15 +15,19 @@ class TektronixAWG70001A(AWG70000A): All the actual driver meat is in the superclass AWG70000A. """ + default_timeout = 10 + def __init__( - self, name: str, address: str, timeout: float = 10, **kwargs: Any + self, + name: str, + address: str, + **kwargs: "Unpack[VisaInstrumentKWArgs]", ) -> None: """ Args: name: The name used internally by QCoDeS in the DataSet address: The VISA resource name of the instrument - timeout: The VISA timeout time (in seconds). **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, num_channels=2, timeout=timeout, **kwargs) + super().__init__(name, address, num_channels=2, **kwargs) diff --git a/src/qcodes/instrument_drivers/tektronix/Tektronix_70001B.py b/src/qcodes/instrument_drivers/tektronix/Tektronix_70001B.py index 8522da80ac8b..e7358c24e773 100644 --- a/src/qcodes/instrument_drivers/tektronix/Tektronix_70001B.py +++ b/src/qcodes/instrument_drivers/tektronix/Tektronix_70001B.py @@ -1,7 +1,12 @@ -from typing import Any +from typing import TYPE_CHECKING from .AWG70000A import AWG70000A +if TYPE_CHECKING: + from typing_extensions import Unpack + + from qcodes.instrument import VisaInstrumentKWArgs + class TektronixAWG70001B(AWG70000A): """ @@ -10,15 +15,19 @@ class TektronixAWG70001B(AWG70000A): All the actual driver meat is in the superclass AWG70000A. """ + default_timeout = 10 + def __init__( - self, name: str, address: str, timeout: float = 10, **kwargs: Any + self, + name: str, + address: str, + **kwargs: "Unpack[VisaInstrumentKWArgs]", ) -> None: """ Args: name: The name used internally by QCoDeS in the DataSet address: The VISA resource name of the instrument - timeout: The VISA timeout time (in seconds). **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, num_channels=2, timeout=timeout, **kwargs) + super().__init__(name, address, num_channels=2, **kwargs) diff --git a/src/qcodes/instrument_drivers/tektronix/Tektronix_70002B.py b/src/qcodes/instrument_drivers/tektronix/Tektronix_70002B.py index 4e85795ddcd6..fa6b9b5601d5 100644 --- a/src/qcodes/instrument_drivers/tektronix/Tektronix_70002B.py +++ b/src/qcodes/instrument_drivers/tektronix/Tektronix_70002B.py @@ -1,7 +1,12 @@ -from typing import Any +from typing import TYPE_CHECKING from .AWG70000A import AWG70000A +if TYPE_CHECKING: + from typing_extensions import Unpack + + from qcodes.instrument import VisaInstrumentKWArgs + class TektronixAWG70002B(AWG70000A): """ @@ -10,15 +15,19 @@ class TektronixAWG70002B(AWG70000A): All the actual driver meat is in the superclass AWG70000A. """ + default_timeout = 10 + def __init__( - self, name: str, address: str, timeout: float = 10, **kwargs: Any + self, + name: str, + address: str, + **kwargs: "Unpack[VisaInstrumentKWArgs]", ) -> None: """ Args: name: The name used internally by QCoDeS in the DataSet address: The VISA resource name of the instrument - timeout: The VISA timeout time (in seconds). **kwargs: kwargs are forwarded to base class. """ - super().__init__(name, address, num_channels=2, timeout=timeout, **kwargs) + super().__init__(name, address, num_channels=2, **kwargs)