Skip to content
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

QASM instruction not parameterized for two-qubit Pauli rotation gates #7172

Closed
epelaaez opened this issue Oct 24, 2021 · 2 comments · Fixed by #9953
Closed

QASM instruction not parameterized for two-qubit Pauli rotation gates #7172

epelaaez opened this issue Oct 24, 2021 · 2 comments · Fixed by #9953
Labels
bug Something isn't working

Comments

@epelaaez
Copy link
Contributor

Information

  • Qiskit Terra version: 0.19.0.dev0+0ee0824
  • Python version: 3.9.6
  • Operating system: Windows 11

What is the current behavior?

The following snippet

from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import RZXGate
import numpy as np

qc = QuantumCircuit(2)
qc.append(RZXGate(np.pi), [0, 1])
qc.append(RZXGate(np.pi / 2), [0, 1])

qc.qasm()

Produces

OPENQASM 2.0;
include "qelib1.inc";
gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(pi) q1; cx q0,q1; h q1; }
gate rzx_1491288775456(param0) q0,q1 { h q1; cx q0,q1; rz(pi/2) q1; cx q0,q1; h q1; }
qreg q[2];
rzx(pi) q[0],q[1];
rzx_1491288775456(pi/2) q[0],q[1];

As you can see, instead of creating a single rzx instruction that uses param0, it creates a single rzx for each value present in the circuit.

Steps to reproduce the problem

This happens with at least all other RPPGates, where PP is placeholder for some Pauli matrices. I haven't tested it with other parameterized gates.

What is the expected behavior?

I think the output QASM string should look like:

OPENQASM 2.0;
include "qelib1.inc";
gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }
qreg q[2];
rzx(pi) q[0],q[1];
rzx(pi/2) q[0],q[1];

I tested it and using that string to build a QuantumCircuit gives the intended circuit.

string = """OPENQASM 2.0;
include "qelib1.inc";
gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }
qreg q[2];
rzx(pi) q[0],q[1];
rzx(pi/2) q[0],q[1];"""

qc = QuantumCircuit.from_qasm_str(string)

qc.decompose().draw()

Output:


q_0: ───────■─────────────■──────────────■───────────────■───────
     ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐┌───┐┌─┴─┐┌─────────┐┌─┴─┐┌───┐
q_1: ┤ H ├┤ X ├┤ Rz(π) ├┤ X ├┤ H ├┤ H ├┤ X ├┤ Rz(π/2) ├┤ X ├┤ H ├
     └───┘└───┘└───────┘└───┘└───┘└───┘└───┘└─────────┘└───┘└───┘
@epelaaez epelaaez added the bug Something isn't working label Oct 24, 2021
@yjt98765
Copy link
Contributor

yjt98765 commented Nov 4, 2021

I have tried to export this program into OpenQASM3. The result is:

OPENQASM 3;
include "stdgates.inc";
gate rzx(param_0) q_0, q_1 {
  h q_1;
  cx q_0, q_1;
  rz(pi) q_1;
  cx q_0, q_1;
  h q_1;
}
qubit[2] _q;
let q = _q[0] || _q[1];
rzx(pi) q[0], q[1];
rzx(pi/2) q[0], q[1];

There is only one rzx definition. However, the parameter is not used in the body. Therefore, the program is not correct.

@yjt98765
Copy link
Contributor

yjt98765 commented Nov 4, 2021

The problem I mentioned above, i.e., not using parameters in a gate's body, is the same as this example:

                "gate u3(param_0, param_1, param_2) q_0 {",
                "  U(0, 0, pi/2) q_0;",
                "}",
                "gate u1(param_0) q_0 {",
                "  u3(0, 0, pi/2) q_0;",
                "}",
                "gate rz(param_0) q_0 {",
                "  u1(pi/2) q_0;",
                "}",
                "gate sdg q_0 {",
                "  u1(-pi/2) q_0;",
                "}",
                "gate u2(param_0, param_1) q_0 {",
                "  u3(pi/2, 0, pi) q_0;",
                "}",

Therefore, the authors should be aware of this problem. There are probably some documents, issues, pull requests, or code comments that explain the design choices or the difficulties leading to the current status. I have not found them, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants