Qiskit C++ Issue #146: Only Add OpenQASM 3 export support in qiskit-cpp#157
Open
GoiBasia wants to merge 1 commit into
Open
Qiskit C++ Issue #146: Only Add OpenQASM 3 export support in qiskit-cpp#157GoiBasia wants to merge 1 commit into
GoiBasia wants to merge 1 commit into
Conversation
|
|
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
This PR version implements OpenQASM 3 export support entirely within
qiskit-cpp. It adds a dedicatedQiskit::qasm3::dumps(...)exporter, keepsQuantumCircuit::to_qasm3()as a compatibility wrapper, and reuses the existing parameter serialization path to support parameter-aware QASM3 output.No changes to the upstream Qiskit library or its C API are required for this implementation.
Details and comments
Fix
src/qasm3/qasm3_exporter.hppAdds the dedicated QASM 3 exporter and public
Qiskit::qasm3::dumps(...)API. It adds RAII wrappers for C API resources such asQkOpCounts,QkCircuitInstruction, andqk_param_str()strings, and emits parameter declarations before registers and operations.src/circuit/quantumcircuit_def.hppRemoves inline QASM text generation from
QuantumCircuit::to_qasm3()and delegates to the new exporter. It also records parameter-symbol metadata when parameterized gates are added, appended, composed, copied, or recovered throughoperator[].src/circuit/quantumcircuit.hppIncludes the new QASM 3 exporter header so the compatibility
to_qasm3()path can delegate cleanly.src/circuit/parameter.hppTracks local parameter-symbol metadata on C++
Parameterobjects. Symbol names are preserved across copies and parameter operations, including arithmetic and common unary functions, so expressions retain the names needed for QASM declarations.test/test_circuit.cppAdds coverage for parameter-aware QASM export, including direct symbolic parameters, expressions, numeric-only parameters, uppercase
U(...), explicit parameter names, invalid explicit names, parameterizedcompose(...),append(src[0]), and the fail-closed path when default names cannot be recovered.Example Result
A parameterized circuit now exports self-contained OpenQASM 3:
Numeric-only parameters do not emit unnecessary
inputdeclarations:Coverage
The qiskit-cpp tests cover:
U(...)outputQiskit::qasm3::dumps(circuit, names)happy pathQuantumCircuit::to_qasm3()compose(...)append(src[0])Verification
The qiskit-cpp fix was verified with:
The qiskit-cpp test suite passed
3/3.