tket icon indicating copy to clipboard operation
tket copied to clipboard

Syntax Error in Exported QASM for `rccx` Gate

Open p51lee opened this issue 10 months ago • 5 comments

Overview

Exporting a qasm code that includes an rccx gate using circuit_to_qasm_str function results in a syntax error.

Example and reproduction steps

Consider the following Python code:

from pytket.qasm import circuit_from_qasm_str, circuit_to_qasm_str

qasm = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];

rccx q[0],q[1],q[2];
"""

circuit_tket = circuit_from_qasm_str(qasm)
print(circuit_to_qasm_str(circuit_tket))

Observed

The resulting QASM code contains an unclosed parenthesis:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[3];
creg c[1];
rccx( q[0],q[1],q[2];  // Incorrect syntax

As defined in qelib1.inc, the last line should be rccx q[0],q[1],q[2];.

...
gate rccx a,b,c
{
  u2(0,pi) c;
  u1(pi/4) c;
  cx b, c;
  u1(-pi/4) c;
  cx a, c;
  u1(pi/4) c;
  cx b, c;
  u1(-pi/4) c;
  u2(0,pi) c;
}
...

p51lee avatar Apr 04 '24 18:04 p51lee