-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I found the unitary after applying .cotrolled()
on rz
behaves differently for version v0.8.2 and v0.9.1 which causes trouble.
The simplest code that that reproduce this issue on my computer is:
import cirq
import numpy as np
rz = cirq.rz(np.pi)
crz= rz.controlled()
u = cirq.unitary(crz)
print(u)
If I run this on v0.8.2, I got
[[0.-1.j 0.+0.j 0.+0.j 0.+0.j]
[0.+0.j 0.-1.j 0.+0.j 0.+0.j]
[0.+0.j 0.+0.j 0.-1.j 0.+0.j]
[0.+0.j 0.+0.j 0.+0.j 0.+1.j]]
If I run with v0.9.1, I got
[[1.+0.j 0.+0.j 0.+0.j 0.+0.j]
[0.+0.j 1.+0.j 0.+0.j 0.+0.j]
[0.+0.j 0.+0.j 0.-1.j 0.+0.j]
[0.+0.j 0.+0.j 0.+0.j 0.+1.j]]
Can anyone else reproduce this issue?
The former converted the control into CZPowGate
and the later is simply a controlled version of ZPowGate
.
If I understand it correctly, controlled ZPowGate
is turned into CZPowGate
only when at least the global shift of ZPowGate
is 0, as shown here, but the phase of a Rz
is -0.5 not 0 so it should never be turned into a CZPowGate
, is that right?
What is even more confusing is that I did not see any changes of controlled
method for version v0.8.2 and v0.9.1 so I would naively believe they should behave the same.