cw-fulmark commited on
Commit
ddb21b6
·
0 Parent(s):

initial public demo release

Browse files
.github/workflows/ci.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: QATALYST SDS CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: actions/setup-python@v5
9
+ with:
10
+ python-version: "3.11"
11
+ - run: pip install torch --index-url https://download.pytorch.org/whl/cpu
12
+ - run: pip install gradio z3-solver pytest
13
+ - run: pytest -q
.gitignore ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ .venv/
7
+ venv/
8
+ .env
9
+
10
+ # Runtime/demo outputs
11
+ *.jsonl
12
+ logs/
13
+ runs/
14
+ outputs/
15
+
16
+ # OS/editor
17
+ .DS_Store
18
+ .vscode/
19
+ .idea/
README.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: QATALYST SDS Demo
3
+ emoji: 🛡️
4
+ colorFrom: gray
5
+ colorTo: blue
6
+ sdk: gradio
7
+ app_file: app.py
8
+ pinned: false
9
+ license: apache-2.0
10
+ ---
11
+ # QATALYST SDS (Experimental Demo)
12
+
13
+ QATALYST SDS is an experimental agentic simulation framework demonstrating modular AI components, a simulated safety layer, and a Gradio UI.
14
+
15
+ **Note:** This repository contains non-enforcing, simulated code intended strictly for UI demonstration and hacking purposes. It does not represent production hardware or cryptographic infrastructure.
16
+
17
+ ## License
18
+ Apache-2.0
app.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+
4
+ # 1. This tells the system where your code is hiding
5
+ sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
6
+
7
+ # 2. This imports your EXACT 'demo' from your original file
8
+ from qatalyst.ui.gradio_app import demo
9
+
10
+ if __name__ == "__main__":
11
+ # 3. This launches your 'demo' exactly as you designed it
12
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ z3-solver
3
+ pytest
setup.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="qatalyst",
5
+ version="0.1",
6
+ packages=find_packages(where="src"),
7
+ package_dir={"": "src"},
8
+ )
src/main.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from qatalyst.apex.tick import run_qatalyst_tick
2
+
3
+
4
+ def main():
5
+ print("--- QATALYST SDS Apex Build Starting ---")
6
+
7
+ # Simulating a standard operational state
8
+ temp = 45.0
9
+ tension = 0.3
10
+
11
+ try:
12
+ output = run_qatalyst_tick(temp, tension)
13
+ print(output)
14
+ except Exception as e:
15
+ print(f"[!] System Fault: {e}")
16
+
17
+
18
+ if __name__ == "__main__":
19
+ main()
src/qatalyst/__init__.py ADDED
File without changes
src/qatalyst/agents/__init__.py ADDED
File without changes
src/qatalyst/agents/godel_cortex.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from qatalyst.shared import DEVICE, DTYPE
3
+
4
+
5
+ class GodelAgent:
6
+ """
7
+ Gödel Cortex - 1.5x Panic Factor & Non-linear warping.
8
+ """
9
+
10
+ BASELINE = 0.50
11
+ PANIC_MULTIPLIER = 1.5
12
+
13
+ def synthesize_routing(self, hypermesh_state: torch.Tensor) -> torch.Tensor:
14
+ stress_signal = float(torch.mean(hypermesh_state))
15
+ panic_factor = stress_signal * self.PANIC_MULTIPLIER
16
+
17
+ angles = torch.tensor([1.1, 0.9, 0.4, 1.2], device=DEVICE, dtype=DTYPE)
18
+ sin_vals = torch.sin(angles)
19
+ cos_vals = torch.cos(angles)
20
+
21
+ base = self.BASELINE
22
+ action_vector = torch.tensor(
23
+ [
24
+ base + panic_factor * sin_vals[0].item(),
25
+ base - panic_factor * cos_vals[1].item(),
26
+ base + panic_factor * 0.8,
27
+ base - panic_factor * 0.8,
28
+ base + panic_factor * sin_vals[2].item(),
29
+ base - panic_factor * cos_vals[3].item(),
30
+ ],
31
+ dtype=DTYPE,
32
+ device=DEVICE,
33
+ )
34
+
35
+ return torch.clamp(action_vector, 0.0, 1.0)
src/qatalyst/agents/meta_critic.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from typing import Tuple
3
+
4
+
5
+ class GodelMetaCritic:
6
+ """Evaluates proposal variance; squashes if > 0.08."""
7
+
8
+ def __init__(self, max_variance: float = 0.08):
9
+ self.max_variance = max_variance
10
+
11
+ def critique(self, proposal: torch.Tensor) -> Tuple[torch.Tensor, float]:
12
+ variance = float(torch.var(proposal))
13
+ if variance > self.max_variance:
14
+ adjusted = (proposal * 0.6) + (0.4 * 0.5)
15
+ return adjusted, variance
16
+ return proposal, variance
src/qatalyst/apex/__init__.py ADDED
File without changes
src/qatalyst/apex/tick.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ import torch
3
+ from qatalyst.substrate.hca1 import HCA1_Substrate
4
+ from qatalyst.substrate.hypermesh import HyperMeshEngine
5
+ from qatalyst.substrate.scheduler import MetabolicScheduler
6
+ from qatalyst.substrate.spectrahedron import SpectrahedronGeometryEngine
7
+ from qatalyst.agents.godel_cortex import GodelAgent
8
+ from qatalyst.agents.meta_critic import GodelMetaCritic
9
+ from qatalyst.governance.sovereign_vault import SimulatedSovereignVault
10
+ from qatalyst.governance.ledger import CognitiveLedger
11
+
12
+ substrate, hypermesh = HCA1_Substrate(), HyperMeshEngine()
13
+ scheduler, vault = MetabolicScheduler(), SimulatedSovereignVault()
14
+ cortex, critic = GodelAgent(), GodelMetaCritic()
15
+ spectra, ledger = SpectrahedronGeometryEngine(), CognitiveLedger()
16
+
17
+
18
+ def run_qatalyst_tick(temp: float, tension: float):
19
+ temp_norm = temp / 100.0
20
+ telemetry = {
21
+ "T_norm": temp_norm,
22
+ "E": tension,
23
+ "policy": tension,
24
+ "trust": 0.5,
25
+ "latency": 0.1,
26
+ "cost": temp_norm,
27
+ }
28
+ substrate.upsert_telemetry(0, [0.1, 0.5, 0.1, 0.1, tension, temp_norm])
29
+ hyper_state = hypermesh.build_triads(telemetry)
30
+ raw_proposal = cortex.synthesize_routing(hyper_state)
31
+ proposal_adjusted, proposal_var = critic.critique(raw_proposal)
32
+ law_strictness = scheduler.compute_law_strictness(temp_norm, tension)
33
+ is_safe, proof, action_hash, total_energy, dynamic_bound = (
34
+ vault.generate_stability_proof(
35
+ proposal_adjusted, temp_norm, tension, law_strictness
36
+ )
37
+ )
38
+ region, margin = spectra.classify(total_energy, dynamic_bound)
39
+ status = "🟢 EXECUTED" if is_safe else "🔴 ANNIHILATED"
40
+ ledger.record({"status": status, "phi": total_energy, "region": region})
41
+ return f"Status: {status} | Energy: {total_energy:.4f} | Region: {region}"
src/qatalyst/governance/__init__.py ADDED
File without changes
src/qatalyst/governance/ledger.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import time
3
+
4
+
5
+ class CognitiveLedger:
6
+ """Immutable record of system state transitions."""
7
+
8
+ def __init__(self, path="cognitive_ledger.jsonl"):
9
+ self.path = path
10
+
11
+ def record(self, entry: dict):
12
+ entry["timestamp"] = time.time()
13
+ with open(self.path, "a") as f:
14
+ f.write(json.dumps(entry) + "\n")
src/qatalyst/governance/sovereign_vault.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uuid
2
+ import hashlib
3
+ from typing import Tuple
4
+ import torch
5
+ from z3 import Solver, Real, unsat
6
+
7
+
8
+ class SimulatedSovereignVault:
9
+ def __init__(self):
10
+ self.alpha_temp, self.beta_tension, self.gamma_action = 0.40, 0.35, 0.25
11
+ self.base_phi_max = 0.85
12
+
13
+ def generate_stability_proof(
14
+ self,
15
+ proposed_action: torch.Tensor,
16
+ temp_norm: float,
17
+ tension: float,
18
+ law_strictness: float,
19
+ ) -> Tuple[bool, str, str, float, float]:
20
+ s = Solver()
21
+ T_z, E_z, A_z, Phi_z = Real("T"), Real("E"), Real("A_mean_sq"), Real("Phi")
22
+ a_mean_sq = float(torch.mean(proposed_action**2))
23
+ s.add(T_z == float(temp_norm), E_z == float(tension), A_z == a_mean_sq)
24
+ energy_eq = (
25
+ self.alpha_temp * (T_z**2)
26
+ + self.beta_tension * (E_z**2)
27
+ + self.gamma_action * A_z
28
+ )
29
+ s.add(Phi_z == energy_eq)
30
+ dynamic_phi_bound = self.base_phi_max / law_strictness
31
+ s.add(Phi_z <= dynamic_phi_bound)
32
+ action_hash = hashlib.sha256(
33
+ proposed_action.detach().cpu().numpy().tobytes()
34
+ ).hexdigest()
35
+ if s.check() == unsat:
36
+ total_energy = (
37
+ self.alpha_temp * temp_norm**2
38
+ + self.beta_tension * tension**2
39
+ + self.gamma_action * a_mean_sq
40
+ )
41
+ return (
42
+ False,
43
+ "NULL_SPACE_REJECTION",
44
+ action_hash,
45
+ total_energy,
46
+ dynamic_phi_bound,
47
+ )
48
+ zk_proof = f"ZK-SIM-{uuid.uuid4().hex[:8]}"
49
+ m = s.model()
50
+ safe_energy = float(m[Phi_z].as_fraction()) if m[Phi_z] is not None else 0.0
51
+ return True, zk_proof, action_hash, safe_energy, dynamic_phi_bound
src/qatalyst/shared.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
4
+ DTYPE = torch.float32
5
+
6
+ torch.set_default_device(DEVICE)
7
+ torch.set_default_dtype(DTYPE)
src/qatalyst/substrate/__init__.py ADDED
File without changes
src/qatalyst/substrate/hca1.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from typing import List
3
+ from qatalyst.shared import DEVICE, DTYPE
4
+
5
+
6
+ class HCA1_Substrate:
7
+ """Holomorphic Compute Architecture (HCA-1). Zero-copy state array."""
8
+
9
+ def __init__(self, entities: int = 1000):
10
+ self.entities = entities
11
+ self.state_tensor = torch.zeros((entities, 6), device=DEVICE, dtype=DTYPE)
12
+ self.memory_pool = bytearray(entities * 6 * 4)
13
+ print(f"[*] HCA-1 Substrate: {entities} nodes allocated on {DEVICE}")
14
+
15
+ def upsert_telemetry(self, entity_id: int, vector: List[float]) -> None:
16
+ with torch.no_grad():
17
+ self.state_tensor[entity_id] = torch.tensor(
18
+ vector, device=DEVICE, dtype=DTYPE
19
+ )
src/qatalyst/substrate/hypermesh.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from typing import Dict
3
+ from qatalyst.shared import DEVICE, DTYPE
4
+
5
+
6
+ class HyperMeshEngine:
7
+ """Triadic causal state representation for advanced context."""
8
+
9
+ def build_triads(self, telemetry: Dict[str, float]) -> torch.Tensor:
10
+ triad_1 = torch.tensor(
11
+ [telemetry["T_norm"], telemetry["E"], telemetry["policy"]],
12
+ dtype=DTYPE,
13
+ device=DEVICE,
14
+ )
15
+ triad_2 = torch.tensor(
16
+ [telemetry["trust"], telemetry["latency"], telemetry["cost"]],
17
+ dtype=DTYPE,
18
+ device=DEVICE,
19
+ )
20
+ return torch.cat([triad_1, triad_2], dim=0)
src/qatalyst/substrate/scheduler.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ class MetabolicScheduler:
2
+ """strictness = 0.90 + (0.35 * stress)"""
3
+
4
+ def compute_law_strictness(self, temp_norm: float, tension: float) -> float:
5
+ stress = (temp_norm * 0.5) + (tension * 0.5)
6
+ strictness = 0.90 + (0.35 * stress)
7
+ return strictness
src/qatalyst/substrate/spectrahedron.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Tuple
2
+
3
+
4
+ class SpectrahedronGeometryEngine:
5
+ """Classifies where the system sits relative to the warped stability region."""
6
+
7
+ def classify(self, system_energy: float, dynamic_bound: float) -> Tuple[str, float]:
8
+ margin = dynamic_bound - system_energy
9
+ state = "STABLE" if margin > 0 else "WARPED"
10
+ return state, margin
src/qatalyst/ui/__init__.py ADDED
File without changes
src/qatalyst/ui/gradio_app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from qatalyst.apex.tick import run_qatalyst_tick
4
+
5
+
6
+ def simulate_tick(temp, tension):
7
+ try:
8
+ return run_qatalyst_tick(temp, tension)
9
+ except Exception as e:
10
+ return f"**[!] SYSTEM FAULT:** {e}"
11
+
12
+
13
+ def read_ledger():
14
+ ledger_path = "cognitive_ledger.jsonl"
15
+ if not os.path.exists(ledger_path):
16
+ return "[]"
17
+ with open(ledger_path, "r") as f:
18
+ lines = f.readlines()
19
+ # Format the last 10 ticks, reversed so the newest is at the top
20
+ formatted = (
21
+ "[\n " + ",\n ".join([l.strip() for l in reversed(lines[-10:])]) + "\n]"
22
+ )
23
+ return formatted
24
+
25
+
26
+ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
27
+ gr.Markdown("# 🛡️ QATALYST SDS: Apex Command Center")
28
+
29
+ with gr.Tabs():
30
+ with gr.TabItem("Sovereign Vault Control"):
31
+ gr.Markdown(
32
+ "Adjust telemetry to observe Z3 Formal Verification guardrails in real-time."
33
+ )
34
+ with gr.Row():
35
+ with gr.Column():
36
+ gr.Markdown("### 🎛️ Telemetry Inputs")
37
+ temp_slider = gr.Slider(
38
+ 0.0, 100.0, 45.0, step=1.0, label="Substrate Temperature (°C)"
39
+ )
40
+ tension_slider = gr.Slider(
41
+ 0.0, 1.0, 0.3, step=0.05, label="Network Tension (E)"
42
+ )
43
+ run_btn = gr.Button("Execute Apex Tick", variant="primary")
44
+ with gr.Column():
45
+ gr.Markdown("### 📡 Tick Output")
46
+ output_display = gr.Markdown(
47
+ "> System Ready. Awaiting telemetry..."
48
+ )
49
+
50
+ run_btn.click(
51
+ fn=simulate_tick,
52
+ inputs=[temp_slider, tension_slider],
53
+ outputs=output_display,
54
+ )
55
+
56
+ with gr.TabItem("Cognitive Ledger Audit"):
57
+ gr.Markdown(
58
+ "Immutable record of system state transitions (Showing last 10 events)."
59
+ )
60
+ refresh_btn = gr.Button("🔄 Sync Ledger", variant="secondary")
61
+ ledger_display = gr.Code(language="json", interactive=False)
62
+
63
+ # Update ledger when button is clicked OR when the UI first loads
64
+ refresh_btn.click(fn=read_ledger, inputs=[], outputs=ledger_display)
65
+ demo.load(fn=read_ledger, inputs=[], outputs=ledger_display)
66
+
67
+ if __name__ == "__main__":
68
+ print("[*] Launching Upgraded Command Center...")
69
+ demo.launch(server_name="127.0.0.1", server_port=7860, quiet=True)
tests/test_demo.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ def test_demo_environment():
2
+ """Simple sanity check for the Open Demo Surface."""
3
+ assert True