Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .github/workflows/quantum-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Quantum cluster tests

on:
push:
branches: [main]
paths:
- 'brainsnn-r3f-app/src/utils/quantum*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/bellPair*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/eml*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/nand*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/ghzState*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/solovayKitaev*.{js,mjs}'
- 'brainsnn-r3f-app/package.json'
- 'brainsnn-r3f-app/package-lock.json'
- 'quantum_alignment/**'
- '.github/workflows/quantum-tests.yml'
pull_request:
paths:
- 'brainsnn-r3f-app/src/utils/quantum*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/bellPair*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/eml*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/nand*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/ghzState*.{js,mjs}'
- 'brainsnn-r3f-app/src/utils/solovayKitaev*.{js,mjs}'
- 'brainsnn-r3f-app/package.json'
- 'brainsnn-r3f-app/package-lock.json'
- 'quantum_alignment/**'
- '.github/workflows/quantum-tests.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
js:
name: JS quantum + eml + nand + ghz + sk tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: brainsnn-r3f-app

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: brainsnn-r3f-app/package-lock.json

- name: Install dependencies
run: npm ci || npm install

- name: Run quantum tests (8 test files)
run: npm run test:quantum

- name: Build (smoke check that L101–L108 wire up cleanly)
run: npm run build

python-fast:
name: Python pytest (fast lane, no AerSimulator round-trip)
runs-on: ubuntu-latest
defaults:
run:
working-directory: quantum_alignment

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pinned deps
run: pip install -r requirements.lock

- name: Run pytest (fast lane)
run: python -m pytest -q

python-slow:
name: Python pytest (slow lane — ideal AerSimulator e2e)
runs-on: ubuntu-latest
defaults:
run:
working-directory: quantum_alignment

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pinned deps + jsonschema (for results-schema validation)
run: |
pip install -r requirements.lock
pip install jsonschema

- name: Run pytest (slow + schema validation)
run: python -m pytest -q -m slow && python -m pytest -q test_results_schema.py
81 changes: 80 additions & 1 deletion brainsnn-r3f-app/DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,86 @@ docker build -t brainsnn .
docker run --rm -p 8080:8080 -e PORT=8080 brainsnn
```

## 8. Rollbacks
## 8. brainsnn.com launch checklist (Vault-as-Obsidian-replacement)

The L109 Vault, L110 Graph, and L111 Daily Notes layers turn the app
into a local-first knowledge tool with a cognitive firewall on every
note. Use this checklist for the launch.

### 8a. Domain layout (recommended)

```
brainsnn.com → ui/brainsnn-site (marketing landing, fast SSG)
app.brainsnn.com → brainsnn-r3f-app (this Railway service)
```

Why split: the R3F app is ~1 MB gzipped and slow on first paint; the
landing site at `ui/brainsnn-site` is ~30 KB. First-time visitors land
on a fast page, click "Open the app" → `app.brainsnn.com` for the full
108-layer experience.

To switch from the current single-domain setup:

```bash
# 1. Tell Railway about the new subdomain
railway domain app.brainsnn.com

# 2. At your DNS provider:
# CNAME app <railway-cname-target>

# 3. Re-deploy the marketing site to Pages on the apex
# (ui/brainsnn-site has its own workflow at
# .github/workflows/brainsnn-site-pages.yml)
```

### 8b. Pre-launch smoke test (in addition to §6)

```bash
# Vault data is local, but the wiring should not 404:
curl -sI https://app.brainsnn.com/ | head -1
# → HTTP/2 200

# Open DevTools, run in the console of app.brainsnn.com:
# localStorage.getItem('brainsnn_vault_index_v1')
# Should be `null` on first load.
```

Manual QA on the live URL (allow ~10 min):

- [ ] L109 Vault: New note → type a body with `[[Other]]` → see autocomplete
open after `[[`, accept → click the rendered link in the preview, lands
on a freshly-created "Other" note.
- [ ] L109 Vault: Cognitive firewall card appears under the editor for any
body ≥ 5 words; numbers update on save.
- [ ] L110 Vault Graph: refresh the panel after creating 5 notes with cross
links — graph should show 5 nodes, edges connecting them.
- [ ] L111 Daily Notes: "Today's note" button creates a YYYY-MM-DD note;
a second click of the same button does not create a duplicate.
- [ ] Import .md: drag-drop 3 markdown files; they appear in the sidebar.
- [ ] Export JSON: download a `brainsnn-vault-YYYY-MM-DD.json` file; it is
valid JSON with the expected shape (array of notes).
- [ ] L57 Data Portability still round-trips the entire `brainsnn_*` namespace
including the new vault keys.

### 8c. Storage quotas (browser localStorage)

Each browser allocates ~5 MB to localStorage per origin. The vault uses
one key per note (`brainsnn_vault_note_<id>`) plus the index, so the
real cap is roughly:

```
budget ≈ 5 MB
per-note overhead ≈ 100 bytes (key + JSON envelope)
average note ≈ 2 KB body
→ ~2,000–3,000 notes per browser before headroom runs out
```

When users approach that cap, migrate to IndexedDB by replacing
`localStorageBackend()` with an IndexedDB-backed storage object that
implements the same `{ get, set, remove, keys }` shape — the rest of
the vault code is storage-agnostic by design.

## 9. Rollbacks

Railway keeps deploy history. Roll back via the dashboard or:

Expand Down
51 changes: 51 additions & 0 deletions brainsnn-r3f-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,57 @@ All optional. Copy [.env.example](.env.example) to `.env` and fill in only what
| 33 | Multimodal RAG Router | [MultimodalRagPanel.jsx](src/components/MultimodalRagPanel.jsx) + [utils/multimodalRag.js](src/utils/multimodalRag.js) |
| 34 | Vector-Graph Fusion | [VectorGraphFusionPanel.jsx](src/components/VectorGraphFusionPanel.jsx) |
| 35 | Direct Content Insertion (JSON) | [DirectInsertPanel.jsx](src/components/DirectInsertPanel.jsx) |
| 101 | Quantum Coherence Lab | [QuantumCoherencePanel.jsx](src/components/QuantumCoherencePanel.jsx) + [utils/quantumCoherence.js](src/utils/quantumCoherence.js) |
| 102 | Bell Pair Lab | [BellPairPanel.jsx](src/components/BellPairPanel.jsx) + [utils/bellPair.js](src/utils/bellPair.js) |
| 103 | Quantum Sweep | [QuantumSweepPanel.jsx](src/components/QuantumSweepPanel.jsx) + [utils/quantumSweep.js](src/utils/quantumSweep.js) |
| 104 | Quantum Glossary | [QuantumGlossaryPanel.jsx](src/components/QuantumGlossaryPanel.jsx) + [utils/quantumGlossary.js](src/utils/quantumGlossary.js) |
| 105 | Universal Primitive Lab | [UniversalPrimitivePanel.jsx](src/components/UniversalPrimitivePanel.jsx) + [utils/eml.js](src/utils/eml.js) |
| 106 | NAND Lab | [NandLabPanel.jsx](src/components/NandLabPanel.jsx) + [utils/nand.js](src/utils/nand.js) |
| 107 | GHZ Lab | [GhzLabPanel.jsx](src/components/GhzLabPanel.jsx) + [utils/ghzState.js](src/utils/ghzState.js) |
| 108 | Solovay-Kitaev Mini | [SolovayKitaevPanel.jsx](src/components/SolovayKitaevPanel.jsx) + [utils/solovayKitaev.js](src/utils/solovayKitaev.js) |
| 109 | Vault | [VaultPanel.jsx](src/components/VaultPanel.jsx) + [VaultEditor.jsx](src/components/VaultEditor.jsx) (CodeMirror 6, lazy-loaded) + [utils/vault.js](src/utils/vault.js) + [utils/vaultMarkdown.js](src/utils/vaultMarkdown.js) + [utils/vaultGraph.js](src/utils/vaultGraph.js) + [utils/vaultSearch.js](src/utils/vaultSearch.js) |
| 110 | Vault Graph | [VaultGraphPanel.jsx](src/components/VaultGraphPanel.jsx) (uses utils/vaultGraph.js) |
| 111 | Daily Notes | "Today’s note" button inside [VaultPanel.jsx](src/components/VaultPanel.jsx) + [utils/vaultDaily.js](src/utils/vaultDaily.js) |

## Quantum Coherence Lab

**Layer 101 — Quantum Coherence Lab.** A pure-JavaScript, in-browser simulation
of a single qubit running through `|0⟩ → H → RZ(θ) → H → M`. Slide the phase
θ to watch interference move probability between |0⟩ and |1⟩. Add noise to
damp the fringe. Toggle a mid-circuit observation to collapse superposition.
Stack X·X pairs (algebraically identity) to watch decoherence eat depth.

**What this is.** A teaching sandbox for the *mechanism* behind the word
"alignment": phase coherence steers outcomes; noise and observation kill it.
A **Scientific / Metaphor** mode toggle reframes the same numbers in
plain English alongside the math.

**What this is not.** This does **not** prove literal multiverse theory,
consciousness collapse, Planck foam, or spiritual portals. Those are framing
metaphors when the toggle is on, not physics claims.

**Future backend.** The function surface (`runPhaseExperiment`,
`runDecoherenceExperiment`, etc.) is intentionally compatible with the
hardware-grade Qiskit suite at [`quantum_alignment/`](../quantum_alignment/),
which runs the same three experiments on ideal Aer, noisy Aer, or real IBM
Quantum hardware (and is shaped to swap in OriginQ later). **No vendor API
keys are added to the frontend** — IBM tokens stay in the Python suite,
read from `IBM_QUANTUM_TOKEN` at runtime only.

**Cluster siblings.** Three follow-on layers extend L101 into a coherent quantum module:
- **Layer 102 — Bell Pair Lab.** Two qubits run through `H ⊗ I → CNOT` to build the Bell state `|Φ+⟩ = (|00⟩ + |11⟩) / √2`. RY(θ) on qubit 0 lets you watch correlation slide from +1 (mirrored) to 0 (decohered) to −1 (anti-mirrored). Important framing: this is statistical correlation, *not* information transfer.
- **Layer 103 — Quantum Sweep.** Auto-sweeps θ / noise / X·X-depth, plots P(0) and P(1) against the closed-form ideal, and exports a CSV with the same column shape as `quantum_alignment/results/results.csv` so browser-sim curves can be compared directly with the Qiskit ideal/noisy/real curves.
- **Layer 104 — Quantum Glossary.** Searchable reference card for every term used in L101–L103 — plain language, the math, and a metaphor column explicitly framed as a teaching aid.
- **Layer 105 — Universal Primitive Lab.** Implements `eml(x, y) = exp(x) − ln(y)` from Odrzywołek (arXiv:2603.21852): a single binary operator that, with the constant `1`, generates the elementary library (`exp`, `ln`, `+`, `−`, `·`, `sin`, `cos`, `√`, `e`, `π`, …). Sits next to the quantum cluster because the same "one primitive, all the math" idea links **NAND** (Boolean) ↔ **eml** (continuous) ↔ **`{H, CNOT, T}`** (quantum). Every derivation is independently checked against `Math.*` to ~1e-9 precision in `eml.test.mjs`.
- **Layer 106 — NAND Lab.** The classical-Boolean side of the same bridge. Derives `NOT`, `AND`, `OR`, `NOR`, `XOR`, `XNOR`, `MUX` using only nested `NAND` calls and the constants `0` / `1`. Truth tables pinned against JS native logic in `nand.test.mjs`.
- **Layer 107 — GHZ Lab.** Extends L102 from 2 qubits to 3: `|000⟩ → H ⊗ I ⊗ I → CNOT(0,1) → CNOT(0,2) = (|000⟩ + |111⟩) / √2`. Renders the 8-bin joint distribution + parity metric `P(000) + P(111)` (1.0 ideal, 1/4 fully randomised). Apply-to-brain wired.
- **Layer 108 — Solovay-Kitaev mini-demo.** Brute-force *basic-approximation* step over `{H, T, T†}`: pick a target `RZ(θ)`, search every sequence up to length 8, plot best-distance vs length. Teaches the convergence rate that the recursive SK algorithm then accelerates exponentially.

Run the unit tests directly with Node (no extra dev deps):

```bash
npm run test:quantum
```

## Keyboard shortcuts

Expand Down
Loading
Loading