Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Incorrect Numeric Expression Syntax in QASM Export

Open p51lee opened this issue 10 months ago • 2 comments

Description of the issue

image

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

p51lee avatar Apr 05 '24 05:04 p51lee

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?

verult avatar Apr 24 '24 17:04 verult

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?

p51lee avatar Apr 25 '24 06:04 p51lee