Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,14 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import time
|
|
|
|
|
|
|
| 5 |
|
| 6 |
BASE_URL = "https://lap-quantum-qpu-1-api.hf.space"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def run_on_qpu(code, timeout=120):
|
| 9 |
-
"""Execute quantum code on QPU-1"""
|
| 10 |
try:
|
| 11 |
resp = requests.post(
|
| 12 |
f"{BASE_URL}/script",
|
|
@@ -34,171 +37,92 @@ def run_bell_state():
|
|
| 34 |
def run_ghz(n_qubits):
|
| 35 |
n = int(n_qubits)
|
| 36 |
cnots = "\n".join([f"q.CNOT(0, {i})" for i in range(1, n)])
|
| 37 |
-
|
| 38 |
-
return run_on_qpu(code)
|
| 39 |
|
| 40 |
def run_superposition(n_qubits):
|
| 41 |
n = int(n_qubits)
|
| 42 |
-
code = f"
|
| 43 |
-
q.H_all()
|
| 44 |
-
result = q.measure()
|
| 45 |
-
print(f'Result: {{result[:80]}}...')
|
| 46 |
-
print(f'Total qubits: {n}')
|
| 47 |
-
print(f'Ones: {{result.count("1")}}/{n}')"""
|
| 48 |
return run_on_qpu(code)
|
| 49 |
|
| 50 |
def run_bell_correlation(trials):
|
| 51 |
n = int(trials)
|
| 52 |
-
code = f"
|
| 53 |
-
corr=0
|
| 54 |
-
for _ in range(n):
|
| 55 |
-
q=Qreg(2)
|
| 56 |
-
q.H(0)
|
| 57 |
-
q.CNOT(0,1)
|
| 58 |
-
r=q.measure()
|
| 59 |
-
if r in['00','11']:
|
| 60 |
-
corr+=1
|
| 61 |
-
print(f'Correlation: {{corr/n*100:.1f}}%')
|
| 62 |
-
print(f'Correlated pairs: {{corr}}/{n}')
|
| 63 |
-
print(f'Expected (perfect entanglement): 100%')"""
|
| 64 |
return run_on_qpu(code)
|
| 65 |
|
| 66 |
def run_long_range(n_qubits):
|
| 67 |
n = int(n_qubits)
|
| 68 |
-
code = f"
|
| 69 |
-
q = Qreg({n})
|
| 70 |
-
q.H(0)
|
| 71 |
-
q.CNOT(0, {n-1})
|
| 72 |
-
start = time.time()
|
| 73 |
-
result = q.measure()
|
| 74 |
-
elapsed = time.time() - start
|
| 75 |
-
print(f'Qubits: {n:,}')
|
| 76 |
-
print(f'Measurement time: {{elapsed*1000:.1f}}ms')
|
| 77 |
-
print(f'Qubit 0: {{result[0]}}')
|
| 78 |
-
print(f'Qubit {n-1:,}: {{result[{n-1}]}}')
|
| 79 |
-
print(f'Entangled (correlated): {{result[0] == result[{n-1}]}}')"""
|
| 80 |
return run_on_qpu(code, timeout=300)
|
| 81 |
|
| 82 |
def run_benchmark():
|
| 83 |
-
code = "
|
| 84 |
-
q = Qreg(100000)
|
| 85 |
-
start = time.time()
|
| 86 |
-
for _ in range(1000):
|
| 87 |
-
q.H(0)
|
| 88 |
-
elapsed = time.time() - start
|
| 89 |
-
print(f'1000 H gates on 100K qubit register')
|
| 90 |
-
print(f'Time: {elapsed*1000:.1f}ms')
|
| 91 |
-
print(f'Gate speed: {1000/elapsed/1e6:.1f}M gates/s')"""
|
| 92 |
return run_on_qpu(code)
|
| 93 |
|
| 94 |
def run_teleportation():
|
| 95 |
-
code = "
|
| 96 |
-
q.X(0)
|
| 97 |
-
q.H(1)
|
| 98 |
-
q.CNOT(1, 2)
|
| 99 |
-
q.CNOT(0, 1)
|
| 100 |
-
q.H(0)
|
| 101 |
-
result = q.measure()
|
| 102 |
-
print(f'Full state: {result}')
|
| 103 |
-
print(f'Qubit 0 (measured): {result[0]}')
|
| 104 |
-
print(f'Qubit 1 (measured): {result[1]}')
|
| 105 |
-
print(f'Qubit 2 (teleported): {result[2]}')"""
|
| 106 |
return run_on_qpu(code)
|
| 107 |
|
| 108 |
def run_deutsch_jozsa():
|
| 109 |
-
code = "
|
| 110 |
-
q.X(1)
|
| 111 |
-
q.H(0)
|
| 112 |
-
q.H(1)
|
| 113 |
-
q.CNOT(0, 1)
|
| 114 |
-
q.H(0)
|
| 115 |
-
result = q.measure()
|
| 116 |
-
verdict = 'BALANCED' if result[0] == '1' else 'CONSTANT'
|
| 117 |
-
print(f'Measurement: {result}')
|
| 118 |
-
print(f'Function is: {verdict}')"""
|
| 119 |
return run_on_qpu(code)
|
| 120 |
|
| 121 |
def run_bernstein_vazirani():
|
| 122 |
-
code = "
|
| 123 |
-
q.X(3)
|
| 124 |
-
q.H(0)
|
| 125 |
-
q.H(1)
|
| 126 |
-
q.H(2)
|
| 127 |
-
q.H(3)
|
| 128 |
-
q.CNOT(0, 3)
|
| 129 |
-
q.CNOT(2, 3)
|
| 130 |
-
q.H(0)
|
| 131 |
-
q.H(1)
|
| 132 |
-
q.H(2)
|
| 133 |
-
result = q.measure()
|
| 134 |
-
secret = result[:3]
|
| 135 |
-
print(f'Full measurement: {result}')
|
| 136 |
-
print(f'Recovered secret: {secret}')
|
| 137 |
-
print(f'Expected: 101')
|
| 138 |
-
print(f'Correct: {secret == "101"}')"""
|
| 139 |
return run_on_qpu(code)
|
| 140 |
|
| 141 |
def run_custom_code(code):
|
| 142 |
return run_on_qpu(code)
|
| 143 |
|
| 144 |
def run_all_experiments():
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
results.append(run_deutsch_jozsa())
|
| 178 |
-
|
| 179 |
-
results.append("\n[7] BERNSTEIN-VAZIRANI (secret=101)")
|
| 180 |
-
results.append("-" * 40)
|
| 181 |
-
results.append(run_bernstein_vazirani())
|
| 182 |
-
|
| 183 |
-
results.append("\n[8] LONG-RANGE ENTANGLEMENT (1M qubits)")
|
| 184 |
-
results.append("-" * 40)
|
| 185 |
-
results.append(run_long_range(1000000))
|
| 186 |
-
|
| 187 |
-
results.append("\n[9] GATE SPEED BENCHMARK")
|
| 188 |
-
results.append("-" * 40)
|
| 189 |
-
results.append(run_benchmark())
|
| 190 |
-
|
| 191 |
-
results.append("\n" + "=" * 60)
|
| 192 |
-
results.append(" ALL EXPERIMENTS COMPLETE!")
|
| 193 |
-
results.append("=" * 60)
|
| 194 |
-
return "\n".join(results)
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
# ===== RUN ON STARTUP =====
|
| 198 |
-
print("Running quantum experiments on QPU-1 at startup...")
|
| 199 |
STARTUP_RESULTS = run_all_experiments()
|
| 200 |
print(STARTUP_RESULTS)
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
|
| 204 |
CSS = """
|
|
@@ -208,70 +132,30 @@ CSS = """
|
|
| 208 |
|
| 209 |
with gr.Blocks(title="QPU-1 Experiments", css=CSS, theme=gr.themes.Soft()) as app:
|
| 210 |
gr.HTML("<h1 class='main-title'>⚛️ QPU-1 Experiments</h1>")
|
| 211 |
-
gr.HTML("<p class='subtitle'>
|
| 212 |
|
| 213 |
with gr.Tab("🚀 Run All"):
|
| 214 |
-
gr.Markdown("### Startup Results (ran
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
|
| 220 |
with gr.Tab("🔬 Individual"):
|
| 221 |
with gr.Row():
|
| 222 |
with gr.Column():
|
| 223 |
-
gr.Markdown("### Bell State")
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
gr.Markdown("### GHZ State")
|
| 229 |
-
ghz_n = gr.Slider(2, 20, value=5, step=1, label="Qubits")
|
| 230 |
-
ghz_btn = gr.Button("Run GHZ", variant="secondary")
|
| 231 |
-
ghz_out = gr.Textbox(lines=2)
|
| 232 |
-
ghz_btn.click(fn=run_ghz, inputs=ghz_n, outputs=ghz_out)
|
| 233 |
-
|
| 234 |
-
gr.Markdown("### Superposition")
|
| 235 |
-
sup_n = gr.Slider(1, 100, value=10, step=1, label="Qubits")
|
| 236 |
-
sup_btn = gr.Button("Run", variant="secondary")
|
| 237 |
-
sup_out = gr.Textbox(lines=3)
|
| 238 |
-
sup_btn.click(fn=run_superposition, inputs=sup_n, outputs=sup_out)
|
| 239 |
-
|
| 240 |
-
gr.Markdown("### Bell Correlation")
|
| 241 |
-
corr_n = gr.Slider(10, 500, value=100, step=10, label="Trials")
|
| 242 |
-
corr_btn = gr.Button("Test", variant="secondary")
|
| 243 |
-
corr_out = gr.Textbox(lines=3)
|
| 244 |
-
corr_btn.click(fn=run_bell_correlation, inputs=corr_n, outputs=corr_out)
|
| 245 |
-
|
| 246 |
with gr.Column():
|
| 247 |
-
gr.Markdown("### Teleportation")
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
gr.Markdown("### Deutsch-Jozsa")
|
| 253 |
-
dj_btn = gr.Button("Run", variant="secondary")
|
| 254 |
-
dj_out = gr.Textbox(lines=2)
|
| 255 |
-
dj_btn.click(fn=run_deutsch_jozsa, outputs=dj_out)
|
| 256 |
-
|
| 257 |
-
gr.Markdown("### Bernstein-Vazirani (s=101)")
|
| 258 |
-
bv_btn = gr.Button("Run", variant="secondary")
|
| 259 |
-
bv_out = gr.Textbox(lines=4)
|
| 260 |
-
bv_btn.click(fn=run_bernstein_vazirani, outputs=bv_out)
|
| 261 |
-
|
| 262 |
-
gr.Markdown("### Long-Range Entanglement")
|
| 263 |
-
lr_n = gr.Slider(1000, 1000000, value=1000000, step=1000, label="Qubits")
|
| 264 |
-
lr_btn = gr.Button("Run", variant="secondary")
|
| 265 |
-
lr_out = gr.Textbox(lines=5)
|
| 266 |
-
lr_btn.click(fn=run_long_range, inputs=lr_n, outputs=lr_out)
|
| 267 |
-
|
| 268 |
-
gr.Markdown("### Benchmark")
|
| 269 |
-
bench_btn = gr.Button("Run", variant="secondary")
|
| 270 |
-
bench_out = gr.Textbox(lines=3)
|
| 271 |
-
bench_btn.click(fn=run_benchmark, outputs=bench_out)
|
| 272 |
|
| 273 |
with gr.Tab("💻 Custom Code"):
|
| 274 |
-
gr.Markdown("Write your own quantum code for QPU-1 (`Qreg` API or QASM)")
|
| 275 |
code_input = gr.Code(language="python", lines=15, value="q = Qreg(3)\nq.H(0)\nq.CNOT(0, 1)\nq.CNOT(1, 2)\nprint(q.measure())")
|
| 276 |
custom_btn = gr.Button("▶️ Execute on QPU-1", variant="primary")
|
| 277 |
custom_out = gr.Textbox(label="Output", lines=8, show_copy_button=True)
|
|
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import time
|
| 5 |
+
import os
|
| 6 |
+
from huggingface_hub import HfApi
|
| 7 |
|
| 8 |
BASE_URL = "https://lap-quantum-qpu-1-api.hf.space"
|
| 9 |
+
HF_TOKEN = os.getenv("HF_TOKEN", "")
|
| 10 |
+
REPO_ID = "Reality123b/qpu1-experiments"
|
| 11 |
|
| 12 |
def run_on_qpu(code, timeout=120):
|
|
|
|
| 13 |
try:
|
| 14 |
resp = requests.post(
|
| 15 |
f"{BASE_URL}/script",
|
|
|
|
| 37 |
def run_ghz(n_qubits):
|
| 38 |
n = int(n_qubits)
|
| 39 |
cnots = "\n".join([f"q.CNOT(0, {i})" for i in range(1, n)])
|
| 40 |
+
return run_on_qpu(f"q = Qreg({n})\nq.H(0)\n{cnots}\nprint(q.measure())")
|
|
|
|
| 41 |
|
| 42 |
def run_superposition(n_qubits):
|
| 43 |
n = int(n_qubits)
|
| 44 |
+
code = f"q = Qreg({n})\nq.H_all()\nresult = q.measure()\nprint(f'Result: {{result[:80]}}...')\nprint(f'Total qubits: {n}')\nprint(f'Ones: {{result.count(\"1\")}}/{n}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return run_on_qpu(code)
|
| 46 |
|
| 47 |
def run_bell_correlation(trials):
|
| 48 |
n = int(trials)
|
| 49 |
+
code = f"n={n}\ncorr=0\nfor _ in range(n):\n q=Qreg(2)\n q.H(0)\n q.CNOT(0,1)\n r=q.measure()\n if r in['00','11']:corr+=1\nprint(f'Correlation: {{corr/n*100:.1f}}%')\nprint(f'Correlated pairs: {{corr}}/{n}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return run_on_qpu(code)
|
| 51 |
|
| 52 |
def run_long_range(n_qubits):
|
| 53 |
n = int(n_qubits)
|
| 54 |
+
code = f"import time\nq = Qreg({n})\nq.H(0)\nq.CNOT(0, {n-1})\nstart = time.time()\nresult = q.measure()\nelapsed = time.time() - start\nprint(f'Qubits: {n:,}')\nprint(f'Measurement time: {{elapsed*1000:.1f}}ms')\nprint(f'Qubit 0: {{result[0]}}')\nprint(f'Qubit {n-1:,}: {{result[{n-1}]}}')\nprint(f'Entangled: {{result[0] == result[{n-1}]}}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
return run_on_qpu(code, timeout=300)
|
| 56 |
|
| 57 |
def run_benchmark():
|
| 58 |
+
code = "import time\nq = Qreg(100000)\nstart = time.time()\nfor _ in range(1000):\n q.H(0)\nelapsed = time.time() - start\nprint(f'1000 H gates on 100K qubit register')\nprint(f'Time: {elapsed*1000:.1f}ms')\nprint(f'Gate speed: {1000/elapsed/1e6:.1f}M gates/s')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return run_on_qpu(code)
|
| 60 |
|
| 61 |
def run_teleportation():
|
| 62 |
+
code = "q = Qreg(3)\nq.X(0)\nq.H(1)\nq.CNOT(1, 2)\nq.CNOT(0, 1)\nq.H(0)\nresult = q.measure()\nprint(f'Full state: {result}')\nprint(f'Qubit 2 (teleported): {result[2]}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return run_on_qpu(code)
|
| 64 |
|
| 65 |
def run_deutsch_jozsa():
|
| 66 |
+
code = "q = Qreg(2)\nq.X(1)\nq.H(0)\nq.H(1)\nq.CNOT(0, 1)\nq.H(0)\nresult = q.measure()\nverdict = 'BALANCED' if result[0] == '1' else 'CONSTANT'\nprint(f'Measurement: {result}')\nprint(f'Function is: {verdict}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return run_on_qpu(code)
|
| 68 |
|
| 69 |
def run_bernstein_vazirani():
|
| 70 |
+
code = "q = Qreg(4)\nq.X(3)\nq.H(0)\nq.H(1)\nq.H(2)\nq.H(3)\nq.CNOT(0, 3)\nq.CNOT(2, 3)\nq.H(0)\nq.H(1)\nq.H(2)\nresult = q.measure()\nsecret = result[:3]\nprint(f'Full measurement: {result}')\nprint(f'Recovered secret: {secret}')\nprint(f'Expected: 101')\nprint(f'Correct: {secret == \"101\"}')"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return run_on_qpu(code)
|
| 72 |
|
| 73 |
def run_custom_code(code):
|
| 74 |
return run_on_qpu(code)
|
| 75 |
|
| 76 |
def run_all_experiments():
|
| 77 |
+
lines = []
|
| 78 |
+
lines.append("=" * 60)
|
| 79 |
+
lines.append(" QPU-1 QUANTUM PROCESSING UNIT — LIVE RESULTS")
|
| 80 |
+
lines.append(" Powered by Lap Quantum")
|
| 81 |
+
lines.append("=" * 60)
|
| 82 |
+
|
| 83 |
+
experiments = [
|
| 84 |
+
("[0] QPU-1 HEALTH", health_check),
|
| 85 |
+
("[1] BELL STATE (2 qubits)", run_bell_state),
|
| 86 |
+
("[2] GHZ STATE (5 qubits)", lambda: run_ghz(5)),
|
| 87 |
+
("[3] SUPERPOSITION (20 qubits)", lambda: run_superposition(20)),
|
| 88 |
+
("[4] BELL CORRELATION (50 trials)", lambda: run_bell_correlation(50)),
|
| 89 |
+
("[5] QUANTUM TELEPORTATION", run_teleportation),
|
| 90 |
+
("[6] DEUTSCH-JOZSA ALGORITHM", run_deutsch_jozsa),
|
| 91 |
+
("[7] BERNSTEIN-VAZIRANI (secret=101)", run_bernstein_vazirani),
|
| 92 |
+
("[8] LONG-RANGE ENTANGLEMENT (1M qubits)", lambda: run_long_range(1000000)),
|
| 93 |
+
("[9] GATE SPEED BENCHMARK", run_benchmark),
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
for title, fn in experiments:
|
| 97 |
+
lines.append(f"\n{title}")
|
| 98 |
+
lines.append("-" * 40)
|
| 99 |
+
lines.append(fn())
|
| 100 |
+
|
| 101 |
+
lines.append("\n" + "=" * 60)
|
| 102 |
+
lines.append(" ALL EXPERIMENTS COMPLETE!")
|
| 103 |
+
lines.append("=" * 60)
|
| 104 |
+
return "\n".join(lines)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# ===== RUN ON STARTUP & SAVE RESULTS =====
|
| 108 |
+
print(">>> Running quantum experiments on QPU-1...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
STARTUP_RESULTS = run_all_experiments()
|
| 110 |
print(STARTUP_RESULTS)
|
| 111 |
+
|
| 112 |
+
# Save results to repo so they can be read
|
| 113 |
+
try:
|
| 114 |
+
with open("/tmp/results.txt", "w") as f:
|
| 115 |
+
f.write(STARTUP_RESULTS)
|
| 116 |
+
api = HfApi(token=HF_TOKEN)
|
| 117 |
+
api.upload_file(
|
| 118 |
+
path_or_fileobj="/tmp/results.txt",
|
| 119 |
+
path_in_repo="results.txt",
|
| 120 |
+
repo_id=REPO_ID,
|
| 121 |
+
repo_type="space",
|
| 122 |
+
)
|
| 123 |
+
print(">>> Results saved to results.txt in repo!")
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print(f">>> Could not save results: {e}")
|
| 126 |
|
| 127 |
|
| 128 |
CSS = """
|
|
|
|
| 132 |
|
| 133 |
with gr.Blocks(title="QPU-1 Experiments", css=CSS, theme=gr.themes.Soft()) as app:
|
| 134 |
gr.HTML("<h1 class='main-title'>⚛️ QPU-1 Experiments</h1>")
|
| 135 |
+
gr.HTML("<p class='subtitle'>Real quantum circuits on Lap Quantum's QPU-1</p>")
|
| 136 |
|
| 137 |
with gr.Tab("🚀 Run All"):
|
| 138 |
+
gr.Markdown("### Startup Results (ran when Space loaded)")
|
| 139 |
+
startup_box = gr.Textbox(label="Results", lines=45, value=STARTUP_RESULTS, show_copy_button=True)
|
| 140 |
+
rerun_btn = gr.Button("🔄 Re-run All", variant="primary", size="lg")
|
| 141 |
+
fresh_box = gr.Textbox(label="Fresh Results", lines=45, show_copy_button=True)
|
| 142 |
+
rerun_btn.click(fn=run_all_experiments, outputs=fresh_box)
|
| 143 |
|
| 144 |
with gr.Tab("🔬 Individual"):
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Column():
|
| 147 |
+
gr.Markdown("### Bell State"); bell_btn = gr.Button("Run"); bell_out = gr.Textbox(lines=2); bell_btn.click(fn=run_bell_state, outputs=bell_out)
|
| 148 |
+
gr.Markdown("### GHZ State"); ghz_n = gr.Slider(2, 20, value=5, step=1, label="Qubits"); ghz_btn = gr.Button("Run GHZ"); ghz_out = gr.Textbox(lines=2); ghz_btn.click(fn=run_ghz, inputs=ghz_n, outputs=ghz_out)
|
| 149 |
+
gr.Markdown("### Superposition"); sup_n = gr.Slider(1, 100, value=10, step=1, label="Qubits"); sup_btn = gr.Button("Run"); sup_out = gr.Textbox(lines=3); sup_btn.click(fn=run_superposition, inputs=sup_n, outputs=sup_out)
|
| 150 |
+
gr.Markdown("### Bell Correlation"); corr_n = gr.Slider(10, 500, value=100, step=10, label="Trials"); corr_btn = gr.Button("Test"); corr_out = gr.Textbox(lines=3); corr_btn.click(fn=run_bell_correlation, inputs=corr_n, outputs=corr_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
with gr.Column():
|
| 152 |
+
gr.Markdown("### Teleportation"); tp_btn = gr.Button("Run"); tp_out = gr.Textbox(lines=3); tp_btn.click(fn=run_teleportation, outputs=tp_out)
|
| 153 |
+
gr.Markdown("### Deutsch-Jozsa"); dj_btn = gr.Button("Run"); dj_out = gr.Textbox(lines=2); dj_btn.click(fn=run_deutsch_jozsa, outputs=dj_out)
|
| 154 |
+
gr.Markdown("### Bernstein-Vazirani"); bv_btn = gr.Button("Run"); bv_out = gr.Textbox(lines=4); bv_btn.click(fn=run_bernstein_vazirani, outputs=bv_out)
|
| 155 |
+
gr.Markdown("### Long-Range (1M qubits)"); lr_n = gr.Slider(1000, 1000000, value=1000000, step=1000, label="Qubits"); lr_btn = gr.Button("Run"); lr_out = gr.Textbox(lines=5); lr_btn.click(fn=run_long_range, inputs=lr_n, outputs=lr_out)
|
| 156 |
+
gr.Markdown("### Benchmark"); bench_btn = gr.Button("Run"); bench_out = gr.Textbox(lines=3); bench_btn.click(fn=run_benchmark, outputs=bench_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
with gr.Tab("💻 Custom Code"):
|
|
|
|
| 159 |
code_input = gr.Code(language="python", lines=15, value="q = Qreg(3)\nq.H(0)\nq.CNOT(0, 1)\nq.CNOT(1, 2)\nprint(q.measure())")
|
| 160 |
custom_btn = gr.Button("▶️ Execute on QPU-1", variant="primary")
|
| 161 |
custom_out = gr.Textbox(label="Output", lines=8, show_copy_button=True)
|