Skip to content

Conversation

@GiggleLiu
Copy link
Member

Summary

  • Add OpenQASM 2.0 parsing and compilation support
  • Parse OpenQASM files to Yao circuit blocks
  • Compile Yao circuits to OpenQASM format
  • Include standard gate library (qelib1.inc)
  • Add comprehensive tests and documentation

Test plan

  • Unit tests for parsing
  • Unit tests for compilation
  • Documentation with examples

🤖 Generated with Claude Code

GiggleLiu and others added 6 commits January 11, 2026 19:04
- 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]>
Copy link

Copilot AI left a 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.

GiggleLiu and others added 3 commits January 11, 2026 21:48
- 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]>
@GiggleLiu
Copy link
Member Author

@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?

Copy link

Copilot AI left a 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.

@GiggleLiu GiggleLiu requested a review from Roger-luo January 11, 2026 16:13
GiggleLiu and others added 2 commits January 12, 2026 00:16
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]>
@Roger-luo
Copy link
Member

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.

@GiggleLiu
Copy link
Member Author

I agree. QASM is implemented by pirating, seems no easy ways to fix.

GiggleLiu and others added 2 commits January 22, 2026 20:06
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]>
@GiggleLiu
Copy link
Member Author

@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 qasm/parseblock functionality when they explicitly using OpenQASM.

The setup:

  • lib/YaoBlocks/Project.toml: OpenQASM is listed under [weakdeps] and [extensions], not [deps]
  • The implementation lives in lib/YaoBlocks/ext/OpenQASMExt/
  • YaoBlocks.jl only defines stub functions (function qasm end, function parseblock end)
  • No parser dependencies are pulled into the core package

The CI failure has been fixed — the Yao-level test file was missing using OpenQASM to trigger the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants