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 all 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) -> None:
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 @@ def test_log_includes_extra_info(
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)) # type: ignore[arg-type]

with pytest.raises(TypeError):
meas.register_parameter(DMM.v1, setpoints=(DAC.ch1, 3)) # type: ignore[arg-type]


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