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

Accept sequences of values for setting MultiChannelInstrumentParameter #6073

29 changes: 24 additions & 5 deletions src/qcodes/parameters/multi_channel_instrument_parameter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Any, Generic, TypeVar

from .multi_parameter import MultiParameter
Expand All @@ -12,6 +13,7 @@
from .parameter_base import ParamRawDataType

InstrumentModuleType = TypeVar("InstrumentModuleType", bound="InstrumentModule")
_LOG = logging.getLogger(__name__)


class MultiChannelInstrumentParameter(MultiParameter, Generic[InstrumentModuleType]):
Expand Down Expand Up @@ -45,16 +47,33 @@
"""
return tuple(chan.parameters[self._param_name].get() for chan in self._channels)

def set_raw(self, value: ParamRawDataType) -> None:
def set_raw(self, value: ParamRawDataType | Sequence[ParamRawDataType]) -> None:
"""
Set all parameters to this value.
Set all parameters to this/these value(s).

Args:
value: The value to set to. The type is given by the
value: The value(s) to set to. The type is given by the
underlying parameter.
"""
for chan in self._channels:
getattr(chan, self._param_name).set(value)
try:
for chan in self._channels:
getattr(chan, self._param_name).set(value)
except Exception as err:
try:
for chan, val in zip(self._channels, value, strict=True):

Check failure on line 63 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.9, false)

No overloads for "__new__" match the provided arguments   Argument types: (Sequence[InstrumentModuleType@MultiChannelInstrumentParameter], Any | Sequence[ParamRawDataType], Literal[True]) (reportCallIssue)
getattr(chan, self._param_name).set(val)
thangleiter marked this conversation as resolved.
Show resolved Hide resolved
thangleiter marked this conversation as resolved.
Show resolved Hide resolved
except (TypeError, ValueError):
note = (

Check warning on line 66 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/parameters/multi_channel_instrument_parameter.py#L61-L66

Added lines #L61 - L66 were not covered by tests
"Value should either be valid for a single parameter of the channel list "
"or a sequence of valid values of the same length as the list."
)
try:
err.add_note(note)

Check failure on line 71 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)

Cannot access attribute "add_note" for class "Exception"   Attribute "add_note" is unknown (reportAttributeAccessIssue)

Check failure on line 71 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.9, false)

Cannot access attribute "add_note" for class "Exception"   Attribute "add_note" is unknown (reportAttributeAccessIssue)

Check failure on line 71 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.10, false)

Cannot access attribute "add_note" for class "Exception"   Attribute "add_note" is unknown (reportAttributeAccessIssue)
thangleiter marked this conversation as resolved.
Show resolved Hide resolved
except AttributeError:

Check warning on line 72 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/parameters/multi_channel_instrument_parameter.py#L70-L72

Added lines #L70 - L72 were not covered by tests
# <3.11
_LOG.error(note)

Check warning on line 74 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/parameters/multi_channel_instrument_parameter.py#L74

Added line #L74 was not covered by tests
finally:
raise

Check warning on line 76 in src/qcodes/parameters/multi_channel_instrument_parameter.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/parameters/multi_channel_instrument_parameter.py#L76

Added line #L76 was not covered by tests

@property
def full_names(self) -> tuple[str, ...]:
Expand Down
Loading