File size: 5,358 Bytes
6eea3ca
a13a736
1c2a285
6eea3ca
b52ef4a
e9b9fb9
b52ef4a
 
 
 
6fa522a
a13a736
b52ef4a
 
 
1c2a285
b52ef4a
6eea3ca
09ef6ea
b52ef4a
e9b9fb9
 
 
1c2a285
b52ef4a
d38a78d
e9b9fb9
 
09ef6ea
d38a78d
1c2a285
b52ef4a
 
1c2a285
 
e9b9fb9
6fa522a
1c2a285
e9b9fb9
 
 
 
09ef6ea
e9b9fb9
71529e4
09ef6ea
71529e4
09ef6ea
71529e4
09ef6ea
e9b9fb9
09ef6ea
1c2a285
09ef6ea
1c2a285
 
09ef6ea
1c2a285
 
e9b9fb9
 
 
 
 
a13a736
1c2a285
09ef6ea
 
 
 
 
 
e9b9fb9
1c2a285
a13a736
 
 
 
 
 
 
 
 
 
 
 
71529e4
09ef6ea
a13a736
e9b9fb9
a13a736
 
 
0ab5d6a
 
 
 
 
a13a736
0ab5d6a
 
a13a736
 
 
 
 
0ab5d6a
 
 
a13a736
 
0ab5d6a
e9b9fb9
09ef6ea
b52ef4a
a13a736
e9b9fb9
09ef6ea
b52ef4a
1c2a285
09ef6ea
 
 
1c2a285
09ef6ea
a13a736
 
 
1c2a285
a13a736
 
1c2a285
 
 
e9b9fb9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# ============================================================
# Rendered Frame Theory — Stabilising System Verification Panel
# Author: Liam Grinstead | RFT Systems | All Rights Reserved
# ============================================================

import json, random
from datetime import datetime
import numpy as np
import gradio as gr

# ------------------ About / Legal ---------------------------
RFT_VERSION = "v4.0-verification-panel"
RFT_DOI = "https://doi.org/10.5281/zenodo.17466722"
LEGAL_NOTICE = (
    "All Rights Reserved — RFT-IPURL v1.0 (UK / Berne). "
    "Research validation use only. No reverse-engineering without written consent."
)

# ------------------ System Profiles -------------------------
PROFILES = {
    "AI / Neural":          {"base": (0.86, 0.80), "w": (0.65, 0.35)},
    "SpaceX / Aerospace":   {"base": (0.84, 0.79), "w": (0.60, 0.40)},
    "Energy / RHES":        {"base": (0.83, 0.78), "w": (0.55, 0.45)},
    "Extreme Perturbation": {"base": (0.82, 0.77), "w": (0.50, 0.50)},
}

# ------------------ Simulation Core -------------------------
def _rng(seed: int):
    return np.random.RandomState(seed)

def simulate_step(rng, profile, sigma, dist):
    base_q, base_z = PROFILES[profile]["base"]
    wq, wz = PROFILES[profile]["w"]
    if dist == "uniform":
        qn = rng.uniform(-sigma, sigma)
        zn = rng.uniform(-sigma * 0.8, sigma * 0.8)
    else:
        qn = rng.normal(0, sigma)
        zn = rng.normal(0, sigma * 0.8)

    q = float(np.clip(base_q + wq * qn, 0.0, 0.99))
    z = float(np.clip(base_z + wz * zn, 0.0, 0.99))
    variance = abs(qn) + abs(zn)

    if variance > 0.15:
        status = "critical"
    elif variance > 0.07:
        status = "perturbed"
    else:
        status = "nominal"

    return {"σ": round(sigma, 6), "QΩ": q, "ζ_sync": z, "status": status}

# ------------------ Simulation Runner -----------------------
def run(profile, dist, sigma, seed, samples):
    rng = _rng(int(seed))
    results = [simulate_step(rng, profile, sigma, dist) for _ in range(samples)]
    q_mean = np.mean([r["QΩ"] for r in results])
    z_mean = np.mean([r["ζ_sync"] for r in results])
    majority = max(
        ["nominal", "perturbed", "critical"],
        key=lambda s: sum(1 for r in results if r["status"] == s),
    )

    summary = {
        "profile": profile,
        "noise_scale": sigma,
        "distribution": dist,
        "QΩ_mean": round(float(q_mean), 6),
        "ζ_sync_mean": round(float(z_mean), 6),
        "status_majority": majority,
        "timestamp_utc": datetime.utcnow().isoformat() + "Z",
        "rft_notice": LEGAL_NOTICE,
    }
    return summary, json.dumps(summary, indent=2)

# ------------------ File Saver -------------------------------
def save_run_log(run_json_str):
    try:
        data = json.loads(run_json_str)
        filename = f"RFT_Omega_Run_{datetime.utcnow().strftime('%Y-%m-%dT%H-%M-%SZ')}.json"
        with open(filename, "w") as f:
            json.dump(data, f, indent=2)
        return filename
    except Exception as e:
        return None

# ------------------ Gradio Interface ------------------------
with gr.Blocks(title="Rendered Frame Theory — Stabilising System Verification Panel") as demo:
    gr.Markdown(
        f"## 🧠 Rendered Frame Theory — Stabilising System Verification Panel  \n"
        f"**Version:** {RFT_VERSION}  \n"
        f"**DOI:** [{RFT_DOI}]({RFT_DOI})  \n"
        f"{LEGAL_NOTICE}"
    )

    gr.Markdown(
        """
        ### 🧩 How to Use  
        1️⃣ Select a **System Profile** (AI / Neural, SpaceX / Aerospace, Energy / RHES, Extreme Perturbation).  
        2️⃣ Choose a **Noise Distribution** (gauss or uniform).  
        3️⃣ Adjust **Noise Scale (σ)** to simulate environmental perturbations.  
        4️⃣ Press **Run Simulation** — results will show mean QΩ (stability) and ζ_sync (coherence) across samples.  
        5️⃣ Use **Save Run Log** to download your test record as a JSON file with timestamp.  

        **Interpretation:**  
        - `Nominal` → Stable harmonic equilibrium  
        - `Perturbed` → Transitional / adaptive state  
        - `Critical` → Instability threshold reached  

        Each output is time-stamped, reproducible, and protected under RFT-IPURL v1.0.  
        """
    )

    with gr.Row():
        profile = gr.Dropdown(list(PROFILES.keys()), label="System Profile", value="AI / Neural")
        dist = gr.Radio(["gauss", "uniform"], label="Noise Distribution", value="gauss")

    with gr.Row():
        sigma = gr.Slider(0.0, 0.3, value=0.05, step=0.01, label="Noise Scale (σ)")
        seed = gr.Number(value=123, label="Seed (integer)")
        samples = gr.Slider(1, 20, value=5, step=1, label="Samples per run")

    run_btn = gr.Button("Run Simulation")
    output = gr.JSON(label="Simulation Results")
    hidden_json = gr.Textbox(visible=False)
    save_btn = gr.Button("💾 Save Run Log")
    download_file = gr.File(label="Download Saved Log")

    run_btn.click(run, inputs=[profile, dist, sigma, seed, samples], outputs=[output, hidden_json])
    save_btn.click(save_run_log, inputs=[hidden_json], outputs=[download_file])

# ------------------ Launch -------------------------------
if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", share=False, ssr_mode=False)