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

Provide a workaround to #422, Sampler failing when no measurements #426

Merged
merged 9 commits into from
Oct 10, 2023

Conversation

garrison
Copy link
Member

@garrison garrison commented Sep 29, 2023

Temporary workaround to #422.

Needs

  • a test

@garrison garrison added the cutting QPD-based circuit cutting code label Sep 29, 2023
@garrison garrison added this to the 0.4.1 milestone Sep 29, 2023
@garrison garrison added the stable backport potential Suitable to be backported to most recent stable branch by Mergify label Sep 29, 2023
@CLAassistant
Copy link

CLAassistant commented Oct 3, 2023

CLA assistant check
All committers have signed the CLA.

@ibrahim-shehzad
Copy link
Collaborator

I added a test, @garrison, in test_cutting_roundtrip.py, called test_sampler_fail.

@ibrahim-shehzad ibrahim-shehzad marked this pull request as ready for review October 4, 2023 02:48
With this, the current PR will touch one fewer file
Copy link
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.

Will these circuits with 1 measurement be ignored during reconstruction, since they don't actually have non-trivial observables associated with them?

# measure one qubit as a temporary workaround to
# https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/issues/422
pauli_indices = cog.pauli_indices
if not pauli_indices:
Copy link
Collaborator

@caleb-johnson caleb-johnson Oct 5, 2023

Choose a reason for hiding this comment

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

What can pauli_indices be here? Should we just explicitly state what we expect? (e.g. if pauli_indices == [])

Or we could just assert pauli_indices == [] inside the if? (assuming an empty list is what is returned in I observable case)

Copy link
Member Author

Choose a reason for hiding this comment

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

What can pauli_indices be here? Should we just explicitly state what we expect? (e.g. if pauli_indices == [])

It's a sequence of ints. It contains the qubit indices that need to be measured.

The choice of style here is influenced by PEP 8:

For sequences, (strings, lists, tuples), use the fact that empty sequences are false:

# Correct:
if not seq:
if seq:
# Wrong:
if len(seq):
if not len(seq):

The "nice" thing about doing it this way is it doesn't matter what type the sequence is. For instance, if it were to be a tuple of indices, then it will still behave correctly with the current code, but it would not if we were to compare with [] because () != [].

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, thanks for explanation

Copy link
Collaborator

@ibrahim-shehzad ibrahim-shehzad Oct 6, 2023

Choose a reason for hiding this comment

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

Wow, this is more profound than I thought. Nice!

@garrison
Copy link
Member Author

garrison commented Oct 5, 2023

Will these circuits with 1 measurement be ignored during reconstruction, since they don't actually have non-trivial observables associated with them?

Yes

caleb-johnson
caleb-johnson previously approved these changes Oct 5, 2023
Copy link
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.

LGTM 👍

Thanks @IbrahimShehzad and @garrison !

@garrison
Copy link
Member Author

garrison commented Oct 9, 2023

I am leaning toward waiting first until #434 is merged and then updating this branch accordingly.

EDIT: Actually, I might have changed my mind already. 😂

ibrahim-shehzad and others added 3 commits October 9, 2023 15:03
Co-authored-by: Jim Garrison <garrison@ibm.com>
Co-authored-by: Jim Garrison <garrison@ibm.com>
Copy link
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.

Everything now looks good to me. Thanks.

@garrison garrison merged commit f596307 into main Oct 10, 2023
10 checks passed
@garrison garrison deleted the measurementless-circuit-workaround branch October 10, 2023 01:27
mergify bot pushed a commit that referenced this pull request Oct 10, 2023
)

* Provide a workaround to #422, Sampler failing when no measurements

* Add test for workaround to Issue #422.

* Redo previous commit after running tox.

* Fix tox error from previous build.

* Fix tox error from last build.

* Un-modify the metadata in a notebook

With this, the current PR will touch one fewer file

* Update test/cutting/test_cutting_roundtrip.py

Co-authored-by: Jim Garrison <garrison@ibm.com>

* Update test/cutting/test_cutting_roundtrip.py

Co-authored-by: Jim Garrison <garrison@ibm.com>

* black

---------

Co-authored-by: Ibrahim <ibrahim.shehzad@ibm.com>
Co-authored-by: Ibrahim Shehzad <75153717+Ibrahim-Shehzad@users.noreply.github.com>
(cherry picked from commit f596307)
garrison added a commit that referenced this pull request Oct 10, 2023
) (#436)

* Provide a workaround to #422, Sampler failing when no measurements

* Add test for workaround to Issue #422.

* Redo previous commit after running tox.

* Fix tox error from previous build.

* Fix tox error from last build.

* Un-modify the metadata in a notebook

With this, the current PR will touch one fewer file

* Update test/cutting/test_cutting_roundtrip.py

Co-authored-by: Jim Garrison <garrison@ibm.com>

* Update test/cutting/test_cutting_roundtrip.py

Co-authored-by: Jim Garrison <garrison@ibm.com>

* black

---------

Co-authored-by: Ibrahim <ibrahim.shehzad@ibm.com>
Co-authored-by: Ibrahim Shehzad <75153717+Ibrahim-Shehzad@users.noreply.github.com>
(cherry picked from commit f596307)

Co-authored-by: Jim Garrison <garrison@ibm.com>
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 stable backport potential Suitable to be backported to most recent stable branch by Mergify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants