raayraay commited on
Commit
22820b3
·
verified ·
1 Parent(s): 7d20fcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -1,7 +1,6 @@
1
  """
2
  Quantum Paradox Lab
3
  Interactive demos proving quantum's future is architecture over qubit counts.
4
-
5
  Explores: Barren Plateaus, QSVT Unification, Photonic Blueprints, AI Circuit Design
6
  """
7
 
@@ -135,7 +134,8 @@ def simulate_barren_plateau(num_qubits, num_layers, num_samples=100):
135
  np.random.seed(42)
136
 
137
  qubit_range = range(2, num_qubits + 1)
138
- layer_configs = [1, num_layers // 2, num_layers]
 
139
 
140
  results = []
141
  for n_qubits in qubit_range:
@@ -166,7 +166,10 @@ def create_barren_plateau_chart(num_qubits, num_layers):
166
  specs=[[{"type": "scatter"}, {"type": "heatmap"}]]
167
  )
168
 
169
- for n_layers in [1, num_layers // 2, num_layers]:
 
 
 
170
  layer_data = [r for r in results if r["layers"] == n_layers]
171
  fig.add_trace(
172
  go.Scatter(
@@ -390,49 +393,38 @@ def generate_circuit_description(problem_type, num_qubits):
390
  "QAOA (Max-Cut)": f"""
391
  # QAOA Circuit for {num_qubits}-qubit Max-Cut
392
  # Layers: 2, Parameters: {num_qubits * 4}
393
-
394
  OPENQASM 3.0;
395
  include "stdgates.inc";
396
-
397
  qubit[{num_qubits}] q;
398
  bit[{num_qubits}] c;
399
-
400
  // Initial superposition
401
  for int i in [0:{num_qubits-1}] {{ h q[i]; }}
402
-
403
  // Cost layer (problem-dependent ZZ interactions)
404
  for int i in [0:{num_qubits-2}] {{
405
  cx q[i], q[i+1];
406
  rz(gamma) q[i+1];
407
  cx q[i], q[i+1];
408
  }}
409
-
410
  // Mixer layer
411
  for int i in [0:{num_qubits-1}] {{ rx(beta) q[i]; }}
412
-
413
  // Measurement
414
  c = measure q;
415
  """,
416
  "VQE (H2 Molecule)": f"""
417
  # VQE Ansatz for Molecular Simulation
418
  # Qubits: {num_qubits}, Parameters: {num_qubits * 2}
419
-
420
  OPENQASM 3.0;
421
  include "stdgates.inc";
422
-
423
  qubit[{num_qubits}] q;
424
-
425
  // Hardware-efficient ansatz
426
  for int i in [0:{num_qubits-1}] {{
427
  ry(theta[i]) q[i];
428
  rz(phi[i]) q[i];
429
  }}
430
-
431
  // Entangling layer
432
  for int i in [0:{num_qubits-2}] {{
433
  cx q[i], q[i+1];
434
  }}
435
-
436
  // Second rotation layer
437
  for int i in [0:{num_qubits-1}] {{
438
  ry(theta2[i]) q[i];
@@ -441,18 +433,14 @@ for int i in [0:{num_qubits-1}] {{
441
  "Grover's Search": f"""
442
  # Grover's Algorithm for {num_qubits}-qubit search
443
  # Iterations: {int(np.pi/4 * np.sqrt(2**num_qubits))}
444
-
445
  OPENQASM 3.0;
446
  include "stdgates.inc";
447
-
448
  qubit[{num_qubits}] q;
449
  qubit ancilla;
450
-
451
  // Initialize
452
  for int i in [0:{num_qubits-1}] {{ h q[i]; }}
453
  x ancilla;
454
  h ancilla;
455
-
456
  // Grover iterations
457
  for int iter in [0:{int(np.pi/4 * np.sqrt(2**num_qubits))-1}] {{
458
  // Oracle (problem-specific)
@@ -478,51 +466,43 @@ def get_algorithm_details(algo_name):
478
  Algorithm: {algo_name}
479
  Year Discovered: {data['year']}
480
  Speedup Type: {data['speedup']}
481
-
482
  Problem Solved: {data['problem']}
483
  Classical Complexity: {data['classical']}
484
  Quantum Complexity: {data['quantum']}
485
-
486
  QSVT Polynomial: {data['polynomial']}
487
-
488
  How QSVT Unifies This:
489
  QSVT represents this algorithm as a polynomial transformation
490
  of singular values. The specific polynomial ({data['polynomial']})
491
  is implemented via a sequence of signal processing rotations.
492
-
493
  This means: ONE framework, ONE circuit template, MANY algorithms.
494
  """
495
 
496
  CSS = """
497
  @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Orbitron:wght@400;700&display=swap');
498
-
499
  .gradio-container {
500
  background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 50%, #0a1a1a 100%) !important;
501
  }
502
-
503
  h1, h2, h3 {
504
  font-family: 'Orbitron', sans-serif !important;
505
  color: #00ffcc !important;
506
  text-shadow: 0 0 30px rgba(0, 255, 204, 0.4);
507
  }
508
-
509
  .tab-nav button.selected {
510
  background: linear-gradient(135deg, #00ffcc, #00cc99) !important;
511
  color: #0a0a1a !important;
512
  }
513
-
514
  button.primary {
515
  background: linear-gradient(135deg, #00ffcc, #00cc99) !important;
516
  color: #0a0a1a !important;
517
  }
518
-
519
  .prose code {
520
  background: #1a1a2e !important;
521
  color: #00ffcc !important;
522
  }
523
  """
524
 
525
- with gr.Blocks(title="Quantum Paradox Lab") as demo:
 
526
 
527
  gr.Markdown("""
528
  # Quantum Paradox Lab
@@ -717,7 +697,7 @@ with gr.Blocks(title="Quantum Paradox Lab") as demo:
717
 
718
  ---
719
 
720
- **Created by:** Eric Raymond | Purdue AI/Robotics Engineering
721
  """)
722
 
723
  gr.Markdown("""
@@ -728,4 +708,4 @@ with gr.Blocks(title="Quantum Paradox Lab") as demo:
728
  """)
729
 
730
  if __name__ == "__main__":
731
- demo.launch()
 
1
  """
2
  Quantum Paradox Lab
3
  Interactive demos proving quantum's future is architecture over qubit counts.
 
4
  Explores: Barren Plateaus, QSVT Unification, Photonic Blueprints, AI Circuit Design
5
  """
6
 
 
134
  np.random.seed(42)
135
 
136
  qubit_range = range(2, num_qubits + 1)
137
+ # FIX: Ensure unique layer configurations to avoid duplicate simulation
138
+ layer_configs = sorted(list(set([1, num_layers // 2, num_layers])))
139
 
140
  results = []
141
  for n_qubits in qubit_range:
 
166
  specs=[[{"type": "scatter"}, {"type": "heatmap"}]]
167
  )
168
 
169
+ # FIX: Ensure unique layer configurations to avoid duplicate legend entries
170
+ unique_layers = sorted(list(set([1, num_layers // 2, num_layers])))
171
+
172
+ for n_layers in unique_layers:
173
  layer_data = [r for r in results if r["layers"] == n_layers]
174
  fig.add_trace(
175
  go.Scatter(
 
393
  "QAOA (Max-Cut)": f"""
394
  # QAOA Circuit for {num_qubits}-qubit Max-Cut
395
  # Layers: 2, Parameters: {num_qubits * 4}
 
396
  OPENQASM 3.0;
397
  include "stdgates.inc";
 
398
  qubit[{num_qubits}] q;
399
  bit[{num_qubits}] c;
 
400
  // Initial superposition
401
  for int i in [0:{num_qubits-1}] {{ h q[i]; }}
 
402
  // Cost layer (problem-dependent ZZ interactions)
403
  for int i in [0:{num_qubits-2}] {{
404
  cx q[i], q[i+1];
405
  rz(gamma) q[i+1];
406
  cx q[i], q[i+1];
407
  }}
 
408
  // Mixer layer
409
  for int i in [0:{num_qubits-1}] {{ rx(beta) q[i]; }}
 
410
  // Measurement
411
  c = measure q;
412
  """,
413
  "VQE (H2 Molecule)": f"""
414
  # VQE Ansatz for Molecular Simulation
415
  # Qubits: {num_qubits}, Parameters: {num_qubits * 2}
 
416
  OPENQASM 3.0;
417
  include "stdgates.inc";
 
418
  qubit[{num_qubits}] q;
 
419
  // Hardware-efficient ansatz
420
  for int i in [0:{num_qubits-1}] {{
421
  ry(theta[i]) q[i];
422
  rz(phi[i]) q[i];
423
  }}
 
424
  // Entangling layer
425
  for int i in [0:{num_qubits-2}] {{
426
  cx q[i], q[i+1];
427
  }}
 
428
  // Second rotation layer
429
  for int i in [0:{num_qubits-1}] {{
430
  ry(theta2[i]) q[i];
 
433
  "Grover's Search": f"""
434
  # Grover's Algorithm for {num_qubits}-qubit search
435
  # Iterations: {int(np.pi/4 * np.sqrt(2**num_qubits))}
 
436
  OPENQASM 3.0;
437
  include "stdgates.inc";
 
438
  qubit[{num_qubits}] q;
439
  qubit ancilla;
 
440
  // Initialize
441
  for int i in [0:{num_qubits-1}] {{ h q[i]; }}
442
  x ancilla;
443
  h ancilla;
 
444
  // Grover iterations
445
  for int iter in [0:{int(np.pi/4 * np.sqrt(2**num_qubits))-1}] {{
446
  // Oracle (problem-specific)
 
466
  Algorithm: {algo_name}
467
  Year Discovered: {data['year']}
468
  Speedup Type: {data['speedup']}
 
469
  Problem Solved: {data['problem']}
470
  Classical Complexity: {data['classical']}
471
  Quantum Complexity: {data['quantum']}
 
472
  QSVT Polynomial: {data['polynomial']}
 
473
  How QSVT Unifies This:
474
  QSVT represents this algorithm as a polynomial transformation
475
  of singular values. The specific polynomial ({data['polynomial']})
476
  is implemented via a sequence of signal processing rotations.
 
477
  This means: ONE framework, ONE circuit template, MANY algorithms.
478
  """
479
 
480
  CSS = """
481
  @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Orbitron:wght@400;700&display=swap');
 
482
  .gradio-container {
483
  background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 50%, #0a1a1a 100%) !important;
484
  }
 
485
  h1, h2, h3 {
486
  font-family: 'Orbitron', sans-serif !important;
487
  color: #00ffcc !important;
488
  text-shadow: 0 0 30px rgba(0, 255, 204, 0.4);
489
  }
 
490
  .tab-nav button.selected {
491
  background: linear-gradient(135deg, #00ffcc, #00cc99) !important;
492
  color: #0a0a1a !important;
493
  }
 
494
  button.primary {
495
  background: linear-gradient(135deg, #00ffcc, #00cc99) !important;
496
  color: #0a0a1a !important;
497
  }
 
498
  .prose code {
499
  background: #1a1a2e !important;
500
  color: #00ffcc !important;
501
  }
502
  """
503
 
504
+ # FIX: CSS added to Blocks initialization
505
+ with gr.Blocks(title="Quantum Paradox Lab", css=CSS) as demo:
506
 
507
  gr.Markdown("""
508
  # Quantum Paradox Lab
 
697
 
698
  ---
699
 
700
+ **Created by:** Eric Raymond & Samiksha BC | Purdue AI/Robotics Engineering | IU SouthBend
701
  """)
702
 
703
  gr.Markdown("""
 
708
  """)
709
 
710
  if __name__ == "__main__":
711
+ demo.launch()