quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Incorrect Numeric Expression Syntax in QASM Export #6550

Open p51lee opened 5 months ago

p51lee commented 5 months ago

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

verult commented 5 months ago

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?

p51lee commented 5 months ago

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?