Skip to content

Fix 7717#7725

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

Fix 7717#7725
jenshnielsen wants to merge 10 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 77.27273% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.58%. Comparing base (ffa18e5) to head (0b677f6).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/qcodes/dataset/exporters/export_to_xarray.py 76.19% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7725      +/-   ##
==========================================
+ Coverage   60.54%   60.58%   +0.03%     
==========================================
  Files         333      333              
  Lines       32232    32284      +52     
==========================================
+ Hits        19516    19559      +43     
- Misses      12716    12725       +9     

☔ 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"?

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.

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

Fixes QCoDeS dataset export behavior related to issue #7717, where ParameterWithSetpoints parameters involved in has_control_of/inference relationships could cause to_xarray_dataset() to export ravelled (ungridded) data instead of a properly gridded dataset.

Changes:

  • Add regression tests covering 1D and 2D ParameterWithSetpoints + has_control_of inference export behavior, plus a warning-path test.
  • Adjust InterDependencies_.top_level_parameters to avoid treating inferred parameters as independent top-level parameters.
  • Extend xarray export to include inferred parameters as data variables when exporting via the pandas-index path, warning when inferred data sizes don’t match the parent parameter.

Reviewed changes

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

File Description
tests/dataset/test_parameter_with_setpoints_has_control.py Adds regression tests reproducing #7717 and validating inferred parameters appear correctly in xarray export.
src/qcodes/dataset/exporters/export_to_xarray.py Adds _add_inferred_data_vars and integrates it into the pandas-index export paths to include inferred parameters.
src/qcodes/dataset/descriptions/dependencies.py Updates top_level_parameters to exclude parameters inferred from others from dependency top-level candidates.

Comment on lines +104 to +111
inferred_from_params = interdeps.inferences.get(inf, ())
if len(inferred_from_params) == 0:
continue
parent_name = inferred_from_params[0].name
if parent_name not in sub_dict:
continue
expected_size = sub_dict[parent_name].ravel().shape[0]
if flat.shape[0] == expected_size:
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

_add_inferred_data_vars assumes an inferred parameter has exactly one inferred_from parent by taking inferred_from_params[0]. ParamSpecs can be inferred from multiple parameters (e.g. inferred_from=[p1, p2]), and picking the first element can be nondeterministic and can cause inferred variables to be skipped or warned incorrectly. Consider iterating over all inferred-from parents (that are present in sub_dict) and using the first one whose flattened size matches, or otherwise logging an explicit warning/choosing a deterministic parent (e.g. prefer the top-level measured parameter if present).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The logic was updated to check all inferred from parameters and export if one of them matches. Perhaps it would be more correct if all of them match? @astafan8 what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be more correct if all of them match?

that depends on whether we expect the data shapes for the inferred from parameters to be the same as of the parent. do we? that's not obvious to me.

jenshnielsen and others added 2 commits March 23, 2026 11:08
Instead of assuming a single parent by taking inferred_from_params[0],
iterate over all inferred-from parents and use the first one whose
flattened data size matches. Log a warning listing all available parents
when no match is found.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Dataset converts to ungridded data if two ParameterWithSetpoints share inference and setpoints

3 participants