-
Notifications
You must be signed in to change notification settings - Fork 119
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
Support for OpenQASM 3.0 #116
Comments
I think this particular issue can probably be quite easily fixed with a hacky solution. Namely just acknowledging that |
… 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.
Addresses issue zxcalc#116: - accept OpenQASM 3 file header produced by qiskit - condition behaviour of `rz` based on version: - OpenQASM 2: same as `ZPhase` = `diag(1, exp(i*phi))` (unchanged) - OpenQASM 3: acts like `diag(exp(-i*phi/2), exp(i*phi/2))` - add `p` as an alias for `ZPhase` in OpenQASM 3 - add `u1` as an alias for `ZPhase` in both versions
PR #156 adds supports for OpenQASM 3 format. I tried some exports from qiskit and they seem to import just fine, so unless there are requests for additional qasm gates not covered by that PR, this issue can be closed. |
I think this issue can be closed now. |
Hi there,
I am trying to use PyZX to attempt reducing the footprint of some circuits I designed in Qiskit.
When trying to run
pyzx.qasm
on the QASM source generated by Qiskit, I was getting an error onimport 'stdgates.inc'
, which I understand is a library of "standard" gates used by Qiskit.I tried replacing the line with the content of stdgates.inc, however this results in
TypeError: Arguments for custom gates are currently not supported: p(λ) a { ctrl @ gphase(λ) a; }
on the very first "phase" gate in the file.I could try downgrading to a previous Qiskit, however I was wondering if there is any way to support this out of the box, since anyway it seems OpenQASM 2.0 is considered deprecated.
The text was updated successfully, but these errors were encountered: