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

subexperiments associated with the identity Pauli observable should not be passed to Sampler #422

Open
caleb-johnson opened this issue Sep 27, 2023 · 2 comments
Labels
bug Something isn't working cutting QPD-based circuit cutting code good first issue Good for newcomers highly desired

Comments

@caleb-johnson
Copy link
Collaborator

caleb-johnson commented Sep 27, 2023

We do not need to run circuits associated with the Identity observable, as the measurement readout is trivial.

Now, the cutting workflow in the tutorials will fail ungracefully when the subexperiments associated with the I observable are passed to the Sampler, as they do not contain any end-of-circuit measurements. Passing these circuits results in:

ValueError: The 0-th circuit does not have any classical bit. Sampler requires classical bits, plus measurements on the desired qubits.

How do we handle this? Do we only return subexperiments which need actual measurement? If we do that, we'd need to extrapolate the trivial I measurements back into the final answer somehow.

@caleb-johnson caleb-johnson added bug Something isn't working good first issue Good for newcomers cutting QPD-based circuit cutting code highly desired labels Sep 27, 2023
@garrison
Copy link
Member

The way a user can hack around it without requiring any changes to CKT is to add a Pauli Z observable somewhere in the subsystem that is currently throwing an error with all identities.

But even better would be not to run these experiments at all. I've had this in mind as one of the special cases at #262, but it looks like I failed to ever explicitly mention this there. I did mention it at #378 (comment), and I think the follow up at #387 is relevant to fixing this.

I will also think if there's something we can do that doesn't involve breaking interfaces, which #387 would, technically. We could always write a helper function that elides calling the Sampler if there are no measurements, but then we're back to where we started: hiding the Sampler from the user. Alternatively, perhaps the sampler could be modified to have a flag that elides execution (rather than errors) if there are no measurements, but it would take time to get that integrated into all the Sampler implementations.

@garrison
Copy link
Member

The way a user can hack around it without requiring any changes to CKT is to add a Pauli Z observable somewhere in the subsystem that is currently throwing an error with all identities.

Actually, automating this hack is probably the best way for us to "quick fix" this, too. We can modify generate_cutting_experiments to always have at least one measurement in each circuit, and this can be done in 0.4.1, without breaking anything.

The "better" fix is going to be to skip the circuit evaluation altogether, which will probably involve tweaking an interface and is related to the issues I linked above.

garrison added a commit that referenced this issue 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>
mergify bot pushed a commit that referenced this issue 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 issue 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
bug Something isn't working cutting QPD-based circuit cutting code good first issue Good for newcomers highly desired
Projects
None yet
Development

No branches or pull requests

2 participants