-
Notifications
You must be signed in to change notification settings - Fork 346
Fix 7717 #7725
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
Open
jenshnielsen
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
jenshnielsen:fix_7717
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−3
Open
Fix 7717 #7725
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
175b160
Add failing test based on the bug report in 7717
jenshnielsen cc7a866
Fix 7717
jenshnielsen 7ce13b2
Remove outdated comments
jenshnielsen 6de4b2c
Improve test for 7717
jenshnielsen 3c254d8
Add infeered data to exported dataset
jenshnielsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/dataset/test_parameter_with_setpoints_has_control.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
| import numpy.testing as npt | ||
|
|
||
| from qcodes.dataset import Measurement | ||
| from qcodes.parameters import ManualParameter, ParameterWithSetpoints | ||
| from qcodes.validators import Arrays | ||
|
|
||
| if TYPE_CHECKING: | ||
| from qcodes.dataset.experiment_container import Experiment | ||
|
|
||
|
|
||
| def test_parameter_with_setpoints_has_control(experiment: "Experiment"): | ||
astafan8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class MySp(ParameterWithSetpoints): | ||
| def unpack_self(self, value): | ||
| res = super().unpack_self(value) | ||
| res.append((p1, p1())) | ||
| return res | ||
|
|
||
| mp_data = np.arange(10) | ||
| p1_data = np.linspace(-1, 1, 10) | ||
|
|
||
| mp = ManualParameter("mp", vals=Arrays(shape=(10,)), initial_value=mp_data) | ||
| p1 = ParameterWithSetpoints( | ||
| "p1", vals=Arrays(shape=(10,)), setpoints=(mp,), set_cmd=None | ||
| ) | ||
| p2 = MySp("p2", vals=Arrays(shape=(10,)), setpoints=(mp,), set_cmd=None) | ||
| p2.has_control_of.add(p1) | ||
|
|
||
| p1(p1_data) | ||
| p2_data = np.random.randn(10) | ||
| p2(p2_data) | ||
|
|
||
| meas = Measurement() | ||
| meas.register_parameter(p2) | ||
|
|
||
| # Only p2 should be top-level; p1 is inferred from p2 | ||
| interdeps = meas._interdeps | ||
| top_level_names = [p.name for p in interdeps.top_level_parameters] | ||
| assert top_level_names == ["p2"] | ||
|
|
||
| with meas.run() as ds: | ||
| ds.add_result((p2, p2())) | ||
|
|
||
| # Verify raw parameter data has exactly one row per parameter | ||
| raw_data = ds.dataset.get_parameter_data() | ||
| assert list(raw_data.keys()) == ["p2"], "Only p2 should be a top-level result" | ||
| for name, arr in raw_data["p2"].items(): | ||
| assert arr.shape == (1, 10), ( | ||
| f"Expected shape (1, 10) for {name}, got {arr.shape}" | ||
| ) | ||
|
|
||
| xds = ds.dataset.to_xarray_dataset() | ||
|
|
||
| # mp should be the only dimension (not a generic 'index') | ||
| assert list(xds.sizes.keys()) == ["mp"] | ||
| assert xds.sizes["mp"] == 10 | ||
|
|
||
| # mp values used as coordinate axis | ||
| npt.assert_array_equal(xds.coords["mp"].values, mp_data) | ||
|
|
||
| # 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
|
||
| # p1 is included as a data variable (inferred from p2) with correct values | ||
| assert "p1" in xds.data_vars | ||
| npt.assert_array_almost_equal(xds["p1"].values, p1_data) | ||
|
|
||
| # p1 data is also retrievable from the raw parameter data | ||
| npt.assert_array_almost_equal(raw_data["p2"]["p1"].ravel(), p1_data) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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