Skip to content

Commit

Permalink
use typed kwargs for remaining Keysight drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed May 17, 2024
1 parent 77b808c commit 144c51b
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 92 deletions.
38 changes: 31 additions & 7 deletions src/qcodes/instrument_drivers/Keysight/KeysightAgilent_33XXX.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import logging
from functools import partial
from typing import Any, Union
from typing import TYPE_CHECKING, Union

from qcodes import validators as vals
from qcodes.instrument import Instrument, InstrumentChannel, VisaInstrument
from qcodes.instrument import (
Instrument,
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)

from .private.error_handling import KeysightErrorQueueMixin

if TYPE_CHECKING:
from typing_extensions import Unpack

log = logging.getLogger(__name__)


Expand All @@ -19,15 +28,23 @@ class Keysight33xxxOutputChannel(InstrumentChannel):
"""
Class to hold the output channel of a Keysight 33xxxx waveform generator.
"""
def __init__(self, parent: Instrument, name: str, channum: int) -> None:

def __init__(
self,
parent: Instrument,
name: str,
channum: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
"""
Args:
parent: The instrument to which the channel is
attached.
name: The name of the channel
channum: The number of the channel in question (1-2)
**kwargs: kwargs are forwarded to base class.
"""
super().__init__(parent, name)
super().__init__(parent, name, **kwargs)

def val_parser(parser: type, inputstring: str) -> Union[float,int]:
"""
Expand Down Expand Up @@ -288,8 +305,15 @@ class WaveformGenerator_33XXX(KeysightErrorQueueMixin, VisaInstrument):
waveform generators
"""

def __init__(self, name: str, address: str,
silent: bool = False, **kwargs: Any):
default_terminator = "\n"

def __init__(
self,
name: str,
address: str,
silent: bool = False,
**kwargs: "Unpack[VisaInstrumentKWArgs]",
):
"""
Args:
name: The name of the instrument used internally
Expand All @@ -299,7 +323,7 @@ def __init__(self, name: str, address: str,
**kwargs: kwargs are forwarded to base class.
"""

super().__init__(name, address, terminator='\n', **kwargs)
super().__init__(name, address, **kwargs)
self.model = self.IDN()['model']

#######################################################################
Expand Down
34 changes: 28 additions & 6 deletions src/qcodes/instrument_drivers/Keysight/Keysight_B2962A.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
from typing import Any, Optional
from typing import TYPE_CHECKING, Optional

from qcodes.instrument import Instrument, InstrumentChannel, VisaInstrument
from qcodes.instrument import (
Instrument,
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)

if TYPE_CHECKING:
from typing_extensions import Unpack


class KeysightB2962AChannel(InstrumentChannel):
"""
"""
def __init__(self, parent: Instrument, name: str, chan: int) -> None:

def __init__(
self,
parent: Instrument,
name: str,
chan: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
"""
Args:
parent: The instrument to which the channel is attached.
name: The name of the channel
chan: The number of the channel in question (1-2)
**kwargs: Forwarded to base class.
"""
# Sanity Check inputs
if name not in ["ch1", "ch2"]:
raise ValueError(f"Invalid Channel: {name}, expected 'ch1' or 'ch2'")
if chan not in [1, 2]:
raise ValueError(f"Invalid Channel: {chan}, expected '1' or '2'")

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

Check warning on line 40 in src/qcodes/instrument_drivers/Keysight/Keysight_B2962A.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Keysight/Keysight_B2962A.py#L40

Added line #L40 was not covered by tests

self.add_parameter('source_voltage',
label=f"Channel {chan} Voltage",
Expand Down Expand Up @@ -96,8 +113,13 @@ class KeysightB2962A(VisaInstrument):
- Similar drivers have special handlers to map return values of
9.9e+37 to inf, is this needed?
"""
def __init__(self, name: str, address: str, **kwargs: Any):
super().__init__(name, address, terminator='\n', **kwargs)

default_terminator = "\n"

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

Check warning on line 122 in src/qcodes/instrument_drivers/Keysight/Keysight_B2962A.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/instrument_drivers/Keysight/Keysight_B2962A.py#L122

Added line #L122 was not covered by tests

# The B2962A supports two channels
for ch_num in [1, 2]:
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N5183B.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import Any
from typing import TYPE_CHECKING

from qcodes.instrument_drivers.Keysight.N51x1 import N51x1

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class KeysightN5183B(N51x1):
def __init__(self, name: str, address: str, **kwargs: Any):
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
):
super().__init__(name, address, min_power=-20, max_power=19, **kwargs)


Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N5222B.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import Any
from typing import TYPE_CHECKING

from . import N52xx

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class KeysightN5222B(N52xx.PNABase):
def __init__(self, name: str, address: str, **kwargs: Any):
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
):
"""Driver for Keysight PNA N5222B."""
super().__init__(
name,
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N5230C.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import Any
from typing import TYPE_CHECKING

from . import N52xx

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class KeysightN5230C(N52xx.PNABase):
def __init__(self, name: str, address: str, **kwargs: Any):
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
):
super().__init__(
name,
address,
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N5245A.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import Any
from typing import TYPE_CHECKING

from . import N52xx

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class KeysightN5245A(N52xx.PNAxBase):
def __init__(self, name: str, address: str, **kwargs: Any):
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
):
super().__init__(
name,
address,
Expand Down
31 changes: 25 additions & 6 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N6705B.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
from typing import Any, Optional
from typing import TYPE_CHECKING, Optional

from qcodes.instrument import Instrument, InstrumentChannel, VisaInstrument
from qcodes.instrument import (
Instrument,
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)

if TYPE_CHECKING:
from typing_extensions import Unpack


class KeysightN6705BChannel(InstrumentChannel):
def __init__(self, parent: Instrument, name: str, chan: int) -> None:
def __init__(
self,
parent: Instrument,
name: str,
chan: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
) -> None:
if chan not in [1, 2, 3, 4]:
raise ValueError('Invalid channel specified')

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

self.add_parameter('source_voltage',
label=f"Channel {chan} Voltage",
Expand Down Expand Up @@ -62,8 +77,12 @@ def __init__(self, parent: Instrument, name: str, chan: int) -> None:


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

def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
) -> None:
super().__init__(name, address, **kwargs)
self.channels: list[KeysightN6705BChannel] = []
for ch_num in [1, 2, 3, 4]:
ch_name = f"ch{ch_num}"
Expand Down
30 changes: 24 additions & 6 deletions src/qcodes/instrument_drivers/Keysight/Keysight_N9030B.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from __future__ import annotations

from typing import Any, Callable
from typing import TYPE_CHECKING, Any, Callable

import numpy as np

from qcodes.instrument import InstrumentChannel, VisaInstrument
from qcodes.instrument import (
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)
from qcodes.parameters import (
Parameter,
ParameterWithSetpoints,
Expand All @@ -13,6 +18,9 @@
)
from qcodes.validators import Arrays, Bool, Enum, Ints, Numbers

if TYPE_CHECKING:
from typing_extensions import Unpack


class FrequencyAxis(Parameter):
def __init__(
Expand Down Expand Up @@ -73,7 +81,7 @@ def __init__(
name: str,
*arg: Any,
additional_wait: int = 1,
**kwargs: Any,
**kwargs: Unpack[InstrumentBaseKWArgs],
):
super().__init__(parent, name, *arg, **kwargs)

Expand Down Expand Up @@ -411,7 +419,13 @@ class KeysightN9030BPhaseNoiseMode(InstrumentChannel):
Phase Noise Mode for Keysight N9030B instrument.
"""

def __init__(self, parent: KeysightN9030B, name: str, *arg: Any, **kwargs: Any):
def __init__(
self,
parent: KeysightN9030B,
name: str,
*arg: Any,
**kwargs: Unpack[InstrumentBaseKWArgs],
):
super().__init__(parent, name, *arg, **kwargs)

self._min_freq = 1
Expand Down Expand Up @@ -611,8 +625,12 @@ class KeysightN9030B(VisaInstrument):
address
"""

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

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

self._min_freq: float
self._max_freq: float
Expand Down
11 changes: 9 additions & 2 deletions src/qcodes/instrument_drivers/Keysight/Keysight_P9374A.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from typing import Any
from typing import TYPE_CHECKING

from . import N52xx

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs

# This is not the same class of Keysight devices but seems to work well...


class KeysightP9374A(N52xx.PNAxBase):
def __init__(self, name: str, address: str, **kwargs: Any):
def __init__(
self, name: str, address: str, **kwargs: "Unpack[VisaInstrumentKWArgs]"
):
super().__init__(
name,
address,
Expand Down

0 comments on commit 144c51b

Please sign in to comment.