add-mps-concept-encoding: §1, §3-§7 — hierarchical polysemy example, demo, docs - #46
Merged
Merged
Conversation
…demo, docs Lands the rung-1 companion to larql-polysemantic-clusters: a 12-concept two-level hierarchy (3 super-groups × 2 sub-clusters × 2 concepts) prepared as bond-dimension-2 matrix product states via a Ry; CNOT; Ry; CNOT; Ry staircase on a 3-qubit register. The CNOT staircase entangles adjacent qubits, lifting the flat block diagonal of rung 0 into a graded two-level hierarchy. The Gram matrix splits into four ordered tiers — self 1.000 / sub-cluster-mate 0.882 / super-group-sibling [0.47, 0.54] / cross-group [0.12, 0.25] — one tier richer than rung 0. What ships: - examples/larql-polysemantic-hierarchical.q.orca.md — 13 transitions (1 prepare + 12 query call sites), 15 states, 2 parametric actions with three-angle signatures. Leading paragraph documents the angle design, the analytic per-tier band table, an ASCII Gram heatmap, and the polysemy column for |f> = |dog>. Uses measurement_collapse_allowed for the convergent done [final] state. - demos/larql_polysemantic_hierarchical/demo.py — parse + verify → compile (Mermaid + QASM + Qiskit) → 12 independent Qiskit circuits at 1024 shots each → polysemy column print. Prints the analytic Gram matrix as a 4-tier ASCII heatmap, compares empirical vs analytic polysemy, and prints a side-by-side rung-0 (flat) vs rung-1 (hierarchical) comparison. PASSes with max_err 0.0225 < threshold 0.0469 (3 × Monte-Carlo std bound at 1024 shots). - tests/test_examples.py: test_larql_polysemantic_hierarchical_pipeline pins parametric-action signature shape on both prepare_concept and query_concept (3 angle params each), 12 query call sites, qubit[3] q; in QASM, QuantumCircuit(3) plus 39 ry / 26 cx in the Qiskit script, diagonal == 1, and the four off-diagonal tiers with strict sub→super (≥ 0.20) and super→cross (≥ 0.15) separation. - README.md: new "Hierarchical polysemy" sub-heading under Parametric actions linking the example, demo, and back to clusters as the flat-tier variant. Examples table grows the new entry. - CHANGELOG.md: Unreleased / Added bullet describing the new example, demo, and compute_concept_gram_mps helper coverage. - openspec/changes/add-mps-concept-encoding/tasks.md: marks tasks 1.1–1.3, 3.1–3.3, 4.1–4.3, 5.1–5.4, 6.1–6.3, 7.1–7.4 done with measured-result completion notes (per the §5.1 convention from tech-debt-backlog). Verification: - 771 passed, 6 skipped (full pytest) - Ruff clean across touched files - openspec validate add-mps-concept-encoding --strict passes - Demo PASSes locally (max_err 0.0225 < threshold 0.0469) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced May 1, 2026
jascal
added a commit
that referenced
this pull request
May 2, 2026
#49) Bumps version 0.6.0 → 0.7.0 and lands the post-merge documentation sync after PR #46 (`add-mps-concept-encoding`) and PR #48 (`fix-mps-encoding-non-factorizing`). - README: move MPS concept encoding (rung 1) from "Near-term — implementation pending" into "Recently shipped" with PR refs and the cross-coupled-by-sum encoding formula. - CHANGELOG: convert "Unreleased" → "0.7.0 (2026-05-01)"; correct the stale tier values (`super-group-sibling [0.47, 0.54]` → `{0.335, 0.593, 0.753}`, `cross-group [0.12, 0.25]` → `[0.000, 0.178]`) and the encoding (single-bound-param → cross-coupled-by- sum) in the hierarchical-polysemy entry; add Changed entry for the generalized angle parser; add Fixed entry for `fix-mps-encoding-non-factorizing` referencing PR #48 and tech- debt §5.7. - Research doc: link the rung-1 entry in `docs/research/polysemantic-encoding-beyond-product-states.md` to the merged PRs (#46 + #48) and the post-mortem in `add-mps-concept-encoding/design.md`. - OpenSpec: archive `add-mps-concept-encoding` (25/26 — task 4.2 superseded by `fix-mps-encoding-non-factorizing`) and `fix-mps-encoding-non-factorizing` (✓ Complete) under `openspec/changes/archive/2026-05-02-…`. Both updates flow through to `openspec/specs/{compiler,language}/spec.md`. - Tech debt: append §5.8–§5.15 from a post-merge self-review of PR #48 (HIGH: scientific-notation regression in `_split_linear_combination`; MEDIUM: error-message drift, etc.). Note: the demo-smoke step in `verify-examples.yml` is split out of this commit (PAT lacks workflow scope) — to be added via the GitHub UI as a follow-up. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
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
Lands the rung-1 companion to
larql-polysemantic-clusters: a 12-concept two-level hierarchy (3 super-groups × 2 sub-clusters × 2 concepts) prepared as bond-dimension-2 matrix product states via aRy; CNOT; Ry; CNOT; Rystaircase on a 3-qubit register.The CNOT staircase entangles adjacent qubits, lifting the flat block diagonal of rung 0 into a graded two-level hierarchy. The Gram matrix splits into four ordered tiers — self 1.000 / sub-cluster-mate 0.882 / super-group-sibling [0.47, 0.54] / cross-group [0.12, 0.25] — one tier richer than rung 0.
This PR completes the implementation phase of the
add-mps-concept-encodingchange started by #45 (which shipped thecompute_concept_gram_mpshelper in §2). Sections 1, 3, 4, 5, 6, 7 are now landed; only §8 (archive) remains for after merge.What ships
examples/larql-polysemantic-hierarchical.q.orca.md— 15 states, 25 transitions, 2 parametric actions. 13 query/prepare call sites stamped from a single bond-2 MPS template. Leading paragraph documents the angle design, analytic per-tier band table, an ASCII Gram heatmap, and the polysemy column for|f⟩ = |dog⟩. Usesmeasurement_collapse_allowedfor the convergentdone [final]state.demos/larql_polysemantic_hierarchical/demo.py— parse + verify → compile (Mermaid + QASM + Qiskit) → 12 independent Qiskit circuits at 1024 shots each. Prints the analytic Gram matrix as a 4-tier ASCII heatmap, compares empirical vs. analytic polysemy, prints a side-by-side rung-0 vs rung-1 comparison.tests/test_examples.py—test_larql_polysemantic_hierarchical_pipelinepins parametric-action signature shape on bothprepare_conceptandquery_concept(three angle params each), 12 query call sites,qubit[3] q;in QASM,QuantumCircuit(3)plus 39 ry / 26 cx in the Qiskit script, diagonal == 1, and the four off-diagonal tiers with strict sub→super (≥ 0.20) and super→cross (≥ 0.15) separation.README.md— new "Hierarchical polysemy" sub-heading under "Parametric actions" linking the example, demo, and back tolarql-polysemantic-clustersas the flat-tier variant. Examples table grows the new entry.CHANGELOG.md— Unreleased / Added bullet covering the new example, demo, andcompute_concept_gram_mpshelper coverage.openspec/changes/add-mps-concept-encoding/tasks.md— marks tasks 1.1–1.3, 3.1–3.3, 4.1–4.3, 5.1–5.4, 6.1–6.3, 7.1–7.4 done with measured-result completion notes (per the §5.1 convention fromtech-debt-backlog).Test plan
pytest— 771 passed, 6 skipped (full suite, including the new pipeline test)openspec validate add-mps-concept-encoding --strictpasses🤖 Generated with Claude Code