Skip to content

To be confirmed: Inconsistency in controlled gate unitary between v0.8.2 and v0.9.1 #3636

@Kee-Wang

Description

@Kee-Wang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug-reportSomething doesn't seem to work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions