Investigate `lark` as an alternative to `antlr4-python3-runtime` in `openqasm3.parser`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The work centers on parser.py in the OpenQASM3 repository, where the current ANTLR-based parser lives, and the target is a Lark grammar covering a small subset of statements and gate definitions. Start by mapping the parser's entry points and how it emits AST nodes, then sketch the Lark grammar and a Transformer. Done means a prototype that yields identical objects and error messages on sample files, plus a written benchmark against the original parser.
由索引模型根据 Issue 内容生成。
描述
Background
The current OpenQASM3 parser is a known performance bottleneck, especially for large or complex QASM files. Rather than a full migration, this issue proposes a focused experiment: fork the repo, implement a Lark-based parser in parser.py for a subset of the grammar, and evaluate feasibility, performance, and compatibility.
Goals
- Evaluate if Lark can serve as a drop-in replacement for the current parser logic.
- Maintain API and object compatibility with existing code.
- Benchmark correctness and performance on OpenQASM3 files.
Proposed Steps
1. Fork and Prepare
- Fork the OpenQASM repository.
- Create a feature branch (e.g.,
lark-parser-prototype).
2. Analyze parser.py
- Identify key functions/classes responsible for:
- Parsing input strings/files
- Emitting AST or domain objects
- Error handling and reporting
3. Develop Lark Grammar
- Extract a minimal but representative subset of the OpenQASM3 grammar (e.g., statements, declarations, a few gate definitions).
- Write the equivalent Lark EBNF grammar.
4. Implement Lark Parser
- In
parser.py, add a new parser class or function using Lark. - Use a
Transformerto convert the Lark parse tree into the same AST or objects as the current parser. - Add a feature flag or environment variable to switch between the old and new parsers for testing.
5. Ensure API Compatibility
- Match all public methods, return types, and error messages to the existing API.
- Write or adapt unit tests to verify that the Lark-based parser produces identical results.
6. Benchmark and Report
- Compare parsing speed and memory usage between the original and Lark-based parser.
- Document any edge cases, limitations, or incompatibilities encountered.
7. Share Findings
- Summarize results in a markdown file or GitHub issue.
- If successful, outline next steps for incremental migration.
- Eventually, we want this change to be merged upstream into
openqasm3if the maintainers are willing. If not, we can merge this as a parser component withinpyqasmitself.
References
- 主要语言
- Python
- 星标
- 29
- 派生
- 33
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qBraid/pyqasm 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
enhancement error-handling program-validation
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py可能已有人在做 @danielgaskins 于 7 天前认领。 未关闭enhancement qasm2
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM可能已有人在做 @Jah-yee 于 15 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost可能已有人在做 @tonycoder-hub 于 9 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 22/100
维护者通常 1 天内回复
相似的 Issue
-
Uninstall guide omits the CloudWatch log groups AWS CodeBuild creates for useCodeBuild pipelines未关闭bug documentation
难度 1/5 1-3 小时 新手友好度 88/100
awslabs/visual-asset-management-system#552 ·
维护者通常 1 天内回复
-
netbox status: needs triage type: documentation
难度 1/5 1 小时以内 新手友好度 76/100
netbox-community/netbox#23460 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
awslabs/threat-composer#362 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
ansys/pyansys-common-mcp#213 ·
维护者通常 3 天内回复