-
Notifications
You must be signed in to change notification settings - Fork 129
OpenQASM support #578
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
base: master
Are you sure you want to change the base?
OpenQASM support #578
Conversation
- Remove Base.error, use error() directly in parse.jl - Clarify OpenQASM version compatibility in compile.jl docs - Remove [sources] section from YaoToEinsum/Project.toml
The local variable 'error' was shadowing Base.error(), causing 'UndefVarError: error not defined' when trying to throw an error for unknown noise types.
- Use QASM 2.0 compatible syntax for common controlled gates (cx, cy, cz, ch, cu1, crz, ccx) - Change header to OPENQASM 2.0 and include creg declaration - Fix register name from 'reg' to 'q' to match declaration - Add trailing semicolons to all statements - Handle nested ChainBlocks correctly (avoid duplicate semicolons) - Add roundtrip tests for compile->parse->execute equivalence Tested with EasyBuild circuits: qft_circuit, variational_circuit
Apply Optimise.canonicalize to recursively simplify circuits before compiling to OpenQASM. This ensures nested blocks are eliminated and gates are converted to basic types using simplify's fixed-point iteration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Since canonicalize now flattens nested chains automatically, remove the special handling for nested ChainBlocks in print_qasm. Also update docstring and error message to reflect automatic simplification. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive OpenQASM 2.0 support to YaoBlocks, enabling bidirectional conversion between Yao quantum circuits and the OpenQASM format. This integration allows users to export Yao circuits for use with other quantum computing frameworks (e.g., Qiskit) and import OpenQASM circuits into Yao for simulation.
Changes:
- Added OpenQASM parsing functionality to convert QASM strings/files to YaoBlocks circuits
- Implemented OpenQASM compilation to convert YaoBlocks circuits to QASM format
- Included comprehensive noise model support for noisy quantum simulations
- Added extensive test coverage and user-facing documentation
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/YaoBlocks/src/YaoBlocks.jl |
Integrates OpenQASM module and exports qasm and parseblock functions |
lib/YaoBlocks/Project.toml |
Adds OpenQASM package dependency (version 2) |
lib/YaoBlocks/src/openqasm/openqasm.jl |
Module entry point with comprehensive documentation |
lib/YaoBlocks/src/openqasm/compile.jl |
Implements Yao → QASM conversion with support for all common gates |
lib/YaoBlocks/src/openqasm/parse.jl |
Implements QASM → Yao conversion with noise model support |
lib/YaoBlocks/src/openqasm/assets/qelib1.inc |
Standard OpenQASM gate library from Qiskit |
lib/YaoBlocks/test/runtests.jl |
Adds OpenQASM test suite to test runner |
lib/YaoBlocks/test/openqasm/openqasm.jl |
Test suite entry point |
lib/YaoBlocks/test/openqasm/parse.jl |
Comprehensive parsing tests including noise models |
lib/YaoBlocks/test/openqasm/compile.jl |
Compilation tests with round-trip verification |
docs/src/man/openqasm.md |
Extensive user documentation with examples |
docs/make.jl |
Integrates OpenQASM documentation into docs build |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix doctest: update expected Measure output format - Fix typo: "Buiding" -> "Building" - Remove unused current_qubits field from QASMIOContext - Improve qreg/creg duplicate declaration error messages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Test that qft_circuit and variational_circuit can be converted to QASM and parsed back with functional equivalence (verified via fidelity). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add QASM compiler support for SWAP, rzz, and PhaseGate (ignored) - Add PutBlock with ControlBlock handler for proper qubit remapping - Add to_basictypes for SqrtX, SqrtY, SqrtW gates (decompose to rotations) - Fix raise_chain to preserve nqubits for empty chains - Skip global phase gates in QASM output - Add rand_google53 roundtrip test for 4 and 8 qubits 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add section on automatic circuit simplification (canonicalize) - Add roundtrip verification example with EasyBuild circuits - Expand gate tables with SWAP, rzz, and more controlled gates - Organize gates into categories (single-qubit, two-qubit, modifiers) - Add note about QASM 2.0 vs 3.0 compatibility - Add section on interoperability with Cirq and PennyLane - Add limitations section documenting known constraints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
@Roger-luo This PR made OpenQASM a feasture of YaoBlocks. Round trip tests on variational circuit, qft circuit and google supremacy circuits all pass. Copilot has reviewed this PR. Let me know if you agree this PR can be merged in its current status? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Clarify that SqrtX = exp(iπ/4) * Rx(π/2) and SqrtY = exp(iπ/4) * Ry(π/2), explaining that global phase doesn't affect measurement outcomes or fidelity. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
The control gate printing logic was duplicated between PutBlock{ControlBlock}
and ControlBlock handlers. Extract shared logic into print_control_gate helper.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
can we make this optional? or an extra dependency? I'm concerned this is a bad start of adding a bunch of parser or parser generator dependencies into the core package YaoBlocks. |
|
I agree. QASM is implemented by pirating, seems no easy ways to fix. |
OpenQASM is now a weak dependency that gets activated when users load the OpenQASM package. This addresses the concern about adding parser dependencies to the core YaoBlocks package. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
The OpenQASM support was moved to a package extension, but the test/easybuild/openqasm.jl tests didn't load the OpenQASM package, causing MethodError failures in CI. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
@Roger-luo OpenQASM has been made a package extension (weak dependency) of YaoBlocks — it is not a direct dependency of either YaoBlocks or Yao. Users only get the The setup:
The CI failure has been fixed — the Yao-level test file was missing |
Summary
Test plan
🤖 Generated with Claude Code