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

Fixing compiler rule #1044

Merged
merged 1 commit into from
Sep 30, 2024
Merged

Fixing compiler rule #1044

merged 1 commit into from
Sep 30, 2024

Conversation

andrea-pasquale
Copy link
Contributor

@andrea-pasquale andrea-pasquale commented Sep 16, 2024

I believe that this was the issue which was giving us a weird behavior in the single qubit tomography @stavros11 @alecandido.

If we consider the definition of GPI2 provided by Qibo we have that $GPI2(0) = R_X(\pi/2)$ and $GPI2(\pi /2) = R_Y(\pi/2)$ which means that the GPI2 should have the following representation

$$ GPI2(\phi) = e^{-i \frac{\pi}{2} ( \cos{\phi} X + \sin{\phi} Y)} $$

We now need to compute how $GPI2(\phi)$ changes when we apply an $R_Z(\tilde \phi)$ gate

$$ R_Z(\tilde \phi) GPI2(\phi) R_Z(- \tilde \phi) = GPI2( \phi^*) $$

We can find $\phi^*$ with the following passages

$$ R_Z ( \tilde \phi) e^{-i \frac{\pi}{2} ( \cos{\phi} X + \sin{\phi} Y)} R_Z (- \tilde \phi) = e^{-i \frac{\pi}{2} ( \cos{(\phi - \tilde \phi)} X + \sin{(\phi - \tilde \phi)} Y)} =GPI2 (\phi - \tilde \phi). $$

Therefore $\phi^* = \phi - \tilde \phi$ which means that rule for $R_Z(\tilde \phi)$ should be $\phi \rightarrow \phi - \tilde \phi$

@stavros11 feel free to check and let me know if the fix works for you as well.
Currently this PR is pointing to main feel free to merge it directly to 0.2 or 0.1.

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.24%. Comparing base (9bbbbe8) to head (cb04076).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1044   +/-   ##
=======================================
  Coverage   70.24%   70.24%           
=======================================
  Files          64       64           
  Lines        6701     6701           
=======================================
  Hits         4707     4707           
  Misses       1994     1994           
Flag Coverage Δ
unittests 70.24% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@alecandido
Copy link
Member

Thanks @andrea-pasquale. I agree with the explanation, and I trust your experiment.

It would be nice to have this fix in both 0.1 and 0.2 (e.g. we could merge this PR in 0.1, and I could repeat the fix in 0.2). But before merging, I'd like to have a test failing in main and passing here to merge together, in order to avoid regressions.

If no one will volunteer before, I'll provide the test myself.

@Edoardo-Pedicillo Edoardo-Pedicillo dismissed their stale review September 16, 2024 14:14

I have realized it is not ready for review

@Edoardo-Pedicillo
Copy link
Contributor

There is a small typo in the last formula ( it should be $R_Z ( - \tilde \phi) e^{-i \frac{\pi}{2} ( \cos{\phi} X + \sin{\phi} Y)} R_Z ( \tilde \phi)$, so $\phi \rightarrow \phi + \tilde \phi$ ) .

Btw, from the Manenti book, sec 14.6.1, we know that a generic sinusoidal pulse $V(t)=A\epsilon(t) sin(\omega t + \alpha)$ corresponds to a generic rotation

$$ R_{n(\alpha)} (\theta) = e^{-i \frac{\theta}{2} ( \cos{(\alpha)} X + \sin{(\alpha)} Y)} $$

and it holds that (sec.14.6.4)

$$ Z_{-\alpha} X_{\beta} Z_{\alpha} = R_{n(-\alpha)} (\beta). $$

Since we can decompose a generic GPI2 as

$$ GPI2(\phi) = Z_{\phi} X_{\pi/2} Z_{-\phi} = R_{n(\phi)} (\pi/2), $$

we can see that the sign of the GPI2 phase in qibolab is correct and we have to change the Z rule, in principle leaving the latter as it is and changing the sign of the phase in the $GPI2 (\phi)$ should give the same results when we execute it, but the error will propagate when we execute 2q gates.

@alecandido alecandido changed the base branch from main to 0.1 September 17, 2024 17:33
@alecandido
Copy link
Member

I didn't take the time yet to check it yet. But if you're using it, I'm open to trust your results.

To properly determine the sign, it should be traced in the calculation (as you did), and through the whole usage in the code.
In any case, there are just two options, and if one is proven to work, while the other not, it's quite likely it is the correct answer (though there could be two errors balancing only in the tested case, but failing somewhere else - but it's not that complex, so there isn't that much room for something like that).

Whenever it will be merged, I will apply the same fix to 0.2.

@alecandido
Copy link
Member

@stavros11 maybe this is not the final solution to all the (default) compiler problems, but it's well-documented (and arguably well-motivated), and it fixes something.

I'd propose to merge this and the companion PR #1057 for 0.2, and then scheduler a deeper review of the transpiler/compiler.

@stavros11 stavros11 merged commit a6049a9 into 0.1 Sep 30, 2024
35 checks passed
@stavros11 stavros11 deleted the fix_compiler branch September 30, 2024 13:56
@alecandido alecandido added this to the Qibolab 0.1.10 milestone Oct 25, 2024
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.

4 participants