tket icon indicating copy to clipboard operation
tket copied to clipboard

`tk1_to_rzsx` on `TK1(0, 1.5, 0)` outputs 3 `sx` in tket 1.32 but only 1 `sx` in tket 1.7

Open jacofeld opened this issue 1 year ago • 3 comments

I recently upgraded my tket version from 1.7 to 1.32 (I know, it's been a while), and I noticed that TK1(0, 1.5, 0), when run through auto_rebase_pass({OpType.SX, OpType.ECR, OpType.Rz}) in tket 1.32, was decomposed to three SX commands where there was only 1 SX command output in tket 1.7.

From what I can tell, this is because the tk1_to_rzsx decompositions changed:

1.32 version

1.7 version

The two are equivalent up to a global phase.

Was this intentional? the new version (3 SXs) is less optimal on hardware, right?

jacofeld avatar Oct 22 '24 21:10 jacofeld

Hi, thanks for making an issue. I don't know what the reason for the change was (if there was a reason)

@sjdilkes any ideas on this?

I use AutoRebase rather than auto_rebase_pass as the latter is deprecated now. Although this shouldn't matter for the issue you raise.

CalMacCQ avatar Oct 25 '24 13:10 CalMacCQ

Looking at the commit history, I suspect what's happening is TK1(0, 1.5, 0) is now using a decomposition introduced in this commit:

// a = 2k, b = 2m-0.5, c = 2n
// Rz(2k)Rx(2m - 0.5)Rz(2n) = (-1)^{k+m+n}e^{i \pi /4} X.SX

I guess the logic is that for non-zero a and c angles that arbitrary Rz is potentially more expensive than an SX gate - but in this case (with Rx(1) as well) it looks like it could be cheaper to just do the arbitrary Rx rotation. Though my understanding is that Rx(theta) = Rz(0.5).SX.Rz(0.5).Rz(theta).Rz(0.5).SX.Rz(0.5) so maybe the three SX gates is cheaper?

sjdilkes avatar Oct 25 '24 15:10 sjdilkes

@sjdilkes In hardware implementation, Rz usually doesn't requires a pulse. For example, in superconducting QC, Rz is implemented virtually as phases of the adjacent Rx gates. Similarly, in ion trap QC, Rz gate can be absorbed into the adjacent Rx-like gates. So, in terms of pulse length, Rz is less costly than Rx gate (Rz is often referred as "free"). So I think 2 RZ + 1 Sx should be generally cheaper (i.e., shorter pulse length) than 3 Sx.

yitchen-tim avatar Oct 26 '24 03:10 yitchen-tim

Thanks @yitchen-tim and @jacofeld , this makes sense. I've removed the alternative 3 SX gate construction which seems to be more inefficient on hardware in expected cases here -> https://github.com/CQCL/tket/pull/1643.

sjdilkes avatar Oct 30 '24 11:10 sjdilkes