Polygram is a researcher-friendly Python frontend for mechanistic-interpretability experiments on hierarchical polysemantic feature dictionaries in LLMs. It explores several ways of modelling polysemantic representations — quantum- inspired MPS/HEA encodings (with phase-interference and cancellation primitives), behavioural validation against real models, and a compression / regrow loop over SAE checkpoints — so quantum interference is one technique among several, not the headline.
For the quantum-inspired encodings it emits verifiable
Q-Orca .q.orca.md machines; it does
not define a new file format and uses Q-Orca for verification, simulation,
and the analytic Gram helper.
All non-trivial work lands through OpenSpec changes in openspec/changes/.
The v0 milestone is staged as four changes:
bootstrap-package— pyproject, smoke test, CI, this file. Process-only.core-dictionary-mpsrung1—Feature,Dictionary,MPSRung1,Dictionary.gram().experiment-interference-sweep—Experiment,InterferenceSweep,polygram.emit.write_qorca, built-in assertions.animals-example— worked example + integration test that closes v0.
Each change has proposal.md (why + scope), tasks.md (checklist), and
specs/<capability>/spec.md (delta requirements + scenarios). Validate with
openspec validate <change-name> before working on it; archive via
openspec archive when done.
- Pinned at
q-orca>=0.9.0— the first PyPI release with first-class rung-2 HEA encoding (## encoding+## thetagrammar, optionalclustercolumn) and the declarativeconcept_gram_tier_separationinvariant enforced at Stage 4b (HEA_TIER_INVARIANT_VIOLATED/HEA_TIER_UNDEFINED/HEA_TIER_INVARIANT_NOT_APPLICABLE). - Treat
q_orca.compiler.concept_gram_mps.compute_concept_gram_mpsas a stable API surface. Always call it withform="preparation"— the inverse-formRzsymmetry break documented in q-orca-lang'sexamples/larql-animals-interference.q.orca.mdis a hard error (MpsGramConfigurationError(kind="rz_in_inverse_form")), but stay on the preparation form regardless. - For HEA dictionaries, the stable surface is
q_orca.compiler.concept_gram_hea.compute_concept_gram_heaplus thecompute_tier_separationanalysis helper. Both are part of v0.9.0's public API. - Q-Orca is not vendored. If you need a fix in Q-Orca, open it there.
polygram/ Python package
__init__.py version + (later) public re-exports
dictionary.py Feature, Dictionary (added in change 2)
encoding.py MPSRung1 (added in change 2)
experiment.py Experiment, InterferenceSweep (added in change 3)
emit.py write_qorca (added in change 3)
_qorca_emit.py internal QMachineDef builder (added in change 2)
_assertions.py built-in assertion checkers (added in change 3)
tests/ pytest suite (mirrors package layout)
examples/ worked examples (added in change 4)
openspec/ spec-driven changes + capability specs
.github/workflows/ CI
pip install -e ".[dev]"
pytest
ruff check polygram tests- Only the
numpyandq-orcaruntime deps. Plotting and Jupyter are optional extras. - Generated
.q.orca.mdfiles include a header comment block with the source Polygram dictionary name, a timestamp, and the git rev (orunversioned). - No emojis in code or generated artifacts.
- Default to no comments unless the why is non-obvious.