1313from typing import TYPE_CHECKING , Any , Literal
1414
1515import numpy
16+ import numpy .typing as npt
1617from tqdm .auto import trange
1718
1819import qcodes
@@ -851,8 +852,9 @@ def get_parameter_data(
851852 """
852853 if len (params ) == 0 :
853854 valid_param_names = [
854- ps .name for ps in self ._rundescriber .interdeps .non_dependencies
855+ ps .name for ps in self ._rundescriber .interdeps .top_level_parameters
855856 ]
857+
856858 else :
857859 valid_param_names = self ._validate_parameters (* params )
858860 return get_parameter_data (
@@ -903,7 +905,7 @@ def to_pandas_dataframe_dict(
903905
904906 """
905907 datadict = self .get_parameter_data (* params , start = start , end = end )
906- dfs_dict = load_to_dataframe_dict (datadict )
908+ dfs_dict = load_to_dataframe_dict (datadict , self . description . interdeps )
907909 return dfs_dict
908910
909911 def to_pandas_dataframe (
@@ -951,7 +953,7 @@ def to_pandas_dataframe(
951953
952954 """
953955 datadict = self .get_parameter_data (* params , start = start , end = end )
954- return load_to_concatenated_dataframe (datadict )
956+ return load_to_concatenated_dataframe (datadict , self . description . interdeps )
955957
956958 def to_xarray_dataarray_dict (
957959 self ,
@@ -1226,7 +1228,7 @@ def __repr__(self) -> str:
12261228 return "\n " .join (out )
12271229
12281230 def _enqueue_results (
1229- self , result_dict : Mapping [ParamSpecBase , numpy . ndarray ]
1231+ self , result_dict : Mapping [ParamSpecBase , npt . NDArray ]
12301232 ) -> None :
12311233 """
12321234 Enqueue the results into self._results
@@ -1243,14 +1245,25 @@ def _enqueue_results(
12431245 self ._raise_if_not_writable ()
12441246 interdeps = self ._rundescriber .interdeps
12451247
1246- toplevel_params = set (interdeps .dependencies ).intersection (set (result_dict ))
1248+ result_parameters = set (result_dict .keys ())
1249+ unused_results = result_parameters .copy ()
1250+
1251+ toplevel_params = set (interdeps .top_level_parameters ).intersection (
1252+ result_parameters
1253+ )
12471254
1248- new_results : dict [str , dict [str , numpy . ndarray ]] = {}
1255+ new_results : dict [str , dict [str , npt . NDArray ]] = {}
12491256
12501257 for toplevel_param in toplevel_params :
1251- inff_params = set (interdeps .inferences .get (toplevel_param , ()))
1252- deps_params = set (interdeps .dependencies .get (toplevel_param , ()))
1253- all_params = inff_params .union (deps_params ).union ({toplevel_param })
1258+ # Transitively collect all parameters that are related to any parameter
1259+ # in the current tree, including parameters that dependencies are inferred from
1260+ all_params = interdeps .find_all_parameters_in_tree (toplevel_param )
1261+ # Only include parameters that are present in result_dict
1262+ # we keep track of results unused in any tree and raise a warning at the end
1263+ # if there are any
1264+ all_params = all_params .intersection (result_parameters )
1265+
1266+ unused_results = unused_results .difference (all_params )
12541267
12551268 if self ._in_memory_cache :
12561269 new_results [toplevel_param .name ] = {}
@@ -1268,8 +1281,13 @@ def _enqueue_results(
12681281 if toplevel_param .type == "array" :
12691282 res_list = self ._finalize_res_dict_array (result_dict , all_params )
12701283 elif toplevel_param .type in ("numeric" , "text" , "complex" ):
1284+ collected_params = all_params .copy ()
1285+ collected_params .remove (toplevel_param )
1286+
12711287 res_list = self ._finalize_res_dict_numeric_text_or_complex (
1272- result_dict , toplevel_param , inff_params , deps_params
1288+ result_dict ,
1289+ toplevel_param ,
1290+ collected_params ,
12731291 )
12741292 else :
12751293 res_dict : dict [str , VALUE ] = {
@@ -1278,18 +1296,12 @@ def _enqueue_results(
12781296 res_list = [res_dict ]
12791297 self ._results += res_list
12801298
1281- # Finally, handle standalone parameters
1282-
1283- standalones = set (interdeps .standalones ).intersection (set (result_dict ))
1284-
1285- if standalones :
1286- stdln_dict = {st : result_dict [st ] for st in standalones }
1287- self ._results += self ._finalize_res_dict_standalones (stdln_dict )
1288- if self ._in_memory_cache :
1289- for st in standalones :
1290- new_results [st .name ] = {
1291- st .name : self ._reshape_array_for_cache (st , result_dict [st ])
1292- }
1299+ if len (unused_results ) > 0 :
1300+ log .warning (
1301+ f"Results for parameters { unused_results } were not added to the "
1302+ "DataSet because they are not part of the interdependencies. "
1303+ "This will be an error in a future version of QCoDeS. "
1304+ )
12931305
12941306 if self ._in_memory_cache :
12951307 self .cache .add_data (new_results )
@@ -1328,10 +1340,9 @@ def reshaper(val: Any, ps: ParamSpecBase) -> VALUE:
13281340
13291341 @staticmethod
13301342 def _finalize_res_dict_numeric_text_or_complex (
1331- result_dict : Mapping [ParamSpecBase , numpy . ndarray ],
1343+ result_dict : Mapping [ParamSpecBase , npt . NDArray ],
13321344 toplevel_param : ParamSpecBase ,
1333- inff_params : set [ParamSpecBase ],
1334- deps_params : set [ParamSpecBase ],
1345+ params : set [ParamSpecBase ],
13351346 ) -> list [dict [str , VALUE ]]:
13361347 """
13371348 Make a res_dict in the format expected by DataSet.add_results out
@@ -1341,7 +1352,7 @@ def _finalize_res_dict_numeric_text_or_complex(
13411352 """
13421353
13431354 res_list : list [dict [str , VALUE ]] = []
1344- all_params = inff_params . union ( deps_params ) .union ({toplevel_param })
1355+ all_params = params .union ({toplevel_param })
13451356
13461357 t_map = {"numeric" : float , "text" : str , "complex" : complex }
13471358
@@ -1352,21 +1363,16 @@ def _finalize_res_dict_numeric_text_or_complex(
13521363 else :
13531364 # We first massage all values into np.arrays of the same
13541365 # shape
1355- flat_results : dict [str , numpy . ndarray ] = {}
1366+ flat_results : dict [str , npt . NDArray ] = {}
13561367
13571368 toplevel_val = result_dict [toplevel_param ]
13581369 flat_results [toplevel_param .name ] = toplevel_val .ravel ()
13591370 N = len (flat_results [toplevel_param .name ])
1360- for dep in deps_params :
1361- if result_dict [dep ].shape == ():
1362- flat_results [dep .name ] = numpy .repeat (result_dict [dep ], N )
1363- else :
1364- flat_results [dep .name ] = result_dict [dep ].ravel ()
1365- for inff in inff_params :
1366- if numpy .shape (result_dict [inff ]) == ():
1367- flat_results [inff .name ] = numpy .repeat (result_dict [inff ], N )
1371+ for param in params :
1372+ if result_dict [param ].shape == ():
1373+ flat_results [param .name ] = numpy .repeat (result_dict [param ], N )
13681374 else :
1369- flat_results [inff .name ] = result_dict [inff ].ravel ()
1375+ flat_results [param .name ] = result_dict [param ].ravel ()
13701376
13711377 # And then put everything into the list
13721378
@@ -1379,7 +1385,7 @@ def _finalize_res_dict_numeric_text_or_complex(
13791385
13801386 @staticmethod
13811387 def _finalize_res_dict_standalones (
1382- result_dict : Mapping [ParamSpecBase , numpy . ndarray ],
1388+ result_dict : Mapping [ParamSpecBase , npt . NDArray ],
13831389 ) -> list [dict [str , VALUE ]]:
13841390 """
13851391 Massage all standalone parameters into the correct shape
0 commit comments