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

Incorrect Numeric Expression Syntax in QASM Export #6550

Open
p51lee opened this issue Apr 5, 2024 · 3 comments · May be fixed by #6802
Open

Incorrect Numeric Expression Syntax in QASM Export #6550

p51lee opened this issue Apr 5, 2024 · 3 comments · May be fixed by #6802
Labels
area/interop area/qasm kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@p51lee
Copy link

p51lee commented Apr 5, 2024

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 p51lee added the kind/bug-report Something doesn't seem to work. label Apr 5, 2024
@pavoljuhas pavoljuhas added the triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add label Apr 24, 2024
@verult
Copy link
Collaborator

verult commented Apr 24, 2024

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
Copy link
Author

p51lee commented Apr 25, 2024

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?

@dstrain115
Copy link
Collaborator

It looks like this is not a problem with OpenQASM 3.0, since the specification and grammar changed:

FloatLiteral:
    // 1_123e-3, 123e+4 or 123E5 (needs the exponent or it's just an integer)
    DecimalIntegerLiteral FloatLiteralExponent
    // .1234_5678 or .1e3 (no digits before the dot)
    | DOT DecimalIntegerLiteral FloatLiteralExponent?
    // 123.456, 123. or 145.32e+1_00
    | DecimalIntegerLiteral DOT DecimalIntegerLiteral? FloatLiteralExponent?;

However, I will see if I can fix this anyway, since I am updating openQASM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/interop area/qasm kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

5 participants