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

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

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

from .multi_parameter import MultiParameter
Expand All @@ -12,6 +14,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 +48,35 @@
"""
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:

Check warning on line 63 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#L62-L63

Added lines #L62 - L63 were not covered by tests
# Catch wrong length of value before any setting is done
value_list = list(value)
if len(value_list) != len(self._channels):
raise ValueError
for chan, val in zip(self._channels, value_list):
getattr(chan, self._param_name).set(val)
thangleiter marked this conversation as resolved.
Show resolved Hide resolved
except (TypeError, ValueError):
note = (

Check warning on line 71 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#L65-L71

Added lines #L65 - L71 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."
)
if sys.version_info >= (3, 11):
err.add_note(note)

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#L75-L76

Added lines #L75 - L76 were not covered by tests
thangleiter marked this conversation as resolved.
Show resolved Hide resolved
else:
_LOG.error(note)
raise err from None

Check warning on line 79 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#L78-L79

Added lines #L78 - L79 were not covered by tests

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