Skip to content
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

Update measurements tests for DQ2; create legacy tests folder #4574

Merged
merged 12 commits into from
Sep 6, 2023

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Sep 6, 2023

Context:
Measurement tests are focused on legacy devices, but we should use the new device API for these tests.

Description of the Change:
Here's what I did, chronologically:

  1. copy-paste every measurement test file into the legacy sub-folder
  2. change the original files to use default.qubit (not DQL), change default.qubit to point to DQ2, fix tests so they work with DQ2 (they all passed)
  3. Put back default.qubit to point to DQL, re-run non-legacy tests to see which ones fail, mark those as xfail (for now)
  4. Remove all tests in the legacy folder that double-cover anything (in other words, any tests that didn't use DQL)

Step 2 above involved some changes to PennyLane source code, and they are:

  1. Introduce MutualInfoMP.map_wires
  2. Change the qinfo transforms to use tape wires if device wires aren't present (I will probably revert this once device wires are supported for DQ2)
  3. Fix sampling.py to not squeeze any CountsMP result (batched results also shouldn't be squeezed, but they are lists of dicts instead of just dicts)
  4. EDIT: Update ProbabilityMP.marginal_prob to just return prob if self.wires is None. This was commented out before, and I'm not sure why.

Benefits:

  • Migrating to DQ2 will be much easier, and we'll have better test coverage for measurements with the new device API
  • qml.probs() did not work with DQ2 before this little change D:

Possible Drawbacks:
Slightly more tests. Think of this as effectively adding one more device to test with whenever doing device integration tests.

Follow-Up:
I made this story and mentioned the removal of xfails in it.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Patch coverage: 88.88% and project coverage change: -0.01% ⚠️

Comparison is base (145d515) 99.65% compared to head (ec9fe3e) 99.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4574      +/-   ##
==========================================
- Coverage   99.65%   99.65%   -0.01%     
==========================================
  Files         376      376              
  Lines       33148    33156       +8     
==========================================
+ Hits        33035    33042       +7     
- Misses        113      114       +1     
Files Changed Coverage Δ
pennylane/measurements/probs.py 98.98% <50.00%> (-1.02%) ⬇️
pennylane/devices/qubit/sampling.py 100.00% <100.00%> (ø)
pennylane/measurements/mutual_info.py 100.00% <100.00%> (ø)

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

@timmysilv timmysilv marked this pull request as ready for review September 6, 2023 13:28
@timmysilv timmysilv requested a review from a team September 6, 2023 13:28
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

I have some thoughts about the changes to qinfo but those are probably more relevant for transforms related discussions rather than device related discussions. Have a rocket 🚀

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

🚀

@timmysilv timmysilv enabled auto-merge (squash) September 6, 2023 16:35
@timmysilv timmysilv merged commit c28e5fc into master Sep 6, 2023
38 of 39 checks passed
@timmysilv timmysilv deleted the new-mp-test-files branch September 6, 2023 18:50
mudit2812 pushed a commit that referenced this pull request Sep 8, 2023
**Context:**
Measurement tests are focused on legacy devices, but we should use the
new device API for these tests.

**Description of the Change:**
Here's what I did, chronologically:
1. copy-paste every measurement test file into the `legacy` sub-folder
2. change the original files to use `default.qubit` (not DQL), change
`default.qubit` to point to DQ2, fix tests so they work with DQ2 (they
all passed)
3. Put back `default.qubit` to point to DQL, re-run non-legacy tests to
see which ones fail, mark those as xfail (for now)
4. Remove all tests in the `legacy` folder that double-cover anything
(in other words, any tests that didn't use DQL)

Step 2 above involved some changes to PennyLane source code, and they
are:
1. Introduce `MutualInfoMP.map_wires`
2. Change the qinfo transforms to use tape wires if device wires aren't
present (I will probably revert this once device wires are supported for
DQ2)
3. Fix `sampling.py` to not squeeze any CountsMP result (batched results
also shouldn't be squeezed, but they are lists of dicts instead of just
dicts)
4. EDIT: Update `ProbabilityMP.marginal_prob` to just return `prob` if
`self.wires` is None. This was commented out before, and I'm not sure
why.

**Benefits:**
- Migrating to DQ2 will be much easier, and we'll have better test
coverage for measurements with the new device API
- `qml.probs()` did not work with DQ2 before this little change D:

**Possible Drawbacks:**
Slightly more tests. Think of this as effectively adding one more device
to test with whenever doing device integration tests.

**Follow-Up:**
I made [this
story](https://app.shortcut.com/xanaduai/story/44915/update-setup-py-to-point-default-qubit-to-defaultqubit2)
and mentioned the removal of xfails in it.
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.

None yet

3 participants