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

Pauli Twirling (PT) User Guide #1848

Merged
merged 18 commits into from
Sep 30, 2023
Merged

Pauli Twirling (PT) User Guide #1848

merged 18 commits into from
Sep 30, 2023

Conversation

Aaron-Robertson
Copy link
Contributor

@Aaron-Robertson Aaron-Robertson commented May 26, 2023

Description

Fixes #1833

To-Dos before merging

  • Replace the png with svg - center all text properly : svg's are not rendered correctly depending on the choice of browser. In safari, the text in the SVG was not aligned correctly. Find which changes to make before replacing png.

License

  • I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Fund the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

Before opening the PR, please ensure you have completed the following where appropriate.

@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch unitaryfund/mitiq/ar-pt-guide

@Misty-W
Copy link
Contributor

Misty-W commented May 26, 2023

hi @Aaron-Robertson, if you add pt.md to the toctree in guide.md, that should fix at least some of the errors.

@Aaron-Robertson Aaron-Robertson marked this pull request as ready for review May 30, 2023 01:11
@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (7980385) 98.28% compared to head (ff51d9f) 98.31%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1848      +/-   ##
==========================================
+ Coverage   98.28%   98.31%   +0.02%     
==========================================
  Files          86       86              
  Lines        4084     4084              
==========================================
+ Hits         4014     4015       +1     
+ Misses         70       69       -1     
Files Coverage Δ
mitiq/pt/pt.py 100.00% <ø> (ø)

... and 3 files with indirect coverage changes

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

@purva-thakre
Copy link
Collaborator

purva-thakre commented May 30, 2023

@Aaron-Robertson Your docs build might be failing because you did not separate the 2 cited bib refs by a comma.

Actually, I think there might be other cell execution issues. never mind!

Copy link
Contributor

@Misty-W Misty-W left a comment

Choose a reason for hiding this comment

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

Nice to see this filled out, @Aaron-Robertson !

My main concern is that the error-mitigated results displayed do not match the descriptions in the text, i.e. showing a worse result in the intro, and the low-level results not closely matching the results from execute_w_pt.

The rest are minor wording suggestions.

docs/source/guide/pt.md Outdated Show resolved Hide resolved
docs/source/guide/pt-1-intro.md Outdated Show resolved Hide resolved
print(f"Error with mitigation (PT): {abs(ideal_value - mitigated_result) :.3}")
```

Here we observe that the application of PT reduces the estimation error when compared
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately this doesn't seem to be the case in https://mitiq--1848.org.readthedocs.build/en/1848/guide/pt-1-intro.html .

At least part of the problem appears to be that there is no noise applied to obtain the "noisy" result.


```{admonition} Note:
PT is designed to mitigate the simple Markovian noise simulated in this example,
but PT can still have a non-trivial effect on the final error, but it is not
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
but PT can still have a non-trivial effect on the final error, but it is not
but PT can still have a non-trivial effect on the final error, although it is not

docs/source/guide/pt-4-low-level.md Show resolved Hide resolved
Comment on lines 119 to 126
Let's verify this fact:

```{code-cell} ipython3
np.isclose(
pt.execute_with_pt(circuit, executor),
average,
)
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the results displayed don't match the text- np.isclose asserts False, see https://mitiq--1848.org.readthedocs.build/en/1848/guide/pt-4-low-level.html .

@andreamari
Copy link
Member

@Aaron-Robertson, thanks this is a lot of useful documentation!
This is not a proper review, but I'd like to give some general comments:

  1. I think we shouldn't claim that PT is an error mitigation technique. By design, PT is not expected to reduce noise. The aim of PT is to transform any noise channel into a Pauli noise channel. So PT is more a noise transformation technique. From a code point of view, the workflow is similar to other techniques but the physical effect is different. Typically, PT is used as a pre-processing step before applying other mitigation techniques. This aspect is perhaps the most important thing we should say in the docs about PT, otherwise users will try to apply it in the wrong way.

  2. I wouldn't mention the subtle aspects about Markovian vs non-Markovian noise. Those aspects are very important for DDD (a technique originally designed for non-Markovian noise) but are much less important for PT which has a different goal.

  3. While DDD is expected to work even with a single circuit (without averaging over different DDD sequences), for PT averaging over many circuits is essential otherwise the noise is not mapped to a Pauli channel. So, if possible, we should change the workflow figures and the associated discussion accordingly. The input circuit is first mapped to many twirled circuits (step 1) --> execution ---> The results are averaged (step 2).

@Aaron-Robertson
Copy link
Contributor Author

Aaron-Robertson commented Jun 2, 2023

Thanks @andreamari @Misty-W!

I think we shouldn't claim that PT is an error mitigation technique. By design, PT is not expected to reduce noise. The aim of PT is to transform any noise channel into a Pauli noise channel. So PT is more a noise transformation technique. From a code point of view, the workflow is similar to other techniques but the physical effect is different. Typically, PT is used as a pre-processing step before applying other mitigation techniques. This aspect is perhaps the most important thing we should say in the docs about PT, otherwise users will try to apply it in the wrong way.

Great point. I tried to capture aspects of it, but I'll be more explicit in calling it a noise transformation and/or tailoring technique. In this way, would it make sense to remove the expectation value examples from the PT section? Or simply state that the effect on the expectation value is as we would expect?

@andreamari
Copy link
Member

Great point. I tried to capture aspects of it, but I'll be more explicit in calling it a noise transformation and/or tailoring technique. In this way, would it make sense to remove the expectation value examples from the PT section? Or simply state that the effect on the expectation value is as we would expect?

We have the function execute_with_pt in Mitiq and so it is fine show it in the docs and stating that we don't expect a better accuracy when applying PT alone.
Alternatively we could directly show something like PT+ZNE, which is the expected reduce errors. I originally thought to keep the PT+XXX case as a future Mitiq example, but it could also go in the main docs if you think if fits well.

Any option is good, as long as we don't give the wrong impression that PT mitigates noise.

@purva-thakre
Copy link
Collaborator

purva-thakre commented Jun 2, 2023

If the goal is to show pauli twirling works to tailor the noise, one option could be to look at the PTM (pauli transfer matrix) superoperator before & after. The discussion could be about how the off-diagonal terms are gone after pauli twirling.

@purva-thakre
Copy link
Collaborator

purva-thakre commented Aug 25, 2023

@Misty-W @Aaron-Robertson If we are moving past calculating an expectation value for pauli twirling, should we change execute_with_pauli_twirling to tailor_circuit_with_pauli_twirling?

@Misty-W
Copy link
Contributor

Misty-W commented Aug 25, 2023

@Misty-W @Aaron-Robertson If we are moving past calculating an expectation value for pauli twirling, should we change execute_with_pauli_twirling to tailor_circuit_with_pauli_twirling?

I vote "yes"!

@purva-thakre
Copy link
Collaborator

@Aaron-Robertson Do you have any local changes for this PR? We changed the output of the twirling functions in #1977. I can take over from here and finish this PR as well.

@Misty-W
Copy link
Contributor

Misty-W commented Sep 6, 2023

hi @purva-thakre and @Aaron-Robertson, I'm guessing this PR will probably need to go in the next release. Importantly, we've made good progress toward the pre-requisite of checking the PTM, and we can build up incrementally from there.

@purva-thakre
Copy link
Collaborator

hi @purva-thakre and @Aaron-Robertson, I'm guessing this PR will probably need to go in the next release. Importantly, we've made good progress toward the pre-requisite of checking the PTM, and we can build up incrementally from there.

Yep, the deadline for this one needs to be stretched to the next milestone. There were a few things outside the Pauli Twirling module that needed to be dealt with before tackling this PR.

@nathanshammah nathanshammah changed the title PT User Guide Pauli Twirling (PT) User Guide Sep 13, 2023
@purva-thakre
Copy link
Collaborator

@Misty-W @Aaron-Robertson @andreamari @nathanshammah @natestemen Do either of you have access to the original images used in this PR? I need to make changes to them as the functions only tailor the noise with the new changes.

If not, it's ok. I can create my own.

@natestemen
Copy link
Member

Do either of you have access to the original images used in this PR?

It looks like an svg, so if you load it into inkscape (or similar), I believe you should be able to modify it?

@purva-thakre
Copy link
Collaborator

Never edited an svg before. I can give it a try. Thanks!

Here, we observe that the application of the Pauli Twirling technique has kept the logic
of the input circuit unchanged while introducing a combination of gates to twilred outputs.

## Combine PT with ZNE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move Aaron's code here where the ideal expectation value is compared to the mitigated one.

@purva-thakre purva-thakre force-pushed the ar-pt-guide branch 2 times, most recently from b410504 to 6818ba8 Compare September 18, 2023 19:20
@nathanshammah
Copy link
Member

Apparently the svg file for the PT workflow shows differently in some browsers, and in others it looks fine. If possible, it would be nice to fix this so that the text does not go beyond the image. Using png format could also be fine.

@nathanshammah nathanshammah added this to the 0.30.0 milestone Sep 22, 2023
@nathanshammah nathanshammah removed their request for review September 22, 2023 16:23
@purva-thakre
Copy link
Collaborator

purva-thakre commented Sep 25, 2023

Edit2: Looks like I have a bug. Apologies for the previous message!

mitiq/pt/pt_utils.py Outdated Show resolved Hide resolved
@purva-thakre
Copy link
Collaborator

purva-thakre commented Sep 29, 2023

I suggest we merge this once all the tests pass and the new changes have been reviewed. I have created Notes to make a comment along the lines of some things are coming in the future. Those things would be the pauli transfer matrix as well as a tutorial combining an error mitigation technique with twirling.

I think I need some more time on the PTM issue because there's either a bug in my code or my understanding of how Pauli Twirling is supposed to work is flawed. For some reason, I could see the magnitude of the off-diagonal terms in the PTM decrease but not go away completely.

Either way, I need to work out the math first of what a CNOT and CZ does to the coefficients in a PTM. When I was discussing this problem with my adviser he pointed out Pauli Twirling single-qubits gates is straightforward as the twirling gate set is also in SU(2). But in this case, we are trying to Pauli Twirl a SU(4) gate by using a SU(2) gate set where the non-local parts of CNOT/CZ are not really affected by the twirling process. I believe Aaron was not getting a better expectation value after PT for the same reason.

Edit: More on the non-local parts of a gate in SU(4). Screenshot taken from https://arxiv.org/abs/quant-ph/0507171

image

@purva-thakre
Copy link
Collaborator

@Misty-W This is ready to be merged on a tentative basis. There are warnings on every page of the user guide that the Pauli Twirling module is currently WIP.

Copy link
Contributor

@Misty-W Misty-W left a comment

Choose a reason for hiding this comment

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

Approved, with plan to update in the next milestone! Thanks for picking this up @purva-thakre!

@purva-thakre purva-thakre merged commit 0c0b7a0 into master Sep 30, 2023
19 checks passed
@natestemen natestemen deleted the ar-pt-guide branch April 26, 2024 15:15
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.

Add Pauli twirling in User Guide
6 participants