Skip to content

Build deterministic BLOCH state-space lab - #1

Merged
EmergentMonk merged 2 commits into
mainfrom
agent/build-bloch-state-space-lab
Jul 30, 2026
Merged

EmergentMonk merged 2 commits into
mainfrom
agent/build-bloch-state-space-lab

Conversation

@EmergentMonk

@EmergentMonk EmergentMonk commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

What changed

  • Builds a dependency-free, offline file:// BLOCH state-space laboratory.
  • Maps Bloch-sphere samples onto an octahedral 2D grid and deterministic LUT.
  • Records integer-only, SHA-256 hash-chained frames with exact replay and BLSF export.
  • Implements fixed parallel transport, contraction to the moving reference manifold, and geodesic extrapolation.
  • Imports local CSV/JSON trajectories and commits the source digest into replay state.
  • Adds dual-window Forman curvature, spectral moments, and relative Berry-holonomy diagnostics.
  • Adds deterministic stereo PCM sonification with a machine-readable receipt.
  • Includes GitHub Pages deployment, verification workflows, fixtures, model documentation, and a rendered preview.

Why

This implements the workflow described by 罔 rō'nin (@theronin42):

Bloch sphere → 2D grid → LUT → time-indexed state space → replay → extrapolation

The implementation makes the critical distinction explicit: the natural zero is the tangent deviation e = 0 around a moving reference trajectory; it is not the fixed Bloch north-pole state |0⟩.

Model boundary

This is a deterministic classical state-space model and visualization instrument. It does not claim quantum-hardware control, physical qubit error correction, a fault-tolerance threshold, or experimental validation. The recovery rule is fixed; there is no syndrome decoder, training, adaptive tuning, or hidden network dependency.

Validation

  • npm test — 18/18 deterministic core and format tests pass
  • npm run check — JavaScript syntax checks pass
  • git diff --check — clean
  • Offline/static contract scan — pass
  • DOM/canvas application smoke test — pass
  • Workflow YAML parse — pass
  • Preview SVG parse and render — pass

Summary by Sourcery

Introduce a deterministic offline Bloch-sphere laboratory with octahedral LUT mapping, encoded state-space frames, replay/extrapolation, geometry diagnostics, sonification, and GitHub Pages deployment.

New Features:

  • Provide an offline browser-based Bloch-sphere state-space lab with interactive controls and multiple visualization panels.
  • Support octahedral sphere-to-grid mapping with generated LUTs and import/export of trajectory, LUT, binary and audio artifacts.
  • Implement deterministic recording, replay and verification of encoded Bloch-frame chains, including a fixed restitution profile and scenarios.
  • Add trajectory sonification to produce deterministic stereo PCM WAV output with an accompanying audio receipt.

Enhancements:

  • Define a mathematical and determinism contract for the BLOCH engine, frame format and geometry witnesses.
  • Add dual-window geometry diagnostics (Forman curvature, spectral moments, relative holonomy) around recorded trajectories.
  • Introduce a compact 64-byte binary state-frame format (BLSF) for efficient offline analysis.
  • Provide browser and Node-based test suites plus static offline/runtime contract checks to ensure determinism and no network dependencies.

Build:

  • Add minimal Node-based tooling via package.json to run syntax checks and deterministic test suites without external dependencies.

CI:

  • Introduce GitHub Actions workflows for verification (syntax, tests) and GitHub Pages deployment of the static lab.

Deployment:

  • Configure GitHub Pages to publish the static BLOCH lab directly from the repository contents.

Documentation:

  • Rewrite README with conceptual overview, usage, model boundaries, determinism and claim boundaries, and project structure.
  • Add detailed MODEL and BLSF documentation describing the mathematical model, replay contract, and binary frame format.
  • Document notices and lineage, browser test harness, and citation metadata for the project.

Tests:

  • Add Node core tests for hashing, octahedral mapping, manifold dynamics, replay, geometry witnesses, import/export, and audio determinism.
  • Add browser-based known-answer tests and static offline contract tests to verify runtime constraints and determinism guarantees.

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements a deterministic, offline Bloch-sphere laboratory that maps Bloch vectors to an octahedral grid and LUT, records hash-chained state-space frames, provides replay/geometry/audio tooling, and packages the lab for GitHub Pages with tests and documentation.

Sequence diagram for deterministic recording, verification and sonification

sequenceDiagram
  actor User
  participant App
  participant Recorder
  participant BlochCore
  participant BlochVisuals
  participant BlochAudio
  participant BlochHash

  User->>App: click STEP
  App->>Recorder: step()
  Recorder->>Recorder: recordCurrent(flagsByPoint)
  Recorder->>BlochHash: domainHash(DOMAINS.frame,core)
  Recorder-->>App: latestFrames()
  App->>BlochVisuals: drawLut(lutCanvas,recorder)
  App->>BlochVisuals: drawStateSpace(stateCanvas,recorder)
  App->>BlochVisuals: SphereView.render(recorder)

  User->>App: click VERIFY
  App->>Recorder: exportDocument(currentFormanMode)
  App->>BlochCore: verifyDocument(document)
  BlochCore-->>App: {ok,headHash}
  App->>BlochCore: replayDocument(document,formanMode)
  BlochCore-->>App: {ok,recorder,document}

  User->>App: click LISTEN
  App->>BlochAudio: renderRecording(recorder.frames,options)
  BlochAudio->>BlochHash: sha256Hex(wav)
  BlochAudio-->>App: {wav,receipt}
Loading

File-Level Changes

Change Details Files
Introduce deterministic Bloch core engine with manifold profile, LUT/grid encoding, frame recording, replay, geometry witnesses, and binary export.
  • Define core math utilities for vectors, tangent transport, exponential/log maps, and octahedral sphere encoding/decoding.
  • Implement fixed RONIN-ZERO manifold profile, scenario generator, and deterministic impulse/contraction dynamics around a moving reference trajectory.
  • Add Recorder class to normalize config, step scenarios/imported trajectories, encode frames with SHA-256 chaining, build geometry bundles (Forman, spectral, holonomy), and export/verify/replay recordings.
  • Provide LUT builder and document generator, BLSF 64-byte binary encoder, and frame/document verification helpers.
js/bloch-core.js
docs/MODEL.md
docs/BLSF.md
fixtures/ronin-zero-profile.json
fixtures/sample-trajectory.csv
Add browser application shell, visuals, audio synthesis, and offline UX to operate the lab via file:// with no dependencies.
  • Create index.html layout with control surface, multiple canvas views (sphere, LUT, state-space, surface, contour), geometry/inspector/export panes, and claim/determinism boundaries.
  • Implement visuals.js for canvas rendering of Bloch sphere, octahedral grid, state-space heatmap, restoration surface, and error contours including interaction (drag/zoom).
  • Implement app.js to wire DOM controls to BlochCore, manage play/step/perturb/import/export, drive animation loop, and keep metrics/geometry/inspector/frame-table in sync.
  • Add bloch-audio.js for deterministic trajectory sonification, WAV encoding, and machine-readable audio receipt with hash-bound provenance.
  • Define style.css for dark, “industrial” responsive layout covering all panels and views.
index.html
js/visuals.js
js/app.js
js/bloch-audio.js
style.css
assets/bloch-state-space-preview.svg
Provide strict canonical hashing, offline/static guarantees, Node/browser test suites, and GitHub Pages + verification workflows.
  • Implement hash.js with canonical safe-integer JSON, domain-separated SHA-256, and text encoding utilities used across the engine.
  • Add Node core/static tests covering hashing, oct encoding/LUT, manifold dynamics, replay/verification, BLSF, geometry witnesses, import handling, and audio determinism.
  • Add browser known-answer tests page that loads the classic scripts via file:// and asserts key invariants (hash, oct map, contraction, replay, audio).
  • Add static.test.js to enforce offline constraints (no fetch/network/service workers, no dependencies) and script-load order.
  • Configure package.json scripts (npm test/check) and GitHub Actions workflows for verify and Pages deployment; add .nojekyll and ancillary files.
  • Expand README with high-level model description, workflow diagram, capabilities, boundaries, project structure, attribution, and offline usage instructions.
js/hash.js
tests/core.test.js
tests/static.test.js
tests/browser-tests.js
tests/index.html
.github/workflows/verify.yml
.github/workflows/pages.yml
package.json
.nojekyll
README.md
NOTICE.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@EmergentMonk
EmergentMonk marked this pull request as ready for review July 30, 2026 06:12

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @EmergentMonk, your pull request is larger than the review limit of 150000 diff characters

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a dependency-free, offline (file://) BLOCH “state-space lab” that deterministically maps Bloch-sphere trajectories onto an octahedral 2D grid/LUT, records hash-chained integer frames with exact replay/export, and adds geometry + audio diagnostics, docs, tests, and GitHub Pages deployment.

Changes:

  • Add deterministic core engine (octahedral mapping, LUT generation, recorder/frame hashing, replay/verification, geometry witnesses, binary BLSF export).
  • Add offline browser UI + deterministic WAV sonification/export and static “no network” contract checks.
  • Add documentation, fixtures, CI verification workflow, and Pages deployment workflow.

Reviewed changes

Copilot reviewed 22 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/static.test.js Static offline/runtime contract checks (no network APIs/assets, script order, SPDX, no deps).
tests/index.html Browser harness page for known-answer tests.
tests/core.test.js Node deterministic tests covering hashing, mapping, replay, binary ABI, geometry, audio determinism.
tests/browser-tests.js In-browser known-answer tests runner and results rendering.
style.css Full offline UI styling for the lab.
README.md Expanded documentation: purpose, boundaries, usage, exports, determinism and claim limits.
package.json Minimal Node scripts for syntax checking and tests; no dependencies.
NOTICE.md Attribution and lineage notes.
js/visuals.js Canvas renderers for sphere/LUT/state/mesh/contours.
js/hash.js Canonical safe-integer JSON + synchronous SHA-256 and domain hashing.
js/bloch-core.js Deterministic engine: mapping/LUT, manifold dynamics, frame hashing, replay, geometry witnesses, BLSF encoding.
js/bloch-audio.js Deterministic trajectory sonification, WAV encoding, audio receipts.
js/app.js Browser controller/UI wiring, import/export, playback, verification, audio rendering.
index.html Offline lab shell (controls + panels) with classic script loading order.
fixtures/sample-trajectory.csv Example import dataset for local CSV ingestion.
fixtures/ronin-zero-profile.json Pinned profile fixture used by tests to lock parameters.
docs/MODEL.md Mathematical + replay/determinism contract documentation.
docs/BLSF.md Binary frame format specification.
CITATION.cff Citation metadata for research use.
assets/bloch-state-space-preview.svg Rendered preview asset for README/Pages.
.nojekyll Pages configuration helper.
.gitignore Ignore exported artifacts and node_modules/.
.github/workflows/verify.yml CI: syntax checks + deterministic tests.
.github/workflows/pages.yml CI: verify then deploy static site to GitHub Pages.
Comments suppressed due to low confidence (1)

js/bloch-core.js:1072

  • verifyDocument() calls Hash.domainHash() directly. If the input document contains non-canonical values (e.g., floats, NaN, or other unsupported types), domainHash() will throw and bubble out of verifyDocument(). Since this API otherwise returns { ok, reason } objects, the throw is an inconsistent failure mode and can crash non-UI callers.
    const core = Object.assign({}, document);
    const supplied = core.recordingSha256;
    delete core.recordingSha256;
    const expected = Hash.domainHash(DOMAINS.recording, core);
    if (supplied !== expected) return { ok: false, reason: "recording-hash" };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread js/bloch-core.js Outdated
Comment on lines +171 to +175
const to = normalize(point);
const angle = angleBetween(from, to);
if (angle < 1e-15) return [0, 0, 0];
const direction = subtract(to, scale(from, dot(from, to)));
return scale(normalize(direction, cross(from, [0, 0, 1])), angle);
Comment thread js/bloch-core.js Outdated
Comment on lines +837 to +841
const core = Object.assign({}, frame);
const supplied = core.frameSha256;
delete core.frameSha256;
const expected = Hash.domainHash(DOMAINS.frame, core);
if (supplied !== expected) {

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 432c77c390

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread js/bloch-core.js Outdated
Comment on lines +900 to +902
|| this.config.importedSamples.find(function (sample) {
return sample.point === point;
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject imported points without an initial sample

When a point's first imported row occurs after sequence 0, this fallback selects that future sample and records it as the point's sequence-0 state. Since the importer permits such sparse datasets, this silently moves observations backward in time and changes forecasts, geometry, and hashes; require an initial sample for every point or define non-fabricating pre-sample behavior instead.

Useful? React with 👍 / 👎.

Comment thread js/app.js
Comment on lines +334 to +335
recorder = result.recorder;
byId("scenario").value = recorder.config.scenario;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the imported Forman mode

When the imported recording's Forman mode differs from the dropdown's current value, replay correctly validates using the artifact's mode, but this control-sync block never updates forman-mode. The next render recomputes and displays geometry using the stale selection, and subsequent export or verification produces a different receipt, so the UI no longer represents the recording it just reported as imported successfully.

Useful? React with 👍 / 👎.

Comment thread js/app.js Outdated
});
byId("forman-mode").addEventListener("change", function () {
dirty = true;
setStatus("GEOMETRY PROFILE CHANGED · recording identity unchanged", "neutral");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report that Forman mode changes recording identity

Changing this selector leaves the frame-chain head unchanged, but it does change the recording identity: exportDocument() commits the mode-specific geometry bundle before computing recordingSha256. The current status therefore gives users incorrect provenance information whenever they switch between weighted and unweighted geometry.

Useful? React with 👍 / 👎.

Comment on lines +27 to +28
- name: Verify static lab
run: npm test

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate Pages deployment on the syntax checks

In the Pages workflow, deploy depends only on this job, but npm test merely reads js/visuals.js and js/app.js as text and never parses them. A syntax error in either browser file can therefore pass this gate and be deployed; the separate verify.yml workflow runs independently and cannot prevent this deployment, so this job should also run npm run check.

Useful? React with 👍 / 👎.

Comment thread js/visuals.js Outdated
Comment on lines +149 to +153
const target = projected.z >= 0 ? front : back;
if (previous && previous.front !== (projected.z >= 0)) {
target.push([projected.x, projected.y]);
}
target.push([projected.x, projected.y]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split wireframe curves into separate visible segments

Whenever a closed latitude or longitude crosses the front/back depth boundary, the hemisphere containing the sampling start is represented by two disjoint runs. Appending both runs to one front or back array makes line() connect them with a straight chord across the intervening hemisphere, so the Bloch sphere wireframe displays spurious lines; retain separate subpaths at each depth transition instead.

Useful? React with 👍 / 👎.

Comment thread js/app.js
Comment on lines +197 to +199
if (dirty) renderAll();
else sphere.render(recorder);
globalThis.requestAnimationFrame(animation);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop rendering the sphere continuously while idle

Once dirty becomes false, the application still redraws the full high-DPI sphere, wireframe, and trajectory on every animation frame, including while playback is paused and no pointer interaction is occurring. This causes continuous CPU/GPU use from the moment the page opens; redraw only when recorder or view state changes, with pointer and wheel handlers marking the sphere dirty.

Useful? React with 👍 / 👎.

Comment thread js/bloch-audio.js Outdated
const sampleRate = [22050, 44100, 48000].indexOf(Number(options.sampleRate)) >= 0
? Number(options.sampleRate)
: 44100;
const groups = sequenceGroups(frames).slice(-512);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the full trajectory in audio exports

For recordings longer than 512 sequences, this unconditional slice silently discards every earlier sequence and sonifies only the tail, even though the WAV feature is presented as an export of the recorded trajectory and the receipt commits the full source frame count and head. Long experiments therefore produce an incomplete audio artifact without an explicit range selection; render all sequences or make the truncation and rendered source range explicit.

Useful? React with 👍 / 👎.

@EmergentMonk
EmergentMonk merged commit 907c723 into main Jul 30, 2026
3 checks passed
@EmergentMonk
EmergentMonk deleted the agent/build-bloch-state-space-lab branch July 30, 2026 06:53
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