Skip to content

Swap register order, removing need to pass num_qpd_bits#434

Merged
garrison merged 4 commits intomainfrom
swap-register-order
Oct 26, 2023
Merged

Swap register order, removing need to pass num_qpd_bits#434
garrison merged 4 commits intomainfrom
swap-register-order

Conversation

@garrison
Copy link
Copy Markdown
Member

@garrison garrison commented Oct 4, 2023

This swaps the order of the registers such that qpd_measurements now comes last. The motivation here is two-fold:

  1. To be consistent with the natural register order when reconstructing probability distributions (Draft support for reconstructing a probability distribution #428)
  2. To remove the need to pass around num_qpd_bits

@garrison garrison added the cutting QPD-based circuit cutting code label Oct 4, 2023
@garrison garrison added this to the 0.5.0 milestone Oct 4, 2023
@garrison garrison requested a review from caleb-johnson October 4, 2023 21:03
@github-actions
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 6463654179

  • 32 of 32 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 92.382%

Totals Coverage Status
Change from base Build 6463570000: 0.02%
Covered Lines: 2959
Relevant Lines: 3203

💛 - Coveralls

Copy link
Copy Markdown
Collaborator

@caleb-johnson caleb-johnson left a comment

Choose a reason for hiding this comment

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

Dropping a couple thoughts here. Will finish this up in a bit. Looking great!

if reg.name == "observable_measurements":
obs_creg = reg
break
else:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Neat code here where the else sits outside the looped if ... I'll have to glance at how this works :)

Comment thread circuit_knitting/cutting/cutting_experiments.py
for k, cog in enumerate(so.groups):
quasi_probs = results_dict[label].quasi_dists[i * len(so.groups) + k]
for outcome, quasi_prob in quasi_probs.items():
try:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

niiiiice

caleb-johnson
caleb-johnson previously approved these changes Oct 23, 2023
Copy link
Copy Markdown
Collaborator

@caleb-johnson caleb-johnson left a comment

Choose a reason for hiding this comment

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

Great idea, thanks for puttin this PR together. Makes thing much more straightforward :)

this vector correspond to the elements of ``cog.commuting_observables``,
and each result will be either +1 or -1.
"""
num_meas_bits = len(cog.pauli_indices)
Copy link
Copy Markdown
Member Author

@garrison garrison Oct 24, 2023

Choose a reason for hiding this comment

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

I realized in my final-review-before-merging that this line has a bug. It should really be

Suggested change
num_meas_bits = len(cog.pauli_indices)
num_meas_bits = len(_get_pauli_indices(cog))

i.e., it needs to consider the actual number of measurement bits given the workaround to #422.

I fixed this and added a test (really, a more thorough version of the existing test_sampler_with_identity_subobservable) in f4dec60. The refactored test

  • only considers a single circuit rather than all circuits given by the example_circuit fixture (should save execution time)
  • performs a smoke test with Sampler (as before) as well as a newly added full roundtrip test (which ensures correct expectation values) using ExactSampler

@garrison
Copy link
Copy Markdown
Member Author

@ibrahim-shehzad: since @caleb-johnson already approved everything before f4dec60, and f4dec60 primarily updates a test that you wrote, I think it makes most sense for you to review the changes in f4dec60 and approve this PR if those changes look good to you. Thanks!

Comment thread test/cutting/test_cutting_roundtrip.py
Comment thread test/cutting/test_cutting_roundtrip.py
Copy link
Copy Markdown
Collaborator

@ibrahim-shehzad ibrahim-shehzad left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@garrison garrison merged commit 26845aa into main Oct 26, 2023
@garrison garrison deleted the swap-register-order branch October 26, 2023 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cutting QPD-based circuit cutting code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants