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

_group_measurements in qubit sampling works with Prod, SProd, Sum, Hamiltonian #5525

Merged
merged 12 commits into from
Apr 21, 2024

Conversation

astralcai
Copy link
Contributor

@astralcai astralcai commented Apr 16, 2024

Context:
The _group_measurements function in qubit/sampling.py groups measurement processes with commuting observables together to reduce the number of executions. Now it does not handle Prod, SProd or single-term Hamiltonian and Sum, which leads to inefficiencies with new opmath.

Description of the Change:
Removes the branch that places Prod, SProd, Hamiltonian and Sum in separate groups. Now is_pauli_word is used for everything.

Benefits:
Better grouping leads to fewer number of executions.

Related GitHub Issues:
Fixes #5512

Related Shortcut Stories:
[sc-61306]

Copy link
Contributor

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.

Copy link

codecov bot commented Apr 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.66%. Comparing base (5f223c1) to head (2826183).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5525      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         406      407       +1     
  Lines       37934    37728     -206     
==========================================
- Hits        37810    37603     -207     
- Misses        124      125       +1     

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

@astralcai astralcai marked this pull request as ready for review April 18, 2024 21:04
@astralcai astralcai requested review from lillian542 and albi3ro April 19, 2024 15:47
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.

Looks good to me! Don't forget a changelog update 🚀

tests/devices/default_qubit/test_default_qubit_tracking.py Outdated Show resolved Hide resolved
@trbromley trbromley added this to the v0.36 milestone Apr 19, 2024
@astralcai astralcai enabled auto-merge (squash) April 19, 2024 21:26
@astralcai astralcai merged commit d03216e into master Apr 21, 2024
38 checks passed
@astralcai astralcai deleted the group-meas branch April 21, 2024 15:25
astralcai added a commit that referenced this pull request Apr 24, 2024
**Context:**
PR #5525 led to two bugs:
- `group_observables` uses `are_identity_pauli_words`, which does not
work for legacy `Hamiltonian`.
- `get_num_shots_and_executions` incorrectly counts number of executions
for `Sum`

**Description of the Change:**
- Converts single-term `Hamiltonian` to `SProd`
- Use the grouping information of `Sum` to correctly count number of
executions.

**Related Shortcut Issues:**
[sc-61807]
[sc-61812]
Fixes #5561
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.

[BUG] Grouping of measurements is inconsistent between legacy and new opmath
4 participants