-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
PT + ZNE tutorial #2601
PT + ZNE tutorial #2601
Conversation
@natestemen Do you mind taking a quick look at the general outline of this tutorial? I have to clean up the code a bit. So, you could ignore the code blocks for now. I am not too sure if I need to describe something in excruciating detail as the PT user guide is still WIP. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2601 +/- ##
==========================================
+ Coverage 98.72% 98.74% +0.01%
==========================================
Files 92 93 +1
Lines 4168 4219 +51
==========================================
+ Hits 4115 4166 +51
Misses 53 53 ☔ View full report in Codecov by Sentry. |
Took a quick look through things and this looks great! I think it's a nice split of theory and practice. I can imagine some of the material working its way in to the user guide, but lets not worry about that for now. |
@natestemen The comparison plot is missing data related to only ZNE values. This is because the circuit I am using is very small for ZNE. If I increase the circuit size used for the comparison plot, the time taken by the tutorial during execution is a lot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't finished reading through everything just yet, but wanted to get feedback soon so we can start iterating.
Overall this is a really great mix of theory and practice. Well done setting the bones up.
I restarted the RTD build; having a rendered version will make it easier to review. |
3f6f478
to
cf8b1a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really solid tutorial! Can't wait to get it up!
plt.ylabel("Expectation Values Difference") | ||
plt.title("Comparison of expectation values with ideal as a function of noise strength") | ||
plt.legend() | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we understand why ZNE is so good when the noise strength = 0.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not too sure for the circuit used in this example.
If I use a smaller GHZ circuit of 2 qubits, the noise does not do anything as the final state vector before and after adding coherent noise is the same. Interestingly, this behavior is not preserved as the number of qubits in the initial ghz circuit is increased. Worth looking into!
Co-authored-by: nate stemen <[email protected]>
5c95219
to
d0d4b2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, but hopefully nothing major!
docs/source/examples/pt_zne.md
Outdated
**Incoherent noise** is a process that results in the quantum system entangling with its environment i.e. this type of noise is irreversible. The system and the environment end up in a mixed state. It scales linearly in the small error limit. | ||
The noise channel can be described using Pauli operators which makes it easy to analyze and simulate. Worst case error rate is directly proportional to the **average gate infidelity**. | ||
|
||
For example, a depolarizing noise channel is a stochastic noise channel where a noiseless process is probabilistically mixed with orthogonal errors. If $\rho$ is a single qubit state, $p$ is the probabilistic error rate and $\mathcal{E}(\rho)$ is the noise channel: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great example, but it needs a connection back to (in)coherent noise. Can you add something, maybe at the end?
Do you think we should have an example for coherent noise too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The depolarizing noise example is to show how Pauli twirling is equivalent to tailoring the noise into a depolarizing noise channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite see how this relates to pauli twirling. Can you help spell it out?
From my perspective the main idea in pauli twirling is to add gates that compile to the identity, but change the impact of noise. So when you say the depolarizing channel can be written in terms of paulis, I don't see how that is pauli twirling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my perspective the main idea in pauli twirling is to add gates that compile to the identity,
Uh, no. Pauli twirling's goal is to transform some noise channel into a local depolarizing noise channel. The circuits average over to a mixed noise channel which is what I was trying to show in my example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pauli twirling's goal is to transform some noise channel into a local depolarizing noise channel.
Right, yes, good point. That's the main goal. When adding gates surrounding each CNOT, you do it in such a way so that the CNOT is still the logical operation (up to global phase). In that sense are we not adding gates that end up compiling out (should you compile, which, you shouldn't)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused about the 'compile to identity' phrase.
If we start out with a CNOT subjected to a coherent noise channel, after Pauli twirling it's a CNOT gate with incoherent noise. That's what I was trying to show with the equations. Pauli twirling is equivalent to a local depoalrizing channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused about the 'compile to identity' phrase.
Yeah that was sloppy phrasing on my part, sorry! I think we agree that the effect of pauli twirling on an ideal CNOT is the identity map (PT(ideal CNOT) = ideal CNOT).
Pauli twirling is equivalent to a local depoalrizing channel.
Is that true in all cases? I think Pauli twirling (in the infinite samples limit) only guarantees a Pauli channel is spit out, right?
BTW thanks for going back and forth on this a few times. It's really helpful for my understanding!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Pauli twirling (in the infinite samples limit) only guarantees a Pauli channel is spit out, right?
Depends on the noise strength, the number of Pauli twirled circuits etc. If you look at the gif example, I ended up at a finite number of pauli twirled circuits that gave us the ideal CNOT PTM. I'll edit the lines to discuss this.
BTW thanks for going back and forth on this a few times. It's really helpful for my understanding!
No worries!
docs/source/examples/pt_zne.md
Outdated
print("Example noisy twirled circuit", noisy_twirled_circuits[-1], sep="\n") | ||
``` | ||
|
||
The twirled PTM is averaged over each noisy twirled circuit such that the new PTM is close to that of the PTM of incoherent noise. We skip the step in this section as we require a very large number of twirled circuits to demonstrate the desired effect of averaging over multiple numpy arrays. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit anti-climatic, I was looking forward to seeing the effect of this on those PTM heatmaps :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, well, this increases the notebook execution time by a lot. The coherent noise that I used is obviously not included in the noisy options allowed by generate_pauli_twirl_variants
. We should create an issue to clean this portion of pauli twirling.
So, if I want to generate 100 pauli twirled circuits, I have to splice each of the circuits to make sure the noise is inserted in the correct spot and the pauli twirling gates are also inserted accordingly. Then, the next step is to get their PTM's and sum them up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we included an image of the twirled PTM heatmap saying "this is what would happen if you generated the twirled PTM"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added 3 4 examples. See 2fbf94f.
I also changed the color palette to make the heatmap easy to read.
Ideally, I would prefer this to be a gif (something like this) to show how the heatmap changes as the number of pauli twirled circuits is increased. We could keep this as a unitary hackathon issue if there are not a lot of non-quantum issues. WDYT?
I manually created a gif in 818a864 Hopefully, this fixes Alessandro's comment.
I was looking forward to seeing the effect of this on those PTM heatmaps
Co-authored-by: nate stemen <[email protected]>
4ea318f
to
c890f2b
Compare
@natestemen @cosenal This is ready. Whenever you guys are free... Good luck with FOSDEM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to go once my comments are addressed (and Alessandro's incoming).
@natestemen I know you already approved this. Pinging you again in case you want to take a look at the changes in aeb9d8f I added a new sub-section to add more information about the quadratic and linear error rates. @cosenal PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
executor=partial(execute, noise_level=NOISE_LEVEL) | ||
|
||
def combine_zne_pt(list_circuits, executor) -> List[float]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
* add md file * add comparison plot * add thumbnail image * correct plot typo * update plot * nate/alessandro feedback * correct typo * Apply suggestions from code review Co-authored-by: nate stemen <[email protected]> * check build: set heatmap bounds and y axis label * nate's suggestions to code, update thumbnail image * ordering phrasing * some suggested changes and example twirled ptms * Update docs/source/examples/pt_zne.md Co-authored-by: nate stemen <[email protected]> * remaining suggestions * add 100 twirled circuits plot * typo lets to let's * change to gif * typo 300 to 100 circuits * Apply suggestions from code review Co-authored-by: nate stemen <[email protected]> * remaining suggestions (nate) + remove links to images in favor of gif * erroneously capitalized Paulis in function defs * some of Alessandro's comments * remaining alessandro's comments * typos * nate's comment --------- Co-authored-by: nate stemen <[email protected]>
Description
Fixes #2374
License
Before opening the PR, please ensure you have completed the following where appropriate.