Skip to content

Add pluggable execution backends (qutip, cuquantum, cudaq) - #7

Merged
jascal merged 9 commits into
mainfrom
execution-backends
Apr 16, 2026
Merged

Add pluggable execution backends (qutip, cuquantum, cudaq)#7
jascal merged 9 commits into
mainfrom
execution-backends

Conversation

@jascal

@jascal jascal commented Apr 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • New q_orca/backends/ packageBackendAdapter ABC, BackendResult dataclass, BackendUnavailableError, and BackendRegistry with graceful fallback (requests unavailable backend → falls back to QuTiP + emits BACKEND_UNAVAILABLE warning)
  • Three backend adapters: qutip_backend (delegates to existing dynamic_verify()), cuquantum_backend (stub, AVAILABLE=False in CI, fallback-safe), cudaq_backend (stub, same pattern)
  • New CUDA-Q compilerq_orca/compiler/cudaq.py::compile_to_cudaq() emits @cudaq.kernel scripts; gate mapping: H→cudaq.h, CNOT→cudaq.x.ctrl, X/Y/Z, Rx/Ry/Rz, measure→mz
  • Verifier wired to registryVerifyOptions.backend = "qutip" routes Stage 4b through BackendRegistry.get_with_fallback()
  • CLI extended--backend, --gpu-count, --tensor-network, --cudaq-target flags on verify and simulate; compile cudaq format target added
  • JSON outputverify --json and simulate --run --json now include a "backend": {"name": ..., "version": ...} block
  • ConfigOrcaConfig gains backend, cuquantum, cudaq fields; _resolve_backend() merges CLI flag over orca.yaml
  • 19 new tests — registry fallback logic, BACKEND_UNAVAILABLE warning, BackendResult fields, CUDA-Q kernel structure/syntax, CLI integration

Test plan

  • pytest tests/test_backends.py — 19 tests pass
  • Full suite pytest — 375 passed, 0 failed, 1 skipped (after lint fixes)
  • cuquantum and cudaq stubs confirmed unavailable in CI; fallback path exercised by tests
  • q-orca compile cudaq examples/bell-entangler.q.orca.md — emits correct @cudaq.kernel with cudaq.h and cudaq.x.ctrl
  • q-orca verify examples/bell-entangler.q.orca.md --backend cudaq — verified working on macOS Apple Silicon with cudaq==0.14.0 + matplotlib

Note: cuquantum requires Linux + NVIDIA GPU. cudaq (pip install cudaq matplotlib) works on macOS Apple Silicon via CPU simulation.

🤖 Generated with Claude Code

Allan Scott and others added 9 commits April 16, 2026 05:13
Implements the execution-backends OpenSpec change:
- New `q_orca/backends/` package with `BackendAdapter` ABC, `BackendResult`,
  `BackendUnavailableError`, and `BackendRegistry` with graceful fallback logic
- `qutip_backend.py`: delegates to existing `dynamic_verify()`
- `cuquantum_backend.py`: stub adapter (AVAILABLE=False in CI), raises
  `BackendUnavailableError` so registry falls back to QuTiP with warning
- `cudaq_backend.py`: stub adapter for CUDA-Q, same fallback pattern
- `q_orca/compiler/cudaq.py`: `compile_to_cudaq()` emitting `@cudaq.kernel`
  scripts with H→`cudaq.h`, CNOT→`cudaq.x.ctrl`, X/Y/Z, Rx/Ry/Rz gate mapping
- `VerifyOptions.backend` field routes Stage 4b through the registry
- CLI gains `--backend`, `--gpu-count`, `--tensor-network`, `--cudaq-target`
  flags on `verify` and `simulate`; `compile cudaq` format target added
- JSON output for `verify` and `simulate` now includes a `backend` block
- `OrcaConfig` gains `backend`, `cuquantum`, `cudaq` fields; `_resolve_backend()`
  merges CLI flag over `orca.yaml` config value
- 19 new tests covering registry fallback, BACKEND_UNAVAILABLE warnings,
  CUDA-Q kernel structure, and CLI integration; 371 tests pass, 0 failures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove unused Optional/Type from registry.py, Any/Dict from cudaq.py,
Optional from config/types.py, and unused dynamic_verify/BackendResult
imports from verifier/__init__.py — all flagged by ruff F401 in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename ambiguous loop variable l → ln (E741) in test files
- Remove unused variables: error_codes, result, slots_needed, bred_any (F841)
- 27 further issues were auto-fixed (F541 f-strings, unused imports)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add --backend, --gpu-count, --tensor-network to CLI flags table
- Add Verification Backends section with backend comparison table
- Add backends/ and compiler/cudaq.py to file tree
- Mark pluggable backends as shipped in roadmap

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- CUDA-Q: pip install cuda-quantum, works on macOS Apple Silicon via qpp-cpu target
- cuQuantum: Linux + NVIDIA GPU only, not supported on macOS
- Add platform column to backends table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add 'Verify the installation' smoke test under Install
- Add 'Optional backends' install block with cudaq and cuquantum commands
- Remove duplicate install subsections from Verification Backends section
- Replace with a link back to Install

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The correct PyPI package name on macOS Apple Silicon is 'cudaq',
not 'cuda-quantum'. Update README and backend error message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cudaq fails to import if matplotlib is absent. Update install
instructions and backend unavailable error message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jascal
jascal merged commit 8cc65fc into main Apr 16, 2026
6 checks passed
jascal pushed a commit that referenced this pull request Apr 16, 2026
PR #7 (8cc65fc) shipped the implementation of the pluggable execution
backends change but only committed tasks.md. The supporting OpenSpec
artifacts (proposal, design, five spec deltas, .openspec.yaml) and the
raw feature spec under docs/specs/ were left orphaned on a local
machine and never committed.

This commit brings them into the repo so the change is fully documented
and archivable. No code changes — documentation backfill only.

Artifacts:
- openspec/changes/execution-backends/.openspec.yaml
- openspec/changes/execution-backends/proposal.md
- openspec/changes/execution-backends/design.md
- openspec/changes/execution-backends/specs/backend-selection/spec.md
- openspec/changes/execution-backends/specs/cuquantum-backend/spec.md
- openspec/changes/execution-backends/specs/cudaq-backend/spec.md
- openspec/changes/execution-backends/specs/verifier/spec.md
- openspec/changes/execution-backends/specs/compiler/spec.md
- docs/specs/spec-execution-backends.md

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jascal
jascal deleted the execution-backends branch April 17, 2026 14:11
jascal pushed a commit that referenced this pull request Apr 17, 2026
Brings `docs/specs/spec-execution-backends.md` into the repo. The
pre-OpenSpec-era feature spec for PR #7 was orphaned on a local
machine and never committed alongside the implementation. Everything
else that was missing (proposal, design, capability specs) already
landed in `openspec/changes/archive/2026-04-17-execution-backends/`
when the nightly archived the change, so this is the last piece.

Docs-only. No code changes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jascal added a commit that referenced this pull request Apr 17, 2026
Brings `docs/specs/spec-execution-backends.md` into the repo. The
pre-OpenSpec-era feature spec for PR #7 was orphaned on a local
machine and never committed alongside the implementation. Everything
else that was missing (proposal, design, capability specs) already
landed in `openspec/changes/archive/2026-04-17-execution-backends/`
when the nightly archived the change, so this is the last piece.

Docs-only. No code changes.

Co-authored-by: Allan Scott <allans@Allans-Mac-mini.lan>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant