""" VPP Quantum Scheduler — Frontend v4 Paradox Systems R&D Security: All sensitive configuration (backend URL, API key, access password) must be set via Hugging Face Space Secrets. No defaults are hardcoded. """ import gradio as gr import requests import os BACKEND_URL = os.environ.get("VPP_BACKEND_URL") ACCESS_PASSWORD = os.environ.get("VPP_ACCESS_PASSWORD") API_KEY = os.environ.get("VPP_API_KEY") if not all([BACKEND_URL, ACCESS_PASSWORD, API_KEY]): raise RuntimeError( "Missing required secrets. Set VPP_BACKEND_URL, VPP_ACCESS_PASSWORD, " "and VPP_API_KEY in Hugging Face Space Secrets." ) API_HEADERS = {"X-API-KEY": API_KEY} PRESETS = { "atom_computing": "Atom Computing (Muniz et al. 2025) — Neutral atoms, 225 qubits", "quantinuum_h2": "Quantinuum H2 (Moses et al. 2023) — Trapped ions, 56 qubits", "quera_aquila": "QuEra Aquila (Bluvstein et al. 2023) — Neutral atoms, 256 qubits", "custom_scalars": "Custom — Enter scalar parameters manually", "custom_curves": "Custom — Upload calibration curves CSV", } def login(password): if password == ACCESS_PASSWORD: return gr.update(visible=False), gr.update(visible=True), gr.update(value="", visible=False) return gr.update(visible=True), gr.update(visible=False), gr.update(value="⚠ Incorrect password.", visible=True) def _fmt_diagnosis(data): d = data["diagnosis"]; r = data["vpp_recommendation"] return f""" ╔══════════════════════════════════════════════════════════╗ ║ VPP QUANTUM SCHEDULER — DIAGNOSIS REPORT ║ ╚══════════════════════════════════════════════════════════╝ HARDWARE SOURCE: {data['hardware_source']} ANALYSIS IC Wall (α=1) : n = {d['IC_wall_standard']} Coherence half-life : {d['HL_analytic']} cycles Primary bottleneck : {d['primary_bottleneck']} {d['bottleneck_explanation']} VPP RECOMMENDATION Optimal DELAY α : {r['optimal_delay_alpha']} IC Wall extended to : n = {r['IC_wall_extended']} Extension : +{r['extension_pct']}% Ancilla fidelity at α*: {r['F_at_optimal_alpha']} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🔒 {data['privacy_note']} Paradox Systems R&D — VPP Quantum Scheduler v4.0 """ def _fmt_schedule(data): s = data["summary"]; res = s["results"]; ana = s["analysis"]; asc = s["alpha_schedule_summary"] n_ref = 160 return f""" ╔══════════════════════════════════════════════════════════╗ ║ VPP QUANTUM SCHEDULER — SCHEDULE REPORT ║ ╚══════════════════════════════════════════════════════════╝ HARDWARE SOURCE: {s['hardware_source']} ANALYSIS IC Wall (α=1) : n = {ana['IC_wall_n']} Half-life analytic : {ana['HL_analytic_cycles']} cycles Cycles simulated : {ana['n_cycles_simulated']} Bottleneck : {ana['bottleneck']} RESULTS Standard HL : {res['standard']['HL_observed']} VPP HL : {res['vpp']['HL_observed']} HL Ratio : {res['HL_ratio']} Coherence gain @160 : +{res.get('coherence_gain_pct_at_cycle_160','n/a')}% Standard retires : {res['standard']['retires_mean']} VPP retires : {res['vpp']['retires_mean']} α SCHEDULE Range : α ∈ [{asc['alpha_range'][0]}, {asc['alpha_range'][1]}] Mean α before wall : {asc['mean_alpha_before_wall']} Mean α after wall : {asc['mean_alpha_after_wall']} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🔒 {s['privacy_note']} Paradox Systems R&D — VPP Quantum Scheduler v4.0 """ def run_diagnosis(hw_choice, c1, s, Fm, c0, kR, I_floor, F_min, curves_file): try: if hw_choice == "custom_curves": if curves_file is None: return "⚠ Please upload a calibration curves CSV file." with open(curves_file.name, 'rb') as f: r = requests.post(f"{BACKEND_URL}/diagnose/curves", files={"curves_csv": f}, data={"I_floor": I_floor, "F_min": F_min}, headers=API_HEADERS, timeout=30) elif hw_choice == "custom_scalars": r = requests.post(f"{BACKEND_URL}/diagnose/scalars", data={"c_alpha1":c1,"s_per_cycle":s,"F_max":Fm, "c_alpha0":c0,"k_R":kR,"I_floor":I_floor,"F_min":F_min}, headers=API_HEADERS, timeout=30) else: preset_id = hw_choice r = requests.post(f"{BACKEND_URL}/diagnose/preset", data={"preset_id": preset_id, "I_floor": I_floor, "F_min": F_min}, headers=API_HEADERS, timeout=30) if not r.ok: try: detail = r.json().get("detail", r.text) except: detail = r.text return f"⚠ Server error {r.status_code}: {detail}" return _fmt_diagnosis(r.json()) except requests.exceptions.ConnectionError: return "⚠ Cannot connect to scheduler backend. Contact: albertoduarte@paradoxsystems.xyz" except Exception as e: return f"⚠ Error: {str(e)}" def run_schedule(hw_choice, c1, s, Fm, c0, kR, I_floor, F_min, curves_file, n_cycles, n_shots, mode): try: common = {"mode": mode, "n_cycles": int(n_cycles), "n_shots": int(n_shots), "I_floor": I_floor, "F_min": F_min} if hw_choice == "custom_curves": if curves_file is None: return "⚠ Please upload a calibration curves CSV file.", None with open(curves_file.name, 'rb') as f: r = requests.post(f"{BACKEND_URL}/schedule/curves", files={"curves_csv": f}, data=common, headers=API_HEADERS, timeout=120) elif hw_choice == "custom_scalars": r = requests.post(f"{BACKEND_URL}/schedule/scalars", data={"c_alpha1":c1,"s_per_cycle":s,"F_max":Fm, "c_alpha0":c0,"k_R":kR,**common}, headers=API_HEADERS, timeout=120) else: r = requests.post(f"{BACKEND_URL}/schedule/preset", data={"preset_id": hw_choice, **common}, headers=API_HEADERS, timeout=120) if not r.ok: try: detail = r.json().get("detail", r.text) except: detail = r.text return f"⚠ Server error {r.status_code}: {detail}", None data = r.json() summary_text = _fmt_schedule(data) csv_path = "/tmp/vpp_schedule.csv" with open(csv_path, "w") as f: f.write(data.get("schedule_csv", "")) return summary_text, csv_path except requests.exceptions.ConnectionError: return "⚠ Cannot connect to scheduler backend.", None except Exception as e: return f"⚠ Error: {str(e)}", None def toggle_custom(hw_choice): show_scalars = hw_choice == "custom_scalars" show_curves = hw_choice == "custom_curves" return gr.update(visible=show_scalars), gr.update(visible=show_curves) # ── CSS ──────────────────────────────────────────────────────────────────────── CSS = """ @import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;600&display=swap'); body { background: #08090d !important; font-family: 'DM Sans', sans-serif !important; } .gradio-container { background: #08090d !important; max-width: 960px !important; margin: 0 auto !important; } h1 { font-family: 'Space Mono', monospace !important; color: #2EC4B6 !important; font-size: 1.8rem !important; } .tab-nav button { font-family: 'Space Mono', monospace !important; color: #8892a4 !important; border-bottom: 2px solid transparent !important; } .tab-nav button.selected { color: #2EC4B6 !important; border-bottom: 2px solid #2EC4B6 !important; } label { color: #8892a4 !important; font-size: 0.82rem !important; font-family: 'Space Mono', monospace !important; } button.primary { background: #2EC4B6 !important; color: #08090d !important; font-family: 'Space Mono', monospace !important; font-weight: 700 !important; border-radius: 4px !important; border: none !important; } button.primary:hover { background: #22a99d !important; } .privacy-note { background: #0d1117; border-left: 3px solid #2EC4B6; padding: 8px 12px; font-size: 0.8rem; color: #8892a4; border-radius: 0 4px 4px 0; } footer { display: none !important; } """ HEADER = """ # VPP Quantum Scheduler **Paradox Systems R&D** · Adaptive mid-circuit measurement optimization > 🔒 **Privacy:** Your calibration data is processed in server memory only and is never stored, logged, or shared. > For partnership inquiries: albertoduarte@paradoxsystems.xyz | WhatsApp: +526122173332 """ CSV_TEMPLATE = """alpha,c_alpha,F_alpha,I_gain,s_alpha 0.0,0.9998,0.500,0.000,0.989 0.1,0.9994,0.650,0.110,0.989 0.2,0.9990,0.780,0.200,0.989 0.3,0.9985,0.870,0.330,0.989 0.5,0.9975,0.950,0.550,0.989 0.7,0.9965,0.985,0.750,0.989 1.0,0.9951,0.997,1.000,0.989""" # ── UI ───────────────────────────────────────────────────────────────────────── with gr.Blocks(css=CSS, title="VPP Quantum Scheduler") as demo: with gr.Group() as login_screen: gr.Markdown(""" # VPP Quantum Scheduler **Paradox Systems R&D** This tool is available by invitation only. Contact **albertoduarte@paradoxsystems.xyz** or WhatsApp **+526122173332** to request access. """) pwd_input = gr.Textbox(label="Access Password", type="password", placeholder="Enter your access password") login_btn = gr.Button("Access Scheduler", variant="primary") login_err = gr.Markdown("", visible=False) with gr.Group(visible=False) as main_screen: gr.Markdown(HEADER) # ── Hardware selector (shared between tabs) ─────────────────────────── hw_choice = gr.Radio( label="Hardware Platform", choices=list(PRESETS.keys()), value="atom_computing", type="value", ) # Map choice labels gr.Markdown("*Select a published platform preset or enter your own calibration data.*") with gr.Group(visible=False) as scalar_params: gr.Markdown("##### Scalar Parameters") with gr.Row(): c1 = gr.Number(label="c(α=1) — coherence retention per MCM cycle", value=0.9951, precision=4) s = gr.Number(label="s — ancilla survival per cycle", value=0.9894, precision=4) Fm = gr.Number(label="F_max — peak ancilla fidelity", value=0.9972, precision=4) with gr.Accordion("Advanced", open=False): with gr.Row(): c0 = gr.Number(label="c(α=0)",value=0.9998,precision=4) kR = gr.Number(label="k_R (saturation rate)",value=7.0,precision=2) with gr.Group(visible=False) as curve_upload: gr.Markdown("##### Upload Calibration Curves") gr.Markdown(f"""Upload a CSV with columns: `alpha`, `c_alpha`, `F_alpha` (required) + `I_gain`, `s_alpha` (optional).
CSV template (click to expand) ``` {CSV_TEMPLATE} ```
🔒 Your data is processed in memory only — never stored or logged.""") curves_file = gr.File(label="Calibration curves CSV", file_types=[".csv"]) with gr.Accordion("Simulation thresholds (optional)", open=False): with gr.Row(): I_floor = gr.Number(label="I_floor",value=1e-4,precision=6) F_min = gr.Number(label="F_min", value=0.90, precision=3) hw_choice.change(fn=toggle_custom, inputs=[hw_choice], outputs=[scalar_params, curve_upload]) with gr.Tabs(): with gr.Tab("Quick Diagnosis"): btn_diag = gr.Button("Run Diagnosis", variant="primary") out_diag = gr.Textbox(label="Diagnosis Report", lines=18) btn_diag.click( fn=run_diagnosis, inputs=[hw_choice, c1, s, Fm, c0, kR, I_floor, F_min, curves_file], outputs=out_diag ) with gr.Tab("Full Schedule"): with gr.Row(): n_cyc = gr.Slider(label="n_cycles", minimum=50, maximum=500, value=200, step=10) n_sh = gr.Slider(label="Monte Carlo shots", minimum=50, maximum=500, value=200, step=50) mode = gr.Radio(label="Mode", choices=["wall_aware","diagnostic"], value="wall_aware") btn_sched = gr.Button("Generate Schedule", variant="primary") with gr.Row(): out_sum = gr.Textbox(label="Schedule Report", lines=22) out_csv = gr.File(label="Download α Schedule (CSV)") btn_sched.click( fn=run_schedule, inputs=[hw_choice, c1, s, Fm, c0, kR, I_floor, F_min, curves_file, n_cyc, n_sh, mode], outputs=[out_sum, out_csv] ) with gr.Tab("About"): gr.Markdown(f""" ### VPP Quantum Scheduler v4.0 The VPP (Variational Principle of Persistence) Quantum Scheduler optimizes mid-circuit measurement protocols for neutral atom quantum computers. **What makes it different** Standard compilers treat measurement strength as fixed (α=1). VPP treats α as a per-cycle optimization variable, extending coherent circuit lifetime while maintaining ancilla fidelity above a threshold. **Demonstrated performance** Using published data (Atom Computing, Muniz et al. 2025): - **2.93× extension** of coherent circuit half-life - Bottleneck diagnosis: coherence vs IC wall vs ancilla survival **Hardware support** | Platform | Type | Status | |---|---|---| | Atom Computing (Muniz 2025) | Neutral atoms | ✓ Preset | | Quantinuum H2 (Moses 2023) | Trapped ions | ✓ Preset | | QuEra Aquila (Bluvstein 2023) | Neutral atoms | ✓ Preset | | Any platform | Any | ✓ Upload CSV | **Privacy** Calibration data uploaded by clients is processed entirely in server RAM. It is never written to disk, logged, or retained after the request completes. **Contact** Email: albertoduarte@paradoxsystems.xyz WhatsApp: +526122173332 (Alberto Alejandro Duarte) *Method IP protected — Paradox Systems R&D* """) login_btn.click(fn=login, inputs=[pwd_input], outputs=[login_screen, main_screen, login_err]) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)