Implement add-classical-context-updates (grammar + verifier + compiler) - #21
Merged
Conversation
Ships the language/AST/verifier/compiler facets of classical context updates — the one primitive the QPC research proposal called out as missing. Grammar is: <effect> ::= <mutation> | if bits[i] == v: <mut_seq> [else: <mut_seq>] <mutation> ::= <ident>[<int>]? (= | += | -=) (<literal> | <ident>) Shot-to-shot runtime execution of the mutation remains out of scope — compilers emit annotations and a banner flagging the no-op, per the spec. - AST: QContextMutation, QEffectContextUpdate, context_update field on QActionSignature. - Parser: _parse_context_update_from_effect + mixed-effect rejection + nested-conditional rejection. - Verifier: new classical_context stage wired between determinism and quantum-static; enforces UNDECLARED_CONTEXT_FIELD, CONTEXT_FIELD_TYPE_MISMATCH, CONTEXT_INDEX_OUT_OF_RANGE, and BIT_READ_BEFORE_WRITE via acyclic-path enumeration from initial. VerifyOptions.skip_classical_context added. - Compiler: QASM and Qiskit emit `// context_update: ...` / `# context_update: ...` at the action site plus a file-level banner when any context-update is present. Mermaid unchanged. - Tests: tests/test_context_updates.py (23 cases across parser, verifier, and compiler); full suite 468 passed, 5 skipped; all 10 examples still verify. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jascal
added a commit
that referenced
this pull request
Apr 20, 2026
Rolling collection point for small items that surface during code review and QA but aren't worth their own proposal. Seeded with two low-severity observations from Hermes QA on PR #21: - parser: rename `_has_trailing_mutation` to match what it detects - verifier: audit CUDA-Q backend severity/valid consistency The backlog is intentionally long-lived and has no specs deltas (so `openspec validate --strict` will fail on it, by design). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
jascal
added a commit
that referenced
this pull request
Apr 20, 2026
Rolling collection point for small items that surface during code review and QA but aren't worth their own proposal. Seeded with two low-severity observations from Hermes QA on PR #21: - parser: rename `_has_trailing_mutation` to match what it detects - verifier: audit CUDA-Q backend severity/valid consistency The backlog is intentionally long-lived and has no specs deltas (so `openspec validate --strict` will fail on it, by design). Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
jascal
added a commit
that referenced
this pull request
Apr 22, 2026
Both shipped earlier but were never moved out of the active changes folder. Relocate to match the archive pattern: - add-classical-context-updates → archive/2026-04-20-... (PR #21) - harden-completeness-detection → archive/2026-04-19-... (PR #18) Pure folder rename; no code impact. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
jascal
added a commit
that referenced
this pull request
Apr 22, 2026
* Archive run-context-updates proposal Shipped in PR #24 (6c5dbfa). Move the folder from active to `openspec/changes/archive/2026-04-21-run-context-updates/` to match the pattern of previously shipped proposals, and update the design-doc breadcrumb in `runtime/iterative.py` to the new path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Archive add-classical-context-updates and harden-completeness-detection Both shipped earlier but were never moved out of the active changes folder. Relocate to match the archive pattern: - add-classical-context-updates → archive/2026-04-20-... (PR #21) - harden-completeness-detection → archive/2026-04-19-... (PR #18) Pure folder rename; no code impact. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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
Implements the
add-classical-context-updatesOpenSpec change (proposal landed in #19). Ships the language/AST/verifier/compiler facets of classical context-update effects — the primitive the QPC research proposal flagged as the one missing piece. Does not ship shot-to-shot runtime execution; that's parked for a follow-up change (run-context-updates).New grammar in the Effect column of
## actions:Example:
if bits[0] == 1: theta[0] -= eta else: theta[0] += eta.What changed
q_orca/ast.py):QContextMutation,QEffectContextUpdate,context_updatefield onQActionSignature.q_orca/parser/markdown_parser.py):_parse_context_update_from_effect+ mixed-effect rejection (H(qs[0]); iteration += 1) + nested-conditional rejection.q_orca/verifier/classical_context.py, new): stage runs between determinism and quantum-static. EnforcesUNDECLARED_CONTEXT_FIELD,CONTEXT_FIELD_TYPE_MISMATCH,CONTEXT_INDEX_OUT_OF_RANGE, andBIT_READ_BEFORE_WRITEvia acyclic-path enumeration from initial. AddsVerifyOptions.skip_classical_context.// context_update: .../# context_update: ...at the action site and a file-level banner when any context-update is present. Mermaid unchanged (transition label is the action name, as for any action).tests/test_context_updates.py, 23 cases): parser forms & error modes, verifier error codes & happy path, compiler emission & banner gating.Test plan
.venv/bin/python -m pytest tests/ -q --ignore=tests/test_cuquantum_backend.py --ignore=tests/test_cudaq_backend.py— 468 passed, 5 skipped.venv/bin/q-orca verifyon all 10examples/*.q.orca.md— all VALID, none regressopenspec validate add-classical-context-updates --strict— validCo-Authored-By: Claude Opus 4.7 noreply@anthropic.com