Upload folder using huggingface_hub
Browse files- server/app.py +31 -31
server/app.py
CHANGED
|
@@ -251,7 +251,7 @@ def do_step(action_type, gate_type, qubit_0, qubit_1, parameter):
|
|
| 251 |
TASK_DESCRIPTIONS = {
|
| 252 |
"Bell State (Easy)": {
|
| 253 |
"description": "Create the famous Bell state: (|00⟩ + |11⟩)/√2",
|
| 254 |
-
"difficulty": "
|
| 255 |
"qubits": 2,
|
| 256 |
"noise": "None",
|
| 257 |
"connectivity": "Full",
|
|
@@ -259,7 +259,7 @@ TASK_DESCRIPTIONS = {
|
|
| 259 |
},
|
| 260 |
"GHZ State (Medium)": {
|
| 261 |
"description": "Build a 3-qubit GHZ state: (|000⟩ + |111⟩)/√2",
|
| 262 |
-
"difficulty": "
|
| 263 |
"qubits": 3,
|
| 264 |
"noise": "Depolarizing",
|
| 265 |
"connectivity": "Linear (0↔1↔2)",
|
|
@@ -267,7 +267,7 @@ TASK_DESCRIPTIONS = {
|
|
| 267 |
},
|
| 268 |
"Unitary Approx (Hard)": {
|
| 269 |
"description": "Approximate a complex unitary: Ry(π/3) ⊗ Rz(π/4) · CNOT",
|
| 270 |
-
"difficulty": "
|
| 271 |
"qubits": 2,
|
| 272 |
"noise": "Thermal",
|
| 273 |
"connectivity": "Restricted",
|
|
@@ -275,7 +275,7 @@ TASK_DESCRIPTIONS = {
|
|
| 275 |
},
|
| 276 |
"Imperfect but Efficient": {
|
| 277 |
"description": "GHZ state with emphasis on circuit efficiency",
|
| 278 |
-
"difficulty": "
|
| 279 |
"qubits": 3,
|
| 280 |
"noise": "None",
|
| 281 |
"connectivity": "Full",
|
|
@@ -283,7 +283,7 @@ TASK_DESCRIPTIONS = {
|
|
| 283 |
},
|
| 284 |
"Noise-Dominant": {
|
| 285 |
"description": "Bell state optimized for noise resilience",
|
| 286 |
-
"difficulty": "
|
| 287 |
"qubits": 2,
|
| 288 |
"noise": "Thermal (High)",
|
| 289 |
"connectivity": "Full",
|
|
@@ -291,7 +291,7 @@ TASK_DESCRIPTIONS = {
|
|
| 291 |
},
|
| 292 |
"Budgeted Optimization": {
|
| 293 |
"description": "GHZ state with strict 3-gate budget",
|
| 294 |
-
"difficulty": "
|
| 295 |
"qubits": 3,
|
| 296 |
"noise": "None",
|
| 297 |
"connectivity": "Full",
|
|
@@ -299,7 +299,7 @@ TASK_DESCRIPTIONS = {
|
|
| 299 |
},
|
| 300 |
"Approximate Target": {
|
| 301 |
"description": "4-qubit GHZ with relaxed fidelity threshold (0.80)",
|
| 302 |
-
"difficulty": "
|
| 303 |
"qubits": 4,
|
| 304 |
"noise": "None",
|
| 305 |
"connectivity": "Full",
|
|
@@ -324,12 +324,12 @@ ACTION_DESCRIPTIONS = {
|
|
| 324 |
}
|
| 325 |
|
| 326 |
def create_gradio_app() -> gr.Blocks:
|
| 327 |
-
with gr.Blocks(title="
|
| 328 |
|
| 329 |
# Header
|
| 330 |
gr.Markdown(
|
| 331 |
"""
|
| 332 |
-
#
|
| 333 |
### Build quantum circuits step-by-step to maximize fidelity with target states
|
| 334 |
|
| 335 |
**Goal:** Design circuits that are accurate, efficient, noise-resistant, and hardware-compliant.
|
|
@@ -337,24 +337,24 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 337 |
)
|
| 338 |
|
| 339 |
# Task Selection Section
|
| 340 |
-
with gr.Accordion("
|
| 341 |
gr.Markdown(
|
| 342 |
"""
|
| 343 |
Choose a task below to start optimizing. Each task has different constraints:
|
| 344 |
|
| 345 |
| Task | Difficulty | Qubits | Noise | Connectivity | Focus |
|
| 346 |
|------|------------|--------|-------|--------------|-------|
|
| 347 |
-
| **Bell State** |
|
| 348 |
-
| **GHZ State** |
|
| 349 |
-
| **Unitary Approx** |
|
| 350 |
-
| **Efficient** |
|
| 351 |
-
| **Noise-Dominant** |
|
| 352 |
-
| **Budgeted** |
|
| 353 |
-
| **Approximate** |
|
| 354 |
"""
|
| 355 |
)
|
| 356 |
|
| 357 |
-
with gr.Accordion("
|
| 358 |
gr.Markdown(
|
| 359 |
"""
|
| 360 |
### How to Use:
|
|
@@ -378,7 +378,7 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 378 |
gr.Markdown("---")
|
| 379 |
|
| 380 |
# Step 1: Task Selection
|
| 381 |
-
gr.Markdown("###
|
| 382 |
with gr.Row():
|
| 383 |
with gr.Column(scale=3):
|
| 384 |
task_dd = gr.Dropdown(
|
|
@@ -388,7 +388,7 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 388 |
info="Select the optimization challenge you want to solve"
|
| 389 |
)
|
| 390 |
with gr.Column(scale=1):
|
| 391 |
-
reset_btn = gr.Button("
|
| 392 |
|
| 393 |
# Task info display
|
| 394 |
task_info = gr.Markdown("")
|
|
@@ -400,7 +400,7 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 400 |
|
| 401 |
{info.get('description', '')}
|
| 402 |
|
| 403 |
-
|
| 404 |
"""
|
| 405 |
|
| 406 |
task_dd.change(fn=update_task_info, inputs=[task_dd], outputs=[task_info])
|
|
@@ -408,7 +408,7 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 408 |
gr.Markdown("---")
|
| 409 |
|
| 410 |
# Step 2: Circuit Building
|
| 411 |
-
gr.Markdown("###
|
| 412 |
|
| 413 |
with gr.Row():
|
| 414 |
with gr.Column():
|
|
@@ -454,52 +454,52 @@ def create_gradio_app() -> gr.Blocks:
|
|
| 454 |
)
|
| 455 |
|
| 456 |
with gr.Row():
|
| 457 |
-
step_btn = gr.Button("
|
| 458 |
-
state_btn = gr.Button("
|
| 459 |
|
| 460 |
gr.Markdown("---")
|
| 461 |
|
| 462 |
# Step 3: Monitor Progress
|
| 463 |
-
gr.Markdown("###
|
| 464 |
|
| 465 |
with gr.Row():
|
| 466 |
with gr.Column():
|
| 467 |
status_out = gr.Textbox(
|
| 468 |
-
label="
|
| 469 |
lines=4,
|
| 470 |
interactive=False,
|
| 471 |
placeholder="Click 'Reset Environment' to start..."
|
| 472 |
)
|
| 473 |
scores_out = gr.Textbox(
|
| 474 |
-
label="
|
| 475 |
lines=6,
|
| 476 |
interactive=False
|
| 477 |
)
|
| 478 |
|
| 479 |
with gr.Column():
|
| 480 |
circuit_out = gr.Textbox(
|
| 481 |
-
label="
|
| 482 |
lines=10,
|
| 483 |
interactive=False,
|
| 484 |
placeholder="Your circuit will appear here..."
|
| 485 |
)
|
| 486 |
|
| 487 |
history_out = gr.Textbox(
|
| 488 |
-
label="
|
| 489 |
lines=8,
|
| 490 |
interactive=False,
|
| 491 |
placeholder="Action history will be logged here..."
|
| 492 |
)
|
| 493 |
|
| 494 |
# Advanced: Full State
|
| 495 |
-
with gr.Accordion("
|
| 496 |
state_out = gr.JSON(label="Complete State Dump")
|
| 497 |
|
| 498 |
# Footer
|
| 499 |
gr.Markdown(
|
| 500 |
"""
|
| 501 |
---
|
| 502 |
-
|
| 503 |
- Start simple: H on qubit 0, then CNOT(0,1) creates a Bell state
|
| 504 |
- Watch the fidelity score — aim for >0.90 on easy tasks
|
| 505 |
- Fewer gates = better efficiency and noise scores
|
|
|
|
| 251 |
TASK_DESCRIPTIONS = {
|
| 252 |
"Bell State (Easy)": {
|
| 253 |
"description": "Create the famous Bell state: (|00⟩ + |11⟩)/√2",
|
| 254 |
+
"difficulty": "Easy",
|
| 255 |
"qubits": 2,
|
| 256 |
"noise": "None",
|
| 257 |
"connectivity": "Full",
|
|
|
|
| 259 |
},
|
| 260 |
"GHZ State (Medium)": {
|
| 261 |
"description": "Build a 3-qubit GHZ state: (|000⟩ + |111⟩)/√2",
|
| 262 |
+
"difficulty": "Medium",
|
| 263 |
"qubits": 3,
|
| 264 |
"noise": "Depolarizing",
|
| 265 |
"connectivity": "Linear (0↔1↔2)",
|
|
|
|
| 267 |
},
|
| 268 |
"Unitary Approx (Hard)": {
|
| 269 |
"description": "Approximate a complex unitary: Ry(π/3) ⊗ Rz(π/4) · CNOT",
|
| 270 |
+
"difficulty": "Hard",
|
| 271 |
"qubits": 2,
|
| 272 |
"noise": "Thermal",
|
| 273 |
"connectivity": "Restricted",
|
|
|
|
| 275 |
},
|
| 276 |
"Imperfect but Efficient": {
|
| 277 |
"description": "GHZ state with emphasis on circuit efficiency",
|
| 278 |
+
"difficulty": "Medium",
|
| 279 |
"qubits": 3,
|
| 280 |
"noise": "None",
|
| 281 |
"connectivity": "Full",
|
|
|
|
| 283 |
},
|
| 284 |
"Noise-Dominant": {
|
| 285 |
"description": "Bell state optimized for noise resilience",
|
| 286 |
+
"difficulty": "Medium",
|
| 287 |
"qubits": 2,
|
| 288 |
"noise": "Thermal (High)",
|
| 289 |
"connectivity": "Full",
|
|
|
|
| 291 |
},
|
| 292 |
"Budgeted Optimization": {
|
| 293 |
"description": "GHZ state with strict 3-gate budget",
|
| 294 |
+
"difficulty": "Medium",
|
| 295 |
"qubits": 3,
|
| 296 |
"noise": "None",
|
| 297 |
"connectivity": "Full",
|
|
|
|
| 299 |
},
|
| 300 |
"Approximate Target": {
|
| 301 |
"description": "4-qubit GHZ with relaxed fidelity threshold (0.80)",
|
| 302 |
+
"difficulty": "Medium",
|
| 303 |
"qubits": 4,
|
| 304 |
"noise": "None",
|
| 305 |
"connectivity": "Full",
|
|
|
|
| 324 |
}
|
| 325 |
|
| 326 |
def create_gradio_app() -> gr.Blocks:
|
| 327 |
+
with gr.Blocks(title="Quantum Circuit Optimizer", theme=gr.themes.Soft()) as demo:
|
| 328 |
|
| 329 |
# Header
|
| 330 |
gr.Markdown(
|
| 331 |
"""
|
| 332 |
+
# Quantum Circuit Optimizer
|
| 333 |
### Build quantum circuits step-by-step to maximize fidelity with target states
|
| 334 |
|
| 335 |
**Goal:** Design circuits that are accurate, efficient, noise-resistant, and hardware-compliant.
|
|
|
|
| 337 |
)
|
| 338 |
|
| 339 |
# Task Selection Section
|
| 340 |
+
with gr.Accordion("Available Tasks & Challenges", open=False):
|
| 341 |
gr.Markdown(
|
| 342 |
"""
|
| 343 |
Choose a task below to start optimizing. Each task has different constraints:
|
| 344 |
|
| 345 |
| Task | Difficulty | Qubits | Noise | Connectivity | Focus |
|
| 346 |
|------|------------|--------|-------|--------------|-------|
|
| 347 |
+
| **Bell State** | Easy | 2 | None | Full | Basic entanglement |
|
| 348 |
+
| **GHZ State** | Medium | 3 | Depolarizing | Linear | Noise + topology |
|
| 349 |
+
| **Unitary Approx** | Hard | 2 | Thermal | Restricted | Parametric tuning |
|
| 350 |
+
| **Efficient** | Medium | 3 | None | Full | Minimize depth/gates |
|
| 351 |
+
| **Noise-Dominant** | Medium | 2 | High thermal | Full | Noise resilience |
|
| 352 |
+
| **Budgeted** | Medium | 3 | None | Full | 3-gate limit |
|
| 353 |
+
| **Approximate** | Medium | 4 | None | Full | Scale to 4 qubits |
|
| 354 |
"""
|
| 355 |
)
|
| 356 |
|
| 357 |
+
with gr.Accordion("Quick Start Guide", open=False):
|
| 358 |
gr.Markdown(
|
| 359 |
"""
|
| 360 |
### How to Use:
|
|
|
|
| 378 |
gr.Markdown("---")
|
| 379 |
|
| 380 |
# Step 1: Task Selection
|
| 381 |
+
gr.Markdown("### Step 1: Select Task")
|
| 382 |
with gr.Row():
|
| 383 |
with gr.Column(scale=3):
|
| 384 |
task_dd = gr.Dropdown(
|
|
|
|
| 388 |
info="Select the optimization challenge you want to solve"
|
| 389 |
)
|
| 390 |
with gr.Column(scale=1):
|
| 391 |
+
reset_btn = gr.Button("Reset Environment", variant="primary", size="lg")
|
| 392 |
|
| 393 |
# Task info display
|
| 394 |
task_info = gr.Markdown("")
|
|
|
|
| 400 |
|
| 401 |
{info.get('description', '')}
|
| 402 |
|
| 403 |
+
**Goal:** {info.get('goal', '')}
|
| 404 |
"""
|
| 405 |
|
| 406 |
task_dd.change(fn=update_task_info, inputs=[task_dd], outputs=[task_info])
|
|
|
|
| 408 |
gr.Markdown("---")
|
| 409 |
|
| 410 |
# Step 2: Circuit Building
|
| 411 |
+
gr.Markdown("### Step 2: Build Your Circuit")
|
| 412 |
|
| 413 |
with gr.Row():
|
| 414 |
with gr.Column():
|
|
|
|
| 454 |
)
|
| 455 |
|
| 456 |
with gr.Row():
|
| 457 |
+
step_btn = gr.Button("Execute Step", variant="primary", size="lg", scale=2)
|
| 458 |
+
state_btn = gr.Button("Get Full State", variant="secondary", scale=1)
|
| 459 |
|
| 460 |
gr.Markdown("---")
|
| 461 |
|
| 462 |
# Step 3: Monitor Progress
|
| 463 |
+
gr.Markdown("### Step 3: Monitor Your Progress")
|
| 464 |
|
| 465 |
with gr.Row():
|
| 466 |
with gr.Column():
|
| 467 |
status_out = gr.Textbox(
|
| 468 |
+
label="Current Status",
|
| 469 |
lines=4,
|
| 470 |
interactive=False,
|
| 471 |
placeholder="Click 'Reset Environment' to start..."
|
| 472 |
)
|
| 473 |
scores_out = gr.Textbox(
|
| 474 |
+
label="Score Breakdown",
|
| 475 |
lines=6,
|
| 476 |
interactive=False
|
| 477 |
)
|
| 478 |
|
| 479 |
with gr.Column():
|
| 480 |
circuit_out = gr.Textbox(
|
| 481 |
+
label="Current Circuit",
|
| 482 |
lines=10,
|
| 483 |
interactive=False,
|
| 484 |
placeholder="Your circuit will appear here..."
|
| 485 |
)
|
| 486 |
|
| 487 |
history_out = gr.Textbox(
|
| 488 |
+
label="Step History",
|
| 489 |
lines=8,
|
| 490 |
interactive=False,
|
| 491 |
placeholder="Action history will be logged here..."
|
| 492 |
)
|
| 493 |
|
| 494 |
# Advanced: Full State
|
| 495 |
+
with gr.Accordion("Advanced: Full Environment State", open=False):
|
| 496 |
state_out = gr.JSON(label="Complete State Dump")
|
| 497 |
|
| 498 |
# Footer
|
| 499 |
gr.Markdown(
|
| 500 |
"""
|
| 501 |
---
|
| 502 |
+
**Tips:**
|
| 503 |
- Start simple: H on qubit 0, then CNOT(0,1) creates a Bell state
|
| 504 |
- Watch the fidelity score — aim for >0.90 on easy tasks
|
| 505 |
- Fewer gates = better efficiency and noise scores
|