[WIP] Initial Implementation of a Limited QASM3 Exporter in Rust #13666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces and integrates several key modules for a Rust-based quantum computing framework, laying the foundation for exporting circuits in QASM 3.0 format. The modules added are:
1. printer.rs:
• Implements functionality for formatted output generation of AST or other hierarchical structures.
2. symbols.rs:
• Manages a symbol table used for mapping variable names to their corresponding entities.
• Provides helper methods for creating, binding, and looking up symbols with robust error handling.
• Note: This file is directly copied from Qiskit’s OpenQASM 3 parser, as this symbol table is used when loading QASM 3.0 and converting it to quantum circuits. However, this architecture might be overly complex for the current task of QASM 3.0 exporting, and its necessity should be revisited in future iterations.
3. ast.rs:
• Defines the AST structure for representing quantum programs.
• Contains data structures such as nodes, expressions, and declarations that model the core components of quantum circuit descriptions.
4. exporter.rs:
• Implements a builder for generating QASM 3.0 programs.
• Integrates with Python-based tools (via pyo3) to extract circuit data and parameters.
Current Limitations
The current implementation has limited QASM 3.0 output functionality and relies on partial Python integration. The following features are not yet supported:
• Control Flow Constructs: While QASM 3.0 supports control flow, such as loops and conditionals, these are not yet implemented.
• Classical Variables: Handling classical variables is not included in the current architecture.
• Not standard Gates: Generating QASM for not standard gates and mapping them to Qiskit’s standard gates is pending.
These tasks require further discussion to determine whether they should be included in the scope of Qiskit Issue #13145. My recommendation is to address these features after Qiskit PR #13278 is merged, potentially targeting them for the 2.1 release and beyond.
What is Pending
1. Support for:
• Control flow constructs like loops, conditionals, and subroutines.
• Advanced QASM 3.0 features, including classical variable handling and parameterized gates.
• Handling edge cases for non-standard instructions or unique circuit data.
2. Architecture Alignment:
• Finalizing the architecture based on team feedback to ensure long-term scalability.
• Deciding whether the symbol table from symbols.rs should remain part of the architecture or be replaced with a more streamlined solution.
Discussion Points
1. Scope of Qiskit Issue #13145:
• Should the above pending features (control flow, classical variables, custom gates) be addressed as part of this issue, or deferred to subsequent iterations?
• My suggestion is to revisit these features post-merge of Qiskit PR #13278, targeting them for the 2.1 release or later.
2. Testing and Architecture Validation:
• Before implementing test cases, I would like to confirm agreement on the overall architecture and the scope of tasks to ensure alignment with the team’s priorities.