Cirq
Cirq copied to clipboard
Incorrect Numeric Expression Syntax in QASM Export
Description of the issue
The to_qasm
method exports numeric expressions in a format not fully compliant with the OpenQASM 2.0 specification. Expressions like 1e-10
are outputted without a leading digit or dot, which could lead to syntax errors in strict OpenQASM parsers.
How to reproduce the issue
import math
cirq_circuit = cirq.Circuit()
a = cirq.NamedQubit("a")
cirq_circuit.append([cirq.Rz(rads=math.pi * 1e-10)(a)])
print(cirq_circuit.to_qasm())
Result
// Generated from Cirq v1.3.0
OPENQASM 2.0;
include "qelib1.inc";
// Qubits: [a]
qreg q[1];
rz(pi*1e-10) q[0]; // invalid syntax (expected: 1.e-10 or 1.0e-10)
Cirq version 1.3.0
From the Cirq Cync: we're planning to drop support for OpenQASM 2 and move to OpenQASM 3. Does the same issue apply in the new version?
I'm working with the latest version and to_qasm
method gives OpenQASM 2 code. Is there a parameter or a different method available that I should use to obtain OpenQASM 3 code instead?