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

visitIODeclaration does not support arrayType #474

Open
menna-atlantic opened this issue May 25, 2023 · 3 comments
Open

visitIODeclaration does not support arrayType #474

menna-atlantic opened this issue May 25, 2023 · 3 comments
Labels
bug Reference Parser ANLTR-based Python reference parser

Comments

@menna-atlantic
Copy link

OpenQASM version:

3.0 (0.4.0)

Python version:

3.11

Operating system:

macOS 13.0 (Ventura)

What is the current behavior?

Parsing a OpenQASM string with arrayType inputs raises an error.

Steps to reproduce the problem

Create a new Conda environment

conda install pip
pip install openqasm3
import openqasm3
qasm_str = """
OPENQASM 3.0;
input array[int, 4] n_steps;
"""
openqasm3.parse(qasm_str)

raises error when processing the last line, in openqasm3/parser.py in visitIODeclarationStatement line
type=self.visit(ctx.scalarType())

What is the expected behavior?
OpenQASM grammar definition shows support for arrayTypes https://github.com/openqasm/openqasm/blob/main/source/grammar/qasm3Parser.g4#L96 but visitIODeclaration only visits scalarType() as mentioned above.
This differs from visitClassicalDeclarationStatement where type does include arrayTypes():
type=self.visit(ctx.scalarType() or ctx.arrayType())

Suggested solutions (Optional)
Adding or ctx.arrayType() to the visit call in visitIODeclarationStatement, similar to the statement in visitClassicalDeclarationStatement

@bkavcaduhq
Copy link

how did openqasm apply for angle type?

@menna-atlantic
Copy link
Author

I believe it is handled as one of the scalar types if you look at the parser.py file line 743:
https://github.com/openqasm/openqasm/blob/07b41d01042a35768c4e26a83ce52b97961d0b84/source/openqasm/openqasm3/parser.py#LL743C45-L743C45

@bkavcaduhq
Copy link

angle type represent of phase of quantum state but scalar type represent amplituted of quantum state, i have a confussion about role of angle type if this is handled as scalar type

@jlapeyre jlapeyre added bug Reference Parser ANLTR-based Python reference parser labels Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reference Parser ANLTR-based Python reference parser
Projects
None yet
Development

No branches or pull requests

3 participants