Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import numpy as np
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import platform
|
| 5 |
+
import psutil
|
| 6 |
+
|
| 7 |
+
# -------------------------------
|
| 8 |
+
# Coherent Compute Core
|
| 9 |
+
# -------------------------------
|
| 10 |
+
|
| 11 |
+
def rft_step(Psi, E, L):
|
| 12 |
+
# Stable, branchless update
|
| 13 |
+
phase = 0.997 * Psi + 0.003 * E
|
| 14 |
+
drive = np.tanh(phase)
|
| 15 |
+
Psi = 0.999 * Psi + 0.001 * drive
|
| 16 |
+
E = 0.995 * E + 0.004 * Psi
|
| 17 |
+
L = 0.998 * L + 0.001 * (Psi * E)
|
| 18 |
+
return Psi, E, L
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def coherence_metric(prev, curr):
|
| 22 |
+
num = np.dot(prev, curr)
|
| 23 |
+
den = (np.linalg.norm(prev) * np.linalg.norm(curr)) + 1e-9
|
| 24 |
+
return float(num / den)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# -------------------------------
|
| 28 |
+
# Benchmark Runner
|
| 29 |
+
# -------------------------------
|
| 30 |
+
|
| 31 |
+
def run_engine(oscillators: int, steps: int):
|
| 32 |
+
oscillators = int(oscillators)
|
| 33 |
+
steps = int(steps)
|
| 34 |
+
|
| 35 |
+
rng = np.random.default_rng(42)
|
| 36 |
+
Psi = rng.random(oscillators, dtype=np.float32)
|
| 37 |
+
E = rng.random(oscillators, dtype=np.float32)
|
| 38 |
+
L = rng.random(oscillators, dtype=np.float32)
|
| 39 |
+
|
| 40 |
+
sample = min(200_000, oscillators)
|
| 41 |
+
prev_snapshot = Psi[:sample].copy()
|
| 42 |
+
|
| 43 |
+
t0 = time.time()
|
| 44 |
+
|
| 45 |
+
for _ in range(steps):
|
| 46 |
+
Psi, E, L = rft_step(Psi, E, L)
|
| 47 |
+
|
| 48 |
+
elapsed = time.time() - t0
|
| 49 |
+
curr_snapshot = Psi[:sample].copy()
|
| 50 |
+
|
| 51 |
+
coherence = abs(coherence_metric(prev_snapshot, curr_snapshot))
|
| 52 |
+
energy = float(np.mean(E))
|
| 53 |
+
|
| 54 |
+
items = oscillators * steps
|
| 55 |
+
throughput = items / elapsed
|
| 56 |
+
|
| 57 |
+
return {
|
| 58 |
+
"Throughput (updates/sec)": f"{throughput/1e9:.3f} B/s",
|
| 59 |
+
"Coherence (|C|)": f"{coherence:.5f}",
|
| 60 |
+
"Mean Energy": f"{energy:.5f}",
|
| 61 |
+
"Elapsed Time (s)": f"{elapsed:.2f}",
|
| 62 |
+
"Oscillators": f"{oscillators:,}",
|
| 63 |
+
"Steps": f"{steps:,}",
|
| 64 |
+
"CPU": platform.processor(),
|
| 65 |
+
"Cores Available": psutil.cpu_count(logical=True)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# -------------------------------
|
| 70 |
+
# Gradio UI
|
| 71 |
+
# -------------------------------
|
| 72 |
+
|
| 73 |
+
with gr.Blocks(title="Coherent Compute Engine") as demo:
|
| 74 |
+
gr.Markdown(
|
| 75 |
+
"""
|
| 76 |
+
# Coherent Compute Engine
|
| 77 |
+
|
| 78 |
+
**What this is**
|
| 79 |
+
- A live, CPU-first coherent compute benchmark
|
| 80 |
+
- No precomputed results
|
| 81 |
+
- No GPUs required
|
| 82 |
+
- Measures real throughput, stability, and energy behavior
|
| 83 |
+
|
| 84 |
+
**What an “item” is**
|
| 85 |
+
- One coherent state update of `[Ψ, E, L]` per oscillator per step
|
| 86 |
+
|
| 87 |
+
Everything you see below is computed **right now**, on this machine.
|
| 88 |
+
"""
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
with gr.Row():
|
| 92 |
+
oscillators = gr.Slider(
|
| 93 |
+
minimum=100_000,
|
| 94 |
+
maximum=10_000_000,
|
| 95 |
+
value=2_000_000,
|
| 96 |
+
step=100_000,
|
| 97 |
+
label="Number of Oscillators"
|
| 98 |
+
)
|
| 99 |
+
steps = gr.Slider(
|
| 100 |
+
minimum=50,
|
| 101 |
+
maximum=1000,
|
| 102 |
+
value=250,
|
| 103 |
+
step=50,
|
| 104 |
+
label="Simulation Steps"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
run_btn = gr.Button("Run Engine")
|
| 108 |
+
|
| 109 |
+
output = gr.JSON(label="Results")
|
| 110 |
+
|
| 111 |
+
run_btn.click(
|
| 112 |
+
fn=run_engine,
|
| 113 |
+
inputs=[oscillators, steps],
|
| 114 |
+
outputs=output
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
demo.launch()
|