Skip to content

add native QIR emitter and parser (LLVM IR, zero dependencies)#32

Merged
splch merged 2 commits intomainfrom
feature/qir-support
Mar 19, 2026
Merged

add native QIR emitter and parser (LLVM IR, zero dependencies)#32
splch merged 2 commits intomainfrom
feature/qir-support

Conversation

@splch
Copy link
Copy Markdown
Owner

@splch splch commented Mar 19, 2026

Introduce qir/ package with full QIR v2.0 support (opaque pointers, LLVM 16+). The emitter converts goqu circuits to spec-compliant LLVM IR text (.ll files) targeting both Base Profile and Adaptive Profile. The parser reads QIR back into goqu circuits with round-trip fidelity.

  • qir/emitter: Emit/EmitString API, 20+ gate intrinsic mappings, automatic decomposition of non-QIR gates via existing transpile infra, profile auto-detection via circuit.IsDynamic(), full control flow support (if/else, while, for, switch) for Adaptive Profile
  • qir/parser: Parse/ParseString/ParseFile API, line-based LLVM IR extraction, reverse gate mapping with cx/cnot and ccx/ccnot aliases, handles tail call, nonnull, writeonly/readonly attributes
  • qir/token: Token types for the LLVM IR subset lexer
  • Gate names aligned to PyQIR/Azure Quantum conventions (ccx__body, tuple_record_output, s__adj/t__adj)
  • 35 tests including round-trip verification

splch added 2 commits March 19, 2026 13:21
Introduce qir/ package with full QIR v2.0 support (opaque pointers,
LLVM 16+). The emitter converts goqu circuits to spec-compliant LLVM IR
text (.ll files) targeting both Base Profile and Adaptive Profile. The
parser reads QIR back into goqu circuits with round-trip fidelity.

- qir/emitter: Emit/EmitString API, 20+ gate intrinsic mappings,
  automatic decomposition of non-QIR gates via existing transpile infra,
  profile auto-detection via circuit.IsDynamic(), full control flow
  support (if/else, while, for, switch) for Adaptive Profile
- qir/parser: Parse/ParseString/ParseFile API, line-based LLVM IR
  extraction, reverse gate mapping with cx/cnot and ccx/ccnot aliases,
  handles tail call, nonnull, writeonly/readonly attributes
- qir/token: Token types for the LLVM IR subset lexer
- Gate names aligned to PyQIR/Azure Quantum conventions (ccx__body,
  tuple_record_output, s__adj/t__adj)
- 35 tests including round-trip verification
- gofmt: fix formatting in emitter.go, parser/gates.go, token/token.go
- gocritic: rewrite if-else chain to switch in round-trip test
- unparam: remove always-nil error returns from extractOperations
  and extractQubitIndices
- gosec G304: sanitize file path with filepath.Clean in ParseFile
@splch splch merged commit 3f6415b into main Mar 19, 2026
6 checks passed
@splch splch deleted the feature/qir-support branch March 19, 2026 20:33
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 55.02577% with 349 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.46%. Comparing base (ba9101f) to head (f910c58).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
qir/parser/lexer.go 0.00% 165 Missing ⚠️
qir/emitter/emitter.go 67.94% 112 Missing and 13 partials ⚠️
qir/parser/parser.go 79.41% 20 Missing and 15 partials ⚠️
qir/profile.go 0.00% 12 Missing ⚠️
qir/token/token.go 0.00% 8 Missing ⚠️
qir/emitter/gates.go 84.61% 3 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (55.02%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
- Coverage   72.21%   71.46%   -0.75%     
==========================================
  Files         157      165       +8     
  Lines       16715    17491     +776     
==========================================
+ Hits        12070    12500     +430     
- Misses       3718     4036     +318     
- Partials      927      955      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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