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

Add rotated RB circuits to calibrator #2065

Closed
nathanshammah opened this issue Oct 20, 2023 · 6 comments · Fixed by #2248
Closed

Add rotated RB circuits to calibrator #2065

nathanshammah opened this issue Oct 20, 2023 · 6 comments · Fixed by #2248
Assignees
Labels
benchmarks Tools for benchmarking error mitigation methods. calibration
Milestone

Comments

@nathanshammah
Copy link
Member

Issue Description

There is a new type of benchmark quantum circuits, rotated_rb_circuits that could be added to the benchmarks performed by the calibrator.

Proposed Solution

Add generate_rotated_rb_circuits to the calibration settings, like what is done here.

Possibly, one could list the benchmark circuits available also in the part of the user guide on calibration and/or in the calibration tutorial.

Discuss whether to set a seed for simpler CI.

Additional References

API-doc for rotated RB circuits
Calibration in the user guide

@nathanshammah nathanshammah added benchmarks Tools for benchmarking error mitigation methods. feature-request A request for a feature, tool, or workflow in Mitiq. calibration labels Oct 20, 2023
@nathanshammah
Copy link
Member Author

@Misty-W happy to be assigned to this.

@natestemen natestemen removed the feature-request A request for a feature, tool, or workflow in Mitiq. label Oct 26, 2023
@natestemen natestemen added this to the 0.32.0 milestone Nov 3, 2023
@natestemen natestemen removed this from the 0.32.0 milestone Dec 19, 2023
@Misty-W Misty-W added this to the 0.33.0 milestone Jan 2, 2024
FarLab added a commit that referenced this issue Feb 6, 2024
@FarLab
Copy link
Contributor

FarLab commented Feb 12, 2024

@bdg221 @Misty-W @natestemen After more extensive testing, it looks like the distribution we thought was the ideal one for the rotated RB circuits is wrong. For example, for an angle theta=pi/5, it is possible to measure all possible bitstrings (we thought only '00' and '01' were possible). It is probably more complicated and this issue might need more time to find the ideal distribution.

@Misty-W
Copy link
Contributor

Misty-W commented Feb 13, 2024

After more extensive testing, it looks like the distribution we thought was the ideal one for the rotated RB circuits is wrong.

I have proposed a possible fix for the strange distributions, PR #2185. PR is to @FarLab 's branch instead of master for testing purposes.

Still, this issue needs more work and review before merge and milestone 0.34.0 is closing, so I will clear the milestone from this issue.

@Misty-W Misty-W removed this from the 0.34.0 milestone Feb 13, 2024
@natestemen natestemen added this to the v0.35.0 milestone Feb 23, 2024
@FarLab
Copy link
Contributor

FarLab commented Mar 13, 2024

Looks like there is an analytic solution for the ideal distribution for the rotated rb circuits, which was expected looking at the empirical distribution. I have done the calculation for the single qubit case, but the 2 qubit case is similar but more tedious.

So how do we compute the ideal distribution $p_0(\theta)$? It is the expectation value of the probability that we measure $\ket{0}$ where the randomness is taken over the choice of Clifford gates. This can be expressed as follows:

$$p_0(\theta)=\mathbb{E}|\bra{0} C R_z(\theta)C^{-1}\ket{0}|^2$$

where the expectation value is taken over $C$ of the single qubit Cliffords. You could evaluate this discrete sum directly, by going over all the 24 possible elements of the group, which might be tedious. Or you use the fact that Cliffords form a 1-design (it even forms a 3-design, but we don't need that). So we may replace the sum with an integral over the 2 by 2 unitary matrices

$$p_0(\theta) = \int dU |\bra{0} U R_z(\theta)U^{-1}\ket{0}|^2.$$

Remember that $R_z(\theta) = \cos(\theta/2) I - i\sin(\theta/2) Z$, so $U R_z(\theta)U^{-1} = \cos(\theta/2)I - i\sin(\theta/2)U Z U^{-1}$. So

$$p_0(\theta) = \int dU \cos^2(\theta/2) + \sin^2(\theta/2) (UZU^{-1})_{0,0}^2.$$

So we just need to compute the top left coordinate of the matrix $UZU^{-1}$ and integrate. You can use your favorite parametrization of the unitary group. We use

$$U = e^{i\alpha} \left( \matrix{ e^{i\psi}\cos(\phi) & e^{i\chi} \sin(\phi) \cr -e^{-i\chi} \sin(\phi) & e^{-i\psi}\cos(\phi) \cr} \right)$$

where $0\leq \phi\leq \pi/2$ and $0\leq \alpha, \psi, \chi < 2\pi$ and volume element $dU = \frac{1}{(2\pi)^3}\sin(2\phi) d\alpha d\phi d\psi d\chi$ (see https://arxiv.org/pdf/math-ph/0210033.pdf for example). What is left is just computing the integral and the answer is $p_0(\theta) = 1-\frac{2}{3}\sin^2(\theta/2)$ and $p_1(\theta) = \frac{2}{3}\sin^2(\theta/2)$.

This is also what I roughly found empirically, by sampling random circuits from generate_rb_circuits function for several values of $\theta$ and the result was (although sampling 0 and 1 were flipped)
output

This was the procedure for finding the ideal distribution of measuring 0 using rotated rb circuits for one qubit. To do it for two qubits requires more computation (see https://arxiv.org/pdf/math-ph/0202002.pdf), but the procedure is exactly the same.

@natestemen
Copy link
Member

Thanks Farrokh for the detailed comment, and nice derivation! I've got a few questions about it, just so I can understand better.

Questions/comments

$p_0(\theta) = \mathbb{E}|\bra{0} C R_z(\theta)C^{-1}\ket{0}|^2$

Nice thinking with this as the expectation value of interest. Since the Clifford are closed under multiplication (they're a group after all), this makes perfect sense!

So we just need to compute the top left coordinate of the matrix $UZU^{-1}$ and integrate

Why do you only need to consider the $_{0, 0}$ element?

Cliffords form a 1-design

Do you have a reference for this? Not doubting it, I just want to learn why this is the case!

Finally, one of the questions we had while working on this together was does the rotation need to go in the middle of the circuit? Do you feel like this derivation gives you any answer there? What if the rotation was the first operation on the qubit?

Next steps

Since we now have the ideal distribution for 1 qubit, we should be able to finish adding this to the calibrator as one of the different types of experiments it can run. Let me know if you need any assistance adding that functionality into the code!

BTW, I don't think we need to go through the derivation (unless it's simple and/or you want to!) for 2 qubits.

@FarLab
Copy link
Contributor

FarLab commented Mar 14, 2024

Why do you only need to consider the 0,0 element?

That is because we want the probability of measuring $\ket{0}$. You can see it in the expression for $p_0(\theta)$, i.e. $\bra{i} A\ket{j} = A_{i,j}$ in general.

Do you have a reference for this? Not doubting it, I just want to learn why this is the case!

No worries, you can find the paper here https://arxiv.org/pdf/1510.02769.pdf

Finally, one of the questions we had while working on this together was does the rotation need to go in the middle of the circuit? Do you feel like this derivation gives you any answer there? What if the rotation was the first operation on the qubit?

From this derivation we can see that it doesn't really matter where we place the rotation, as long as it is not in the end or at the very start! Because in that case the circuit simplifies to just $R_z(\theta)$ and you get $p_0(\theta)=1$.

Let me know if you need any assistance adding that functionality into the code!

Thanks! I will definitely reach out if I need help. Regarding the 2 qubit case, if we want to implement it, we might have to do the computation. Of course we can empirically find the distribution, but that will be an approximation and I think it would nice to have the exact distribution. For the milestone we can just do the 1 qubit case, and later we can add the 2 qubit case as well if we want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmarks Tools for benchmarking error mitigation methods. calibration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants