-
Notifications
You must be signed in to change notification settings - Fork 120
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
CRZ gate decomposition error #103
Comments
So a problem here is that different libraries and people use different standards for this gate. I believe I based the current definition on the qasm spec, but I can check |
Yeah, I was right: the official QASM2.0 spec says that the current definition we have is the correct one. See page 12 of https://arxiv.org/pdf/1707.03429.pdf. By the way, I do agree that your definition is more sensible, and it is also how I think of a crz gate. But that is not how it is defined in the spec. |
Maybe it's the version of OpenQASM that causes the misunderstanding! According to OpenQASM3.0, the |
Yes QASM3.0 seems to use your definition. Which is annoying because now the specs aren't compatible apparently? |
… in pyzx. The OpenQASM 2 spec defines the following: ``` gate rz(phi) a { u1(phi) a; } gate crz(lambda) a,b { u1(lambda/2) b; cx a,b; u1(-lambda/2) b; cx a,b; } gate cu1(lambda) a,b { u1(lambda/2) a; cx a,b; u1(-lambda/2) b; cx a,b; u1(lambda/2) b; } ``` pyzx's `ZPhase` gate and `CRZ` gates are equivalent to, respectively, OpenQASM 2's `rz` (a synonyn for `u1`) and `crz` gates. Confusingly, the `crz` gate is not simply a controlled version of the `rz` gate; that gate is named `cu1`. Meanwhile, the OpenQASM 3 spec defines: ``` gate rz(λ) a { gphase(-λ/2); U(0, 0, λ) a; } gate crz(θ) a, b { ctrl @ rz(θ) a, b; } ``` This has the advantage that `crz` is now simply a controlled version of `rz`, at the expense of changing the meaning of `rz` so that it no longer matches `u1`/`ZPhase`. This difference in conventions leads to user confusion and coding errors, as seen in issues zxcalc#102 and zxcalc#103. As well, changing the behaviour of `qasmparser` depending on the version of OpenQASM used is a blocker for issue zxcalc#116.
… in pyzx. The OpenQASM 2 spec defines the following: ``` gate rz(phi) a { u1(phi) a; } gate crz(lambda) a,b { u1(lambda/2) b; cx a,b; u1(-lambda/2) b; cx a,b; } gate cu1(lambda) a,b { u1(lambda/2) a; cx a,b; u1(-lambda/2) b; cx a,b; u1(lambda/2) b; } ``` pyzx's `ZPhase` gate and `CRZ` gates are equivalent to, respectively, OpenQASM 2's `rz` (a synonym for `u1`) and `crz` gates. Confusingly, the `crz` gate is not simply a controlled version of the `rz` gate; that gate is named `cu1`. Meanwhile, the OpenQASM 3 spec defines: ``` gate rz(λ) a { gphase(-λ/2); U(0, 0, λ) a; } gate crz(θ) a, b { ctrl @ rz(θ) a, b; } ``` This has the advantage that `crz` is now simply a controlled version of `rz`, at the expense of changing the meaning of `rz` so that it no longer matches `u1`/`ZPhase`. This difference in conventions leads to user confusion and coding errors, as seen in issues zxcalc#102 and zxcalc#103. As well, changing the behaviour of `qasmparser` depending on the version of OpenQASM used is a blocker for issue zxcalc#116.
The definitions in the OpenQASM 3 header file are:
If I understand this correctly, |
PR #156 specifically adds a test to document the behaviour of |
This issue can be closed. |
Hi, according to

pyzx/circuit/gates.py
, your decomposition and tensor of crz(pi/2) is shown below:However, the correct form of crz(pi/2) should be like this:

Refer to this transformation:

May I submit a PR to modify this bug?
The text was updated successfully, but these errors were encountered: