From 4ce337cbfb8aab651af685af0454251a165d85b1 Mon Sep 17 00:00:00 2001 From: andncl Date: Tue, 16 Dec 2025 11:44:08 +0000 Subject: [PATCH 1/8] Added paramters that are controlled by setpoints to unpack_self --- .../parameters/parameter_with_setpoints.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qcodes/parameters/parameter_with_setpoints.py b/src/qcodes/parameters/parameter_with_setpoints.py index d9ef9badf4dd..4b13323ec5a2 100644 --- a/src/qcodes/parameters/parameter_with_setpoints.py +++ b/src/qcodes/parameters/parameter_with_setpoints.py @@ -161,13 +161,17 @@ def depends_on(self) -> ParameterSet: def unpack_self(self, value: ValuesType) -> list[tuple[ParameterBase, ValuesType]]: unpacked_results: list[tuple[ParameterBase, ValuesType]] = [] - setpoint_params = [] - setpoint_data = [] - for setpointparam in self.setpoints: - these_setpoints = setpointparam.get() - setpoint_params.append(setpointparam) - setpoint_data.append(these_setpoints) + setpoint_params = list(self.setpoints) + setpoint_data = [param.get() for param in setpoint_params] output_grids = np.meshgrid(*setpoint_data, indexing="ij") + for i, param in enumerate(setpoint_params[:]): + for inferred_param in param.has_control_of: + copy_setpoint_data = setpoint_data[:] + copy_setpoint_data[i] = inferred_param.get() + setpoint_params.append(inferred_param) + output_grids.append( + np.meshgrid(*copy_setpoint_data, indexing="ij")[i] + ) for param, grid in zip(setpoint_params, output_grids): unpacked_results.append((param, grid)) unpacked_results.extend( From 4acea06a66ebdb96a17e8e0147b1d02f05febdca Mon Sep 17 00:00:00 2001 From: andncl Date: Tue, 16 Dec 2025 11:52:36 +0000 Subject: [PATCH 2/8] Added doctring to unpack_self of ParameterWithSetpoints --- src/qcodes/parameters/parameter_with_setpoints.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/qcodes/parameters/parameter_with_setpoints.py b/src/qcodes/parameters/parameter_with_setpoints.py index 4b13323ec5a2..0dee13450016 100644 --- a/src/qcodes/parameters/parameter_with_setpoints.py +++ b/src/qcodes/parameters/parameter_with_setpoints.py @@ -160,6 +160,17 @@ def depends_on(self) -> ParameterSet: return ParameterSet(self.setpoints) def unpack_self(self, value: ValuesType) -> list[tuple[ParameterBase, ValuesType]]: + """ + Unpacks the ParameterWithSetpoints, its setpoints and any inferred + parameters controlled by the setpoints. + + Args: + value(ValuesType): The data acquired from this parameter. + + Returns: + A list of tuples of parameters and values to be added as results + to the dataset. + """ unpacked_results: list[tuple[ParameterBase, ValuesType]] = [] setpoint_params = list(self.setpoints) setpoint_data = [param.get() for param in setpoint_params] From 9992db3442d0e05612d5654b12af2246cff6e44f Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 02:52:09 +0000 Subject: [PATCH 3/8] changed tuple to list in function --- src/qcodes/parameters/parameter_with_setpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qcodes/parameters/parameter_with_setpoints.py b/src/qcodes/parameters/parameter_with_setpoints.py index 0dee13450016..561956348c73 100644 --- a/src/qcodes/parameters/parameter_with_setpoints.py +++ b/src/qcodes/parameters/parameter_with_setpoints.py @@ -174,7 +174,7 @@ def unpack_self(self, value: ValuesType) -> list[tuple[ParameterBase, ValuesType unpacked_results: list[tuple[ParameterBase, ValuesType]] = [] setpoint_params = list(self.setpoints) setpoint_data = [param.get() for param in setpoint_params] - output_grids = np.meshgrid(*setpoint_data, indexing="ij") + output_grids = list(np.meshgrid(*setpoint_data, indexing="ij")) for i, param in enumerate(setpoint_params[:]): for inferred_param in param.has_control_of: copy_setpoint_data = setpoint_data[:] From 02e8c9817da7715f19f10e7d5bd9afae82d763e4 Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 02:52:42 +0000 Subject: [PATCH 4/8] Added test checking inferred parameter unpacking --- .../measurement/test_self_unpacking.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/dataset/measurement/test_self_unpacking.py b/tests/dataset/measurement/test_self_unpacking.py index 7e0245ab17b1..b3ab96feb2cd 100644 --- a/tests/dataset/measurement/test_self_unpacking.py +++ b/tests/dataset/measurement/test_self_unpacking.py @@ -37,9 +37,13 @@ def __init__( def set_raw(self, value: ParamRawDataType) -> None: # Set all dependent parameters based on their mapping functions + self.value = value for param, slope_offset in self._components_dict.items(): param(value * slope_offset[0] + slope_offset[1]) + def get_raw(self) -> ParamRawDataType: + return self.value + def unpack_self( self, value: "ValuesType" ) -> list[tuple["ParameterBase", "ValuesType"]]: @@ -142,6 +146,51 @@ def test_add_result_self_unpack_with_PWS(controlling_parameters, experiment): assert pws_data["pws"].shape == (11, 11) assert pws_data["pws_setpoints"].shape == (11, 11) +def test_add_result_self_unpack_with_PWS_and_inferred_setpoints( + experiment, controlling_parameters): + """ + Docstring for test_add_result_self_unpack_with_PWS_and_inferred_setpoints + + :param experiment: Description + :param controlling_parameters: Description + """ + control1, comp1, comp2 = controlling_parameters + for param in (control1, comp1, comp2): + param.vals = Arrays(shape=(11,)) + pws_other_setpoints = Parameter( + "pws_other_setpoints", + get_cmd=lambda: np.linspace(-1, 1, 13), + vals=Arrays(shape=(13,)), + ) + pws = ParameterWithSetpoints( + "pws", + setpoints=(control1, pws_other_setpoints,), + vals=Arrays(shape=(11,13)), + get_cmd=lambda: np.zeros((11,13)), + ) + + meas = Measurement(experiment) + meas.register_parameter(pws) + + assert all( + param in meas._registered_parameters + for param in (comp1, comp2, control1, pws) + ) + control1.set(np.linspace(-1, 1, 11)) + with meas.run() as datasaver: + datasaver.add_result((pws, pws())) + ds = datasaver.dataset + + dataset_data = ds.get_parameter_data() + pws_data = dataset_data.get("pws", None) + assert (pws_data) is not None + print(pws_data.keys()) + assert all( + param_name in pws_data.keys() + for param_name in ("pws", "comp1", "comp2", "control1", "pws_other_setpoints") + ) + for result in ('control1', 'comp1', 'comp2', 'pws', 'pws_other_setpoints'): + assert pws_data[result].shape == (1, 11, 13) # Testing equality methods for deduplication def test_non_numeric_values_are_equal() -> None: From 5465a9e7b323b557706d2ddf8b4d897b4ebc2a9e Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 02:53:49 +0000 Subject: [PATCH 5/8] Simplified result packaging --- src/qcodes/parameters/parameter_with_setpoints.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qcodes/parameters/parameter_with_setpoints.py b/src/qcodes/parameters/parameter_with_setpoints.py index 561956348c73..49cde0f9f5ba 100644 --- a/src/qcodes/parameters/parameter_with_setpoints.py +++ b/src/qcodes/parameters/parameter_with_setpoints.py @@ -183,8 +183,7 @@ def unpack_self(self, value: ValuesType) -> list[tuple[ParameterBase, ValuesType output_grids.append( np.meshgrid(*copy_setpoint_data, indexing="ij")[i] ) - for param, grid in zip(setpoint_params, output_grids): - unpacked_results.append((param, grid)) + unpacked_results = list(zip(setpoint_params, output_grids)) unpacked_results.extend( super().unpack_self(value) ) # Must come last to preserve original ordering From d5cc0c605506597d2f11bae301be13a5dfd6522e Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 03:01:40 +0000 Subject: [PATCH 6/8] Improved docstring of test --- tests/dataset/measurement/test_self_unpacking.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/dataset/measurement/test_self_unpacking.py b/tests/dataset/measurement/test_self_unpacking.py index b3ab96feb2cd..19c09249b745 100644 --- a/tests/dataset/measurement/test_self_unpacking.py +++ b/tests/dataset/measurement/test_self_unpacking.py @@ -149,10 +149,9 @@ def test_add_result_self_unpack_with_PWS(controlling_parameters, experiment): def test_add_result_self_unpack_with_PWS_and_inferred_setpoints( experiment, controlling_parameters): """ - Docstring for test_add_result_self_unpack_with_PWS_and_inferred_setpoints - - :param experiment: Description - :param controlling_parameters: Description + Test that a ParameterWithSetpoints that has setpoints which themselves + have inferred parameters controlled by a ControllingParameter unpacks + correctly. """ control1, comp1, comp2 = controlling_parameters for param in (control1, comp1, comp2): From 40ae4e4f5c3a79b1f0d1c066afa5791458704ec2 Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 03:05:39 +0000 Subject: [PATCH 7/8] Added newsfragment --- docs/changes/newsfragments/xxxx.improved | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/changes/newsfragments/xxxx.improved diff --git a/docs/changes/newsfragments/xxxx.improved b/docs/changes/newsfragments/xxxx.improved new file mode 100644 index 000000000000..66a39c66a3cc --- /dev/null +++ b/docs/changes/newsfragments/xxxx.improved @@ -0,0 +1,3 @@ +Added parameters that are controlled by a ParameterWithSetpoints setpoints to +``ParameterWithSetpoints.unpack_self``. Dependent parameters will now be +automatically saved in the correct shape alike the corresponding setpoints. \ No newline at end of file From 8da633b1e9c65ef92f81b95713acbc76bce9d285 Mon Sep 17 00:00:00 2001 From: andncl Date: Thu, 18 Dec 2025 03:20:39 +0000 Subject: [PATCH 8/8] Added PR number to newsfragment --- docs/changes/newsfragments/{xxxx.improved => 7732.improved} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/changes/newsfragments/{xxxx.improved => 7732.improved} (94%) diff --git a/docs/changes/newsfragments/xxxx.improved b/docs/changes/newsfragments/7732.improved similarity index 94% rename from docs/changes/newsfragments/xxxx.improved rename to docs/changes/newsfragments/7732.improved index 66a39c66a3cc..00f74c6896b2 100644 --- a/docs/changes/newsfragments/xxxx.improved +++ b/docs/changes/newsfragments/7732.improved @@ -1,3 +1,3 @@ Added parameters that are controlled by a ParameterWithSetpoints setpoints to ``ParameterWithSetpoints.unpack_self``. Dependent parameters will now be -automatically saved in the correct shape alike the corresponding setpoints. \ No newline at end of file +automatically saved in the correct shape alike the corresponding setpoints.