feat(qasm3): export parameterized circuits in QASM3#147
Open
Roll249 wants to merge 1 commit into
Open
Conversation
…upport Extract the `to_qasm3` implementation into a new `Qasm3Exporter` class (src/circuit/qasm3_exporter.hpp, src/circuit/qasm3_exporter.cpp) so that: 1. The `QuantumCircuit` class no longer needs to know about the textual QASM representation. 2. Parameterized circuits can now be serialized: `qk_param_str` is used to convert each gate parameter, preserving symbolic expressions (e.g. `rx(theta) q[0];`) and numeric values alike. New tests cover: - Symbolic parameter export (`rx(theta)`) - Compound parameter expressions (`rx(1.5 + 2*theta)`) - Numeric parameter export (unchanged behavior) - The `U` gate special-case remains intact Fixes: Qiskit#146 Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors OpenQASM 3.0 export into a dedicated Qasm3Exporter and adds regression tests to ensure symbolic Parameter expressions are serialized correctly (issue #146).
Changes:
- Extracted
QuantumCircuit::to_qasm3implementation into a newQasm3Exporterclass. - Added regression tests for symbolic and numeric parameter serialization in QASM3 output.
- Added release notes documenting parameterized QASM3 export support.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_circuit.cpp | Adds regression tests for symbolic/numeric parameter serialization in to_qasm3. |
| test/CMakeLists.txt | Updates test build to compile the new exporter and modifies include paths. |
| src/circuit/quantumregister.hpp | Adds <memory> include (likely needed after refactor/build changes). |
| src/circuit/classicalregister.hpp | Adds <memory> include (likely needed after refactor/build changes). |
| src/circuit/quantumcircuit_def.hpp | Replaces large inline to_qasm3 body with a declaration and refactor note. |
| src/circuit/qasm3_exporter.hpp | Introduces new exporter API for QASM3 serialization. |
| src/circuit/qasm3_exporter.cpp | Implements Qasm3Exporter and QuantumCircuit::to_qasm3. |
| src/circuit/qasm3_exporter_impl.hpp | Adds inline exporter implementation (currently duplicates .cpp). |
| releasenotes/notes/qasm3-parameterized-export-146.yaml | Documents the new QASM3 parameter export support and refactor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+35
to
+38
| add_executable (test_driver ${source_files} ../src/circuit/qasm3_exporter.cpp) | ||
| # ...include the location of the header file... | ||
| target_include_directories (test_driver PRIVATE ${CMAKE_SOURCE_DIR} nlohmann_json::nlohmann_json ../src deps/qiskit/dist/c/include) | ||
| target_include_directories (test_driver PRIVATE /home/khang/pro-lab/coding-space/skill-quantum/qiskit-cpp-work/qiskit-cpp/src /home/khang/pro-lab/coding-space/skill-quantum/qiskit-cpp-work/qiskit-source/dist/c/include) |
| add_library(common STATIC common.cpp) | ||
| # Actually define the test driver program executable to be built... | ||
| add_executable (test_driver ${source_files}) | ||
| add_executable (test_driver ${source_files} ../src/circuit/qasm3_exporter.cpp) |
| return out.str(); | ||
| } | ||
|
|
||
| inline rust_circuit *Qasm3Exporter::rust_circuit_ptr(void) { |
| out << "include \"stdgates.inc\";" << std::endl; | ||
| } | ||
|
|
||
| inline void Qasm3Exporter::write_gate_definitions(std::stringstream &out) const { |
| } | ||
| } | ||
|
|
||
| inline void Qasm3Exporter::write_instructions(std::stringstream &out) const { |
Comment on lines
+43
to
+45
| inline Qasm3Exporter::Qasm3Exporter(QuantumCircuit *circ) : circ_(circ) {} | ||
|
|
||
| inline std::string Qasm3Exporter::run(void) { |
Comment on lines
+369
to
+371
| for (uint_t i = 0; i < nops; i++) { | ||
| QkCircuitInstruction *op = new QkCircuitInstruction; | ||
| qk_circuit_get_instruction(rust_circuit_ptr(), i, op); |
Comment on lines
+407
to
+408
| qk_circuit_instruction_clear(op); | ||
| } |
Comment on lines
+673
to
+679
| // `2*theta + 1.5` may be canonicalised slightly differently by | ||
| // `qk_param_str`; just check that the symbolic name `theta` is preserved | ||
| // and that we do not fall back to a numeric-only representation. | ||
| if (actual.find("2*theta") == std::string::npos) { | ||
| std::cerr << " to_qasm3_parameter_expression test : missing symbolic '2*theta' in: " << actual << std::endl; | ||
| return EqualityError; | ||
| } |
Member
|
This looks an unsupervised LLM submission... @Roll249 did you verify and refine the LLM output as asked in https://unitaryhack.dev/ai-guide/ ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Refactors QuantumCircuit::to_qasm3 into a standalone Qasm3Exporter class and adds full support for exporting parameterized quantum circuits to OpenQASM 3.0.
Changes
Files changed
Fixes #146
Made with Cursor