Skip to content

Fix 7717#7725

Open
jenshnielsen wants to merge 5 commits intomicrosoft:mainfrom
jenshnielsen:fix_7717
Open

Fix 7717#7725
jenshnielsen wants to merge 5 commits intomicrosoft:mainfrom
jenshnielsen:fix_7717

Conversation

@jenshnielsen
Copy link
Collaborator

@jenshnielsen jenshnielsen commented Dec 15, 2025

@jenshnielsen jenshnielsen requested a review from a team as a code owner December 15, 2025 10:33
@jenshnielsen jenshnielsen marked this pull request as draft February 2, 2026 10:18
@jenshnielsen
Copy link
Collaborator Author

@astafan8 converted to draft until it actually fixes the bug

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 73.52941% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.55%. Comparing base (852c06e) to head (3c254d8).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/qcodes/dataset/exporters/export_to_xarray.py 71.87% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7725      +/-   ##
==========================================
+ Coverage   60.54%   60.55%   +0.01%     
==========================================
  Files         333      333              
  Lines       32227    32261      +34     
==========================================
+ Hits        19513    19537      +24     
- Misses      12714    12724      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jenshnielsen jenshnielsen marked this pull request as ready for review March 18, 2026 09:06
Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to see this fixed! And "add a news fragment"?


# p2 is the primary data variable with correct values
assert "p2" in xds.data_vars
npt.assert_array_almost_equal(xds["p2"].values, p2_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall an assrtion be added for p1 in the xarray dataset as well?

xr_dataset[inf.name] = (
dims,
flat.reshape(tuple(xr_dataset.sizes[d] for d in dims)),
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably warn if this is not the case

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #7717, where a dataset export to xarray becomes ungridded when two ParameterWithSetpoints share the same setpoints and one parameter is inferred/controlled by the other. The intent is to ensure the export stays gridded and includes the inferred parameter data alongside the measured top-level parameter.

Changes:

  • Adds a regression test reproducing the ParameterWithSetpoints.has_control_of + shared setpoints scenario.
  • Updates InterDependencies_.top_level_parameters to exclude parameters that are inferred-from others from being considered dependency top-level parameters.
  • Extends the xarray export (pandas-index path) to add inferred parameters as xarray data variables.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/dataset/test_parameter_with_setpoints_has_control.py Regression test ensuring gridded xarray export includes inferred p1 as a data var while keeping only p2 top-level.
src/qcodes/dataset/exporters/export_to_xarray.py Adds _add_inferred_data_vars to include inferred parameters in xarray output when exporting via pandas index.
src/qcodes/dataset/descriptions/dependencies.py Adjusts top-level parameter detection to prevent inferred parameters from being treated as independent top-level parameters.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +78 to +110
interdeps = dataset.description.interdeps
meas_paramspec = interdeps.graph.nodes[name]["value"]
_, deps, inferred = interdeps.all_parameters_in_tree_by_group(meas_paramspec)

dep_names = {dep.name for dep in deps}
dims = tuple(d for d in xr_dataset.dims)

for inf in inferred:
if inf.name in dep_names:
continue
if inf.name in xr_dataset:
continue
if inf.name not in sub_dict:
continue

inf_data = sub_dict[inf.name]
if inf_data.dtype == np.dtype("O"):
try:
flat = np.concatenate(inf_data)
except ValueError:
flat = inf_data.ravel()
else:
flat = inf_data.ravel()

# Only add if the data length matches the existing dataset size
expected_size = 1
for d in dims:
expected_size *= xr_dataset.sizes[d]
if flat.shape[0] == expected_size:
xr_dataset[inf.name] = (
dims,
flat.reshape(tuple(xr_dataset.sizes[d] for d in dims)),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants