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

Test setpoints and basis types in register_parameter #6084

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/newsfragments/6084.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Measurement.register_parameter() now tests for correct types of arguments setpoints and basis.
18 changes: 18 additions & 0 deletions src/qcodes/dataset/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,12 @@ def register_parameter(
f"{ParamSpec.allowed_types} are supported."
)

if setpoints is not None:
self._check_setpoints_type(setpoints, "setpoints")

if basis is not None:
self._check_setpoints_type(basis, "basis")

if isinstance(parameter, ArrayParameter):
self._register_arrayparameter(parameter, setpoints, basis, paramtype)
elif isinstance(parameter, ParameterWithSetpoints):
Expand Down Expand Up @@ -970,6 +976,18 @@ def register_parameter(

return self

@staticmethod
def _check_setpoints_type(arg: setpoints_type, name: str):
if (
not isinstance(arg, Sequence)
or isinstance(arg, str)
or any(not isinstance(a, (str, ParameterBase)) for a in arg)
):
raise TypeError(
f"{name} should be a sequence of str or ParameterBase, not "
f"{type(arg)}"
)

@staticmethod
def _infer_paramtype(parameter: ParameterBase, paramtype: str | None) -> str | None:
"""
Expand Down
25 changes: 25 additions & 0 deletions tests/dataset/measurement/test_measurement_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@
assert "some extra info" in caplog.text


@pytest.mark.usefixtures("experiment")
def test_register_parameter_arg_types(DAC, DMM):
"""Test basis and setpoints argument types."""
meas = Measurement()
meas.register_parameter(DAC.ch1)

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, basis=DAC.ch1)

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, setpoints=DAC.ch1)

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, basis="foo")

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, setpoints="foo")

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, basis=(DAC.ch1, 3))

Check failure on line 73 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "basis" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 73 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "basis" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 73 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "basis" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 73 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "basis" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 73 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "basis" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)
thangleiter marked this conversation as resolved.
Show resolved Hide resolved

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, setpoints=(DAC.ch1, 3))

Check failure on line 76 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "setpoints" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 76 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "setpoints" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 76 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "setpoints" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 76 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "setpoints" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)

Check failure on line 76 in tests/dataset/measurement/test_measurement_context_manager.py

View workflow job for this annotation

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

Argument of type "tuple[Unknown, Literal[3]]" cannot be assigned to parameter "setpoints" of type "setpoints_type | None" in function "register_parameter"   Type "tuple[Unknown, Literal[3]]" is incompatible with type "setpoints_type | None"     "tuple[Unknown, Literal[3]]" is incompatible with "Sequence[str | ParameterBase]"       Type parameter "_T_co@Sequence" is covariant, but "Unknown | Literal[3]" is not a subtype of "str | ParameterBase"     "tuple[Unknown, Literal[3]]" is incompatible with "None" (reportArgumentType)


def test_register_parameter_numbers(DAC, DMM) -> None:
"""
Test the registration of scalar QCoDeS parameters
Expand Down
Loading