jezerjojo commited on
Commit
034a360
·
2 Parent(s): 4740382 f21a3a4

Merge branch 'main' of https://huggingface.co/spaces/ansysresearch/quantum

Browse files
Files changed (3) hide show
  1. docker/nginx.conf +14 -14
  2. qlbm/qlbm_sample_app.py +13 -1
  3. qlbm_embedded.py +68 -2
docker/nginx.conf CHANGED
@@ -18,11 +18,11 @@ http {
18
  sendfile on;
19
 
20
  # Increased timeouts for long-running quantum computations
21
- keepalive_timeout 3600s;
22
- proxy_connect_timeout 3600s;
23
- proxy_read_timeout 3600s;
24
- proxy_send_timeout 3600s;
25
- send_timeout 3600s;
26
 
27
  # Disable buffering for real-time updates
28
  proxy_buffering off;
@@ -59,9 +59,9 @@ http {
59
  proxy_set_header Connection $connection_upgrade;
60
 
61
  # Timeouts for long-running quantum simulations
62
- proxy_connect_timeout 3600s;
63
- proxy_read_timeout 3600s;
64
- proxy_send_timeout 3600s;
65
  }
66
 
67
  location /qlbm/ {
@@ -75,9 +75,9 @@ http {
75
  proxy_set_header Connection $connection_upgrade;
76
 
77
  # Timeouts for long-running quantum simulations
78
- proxy_connect_timeout 3600s;
79
- proxy_read_timeout 3600s;
80
- proxy_send_timeout 3600s;
81
  }
82
 
83
  location / {
@@ -91,9 +91,9 @@ http {
91
  proxy_set_header Connection $connection_upgrade;
92
 
93
  # Timeouts for long-running operations
94
- proxy_connect_timeout 3600s;
95
- proxy_read_timeout 3600s;
96
- proxy_send_timeout 3600s;
97
  }
98
  }
99
  }
 
18
  sendfile on;
19
 
20
  # Increased timeouts for long-running quantum computations
21
+ keepalive_timeout 360000s;
22
+ proxy_connect_timeout 360000s;
23
+ proxy_read_timeout 360000s;
24
+ proxy_send_timeout 360000s;
25
+ send_timeout 360000s;
26
 
27
  # Disable buffering for real-time updates
28
  proxy_buffering off;
 
59
  proxy_set_header Connection $connection_upgrade;
60
 
61
  # Timeouts for long-running quantum simulations
62
+ proxy_connect_timeout 360000s;
63
+ proxy_read_timeout 360000s;
64
+ proxy_send_timeout 360000s;
65
  }
66
 
67
  location /qlbm/ {
 
75
  proxy_set_header Connection $connection_upgrade;
76
 
77
  # Timeouts for long-running quantum simulations
78
+ proxy_connect_timeout 360000s;
79
+ proxy_read_timeout 360000s;
80
+ proxy_send_timeout 360000s;
81
  }
82
 
83
  location / {
 
91
  proxy_set_header Connection $connection_upgrade;
92
 
93
  # Timeouts for long-running operations
94
+ proxy_connect_timeout 360000s;
95
+ proxy_read_timeout 360000s;
96
+ proxy_send_timeout 360000s;
97
  }
98
  }
99
  }
qlbm/qlbm_sample_app.py CHANGED
@@ -792,6 +792,10 @@ def show_initial_distribution(
792
  gauss_cy: float = None,
793
  gauss_cz: float = None,
794
  gauss_sigma: float = None,
 
 
 
 
795
  # Display options
796
  plot: bool = True,
797
  return_data: bool = False,
@@ -806,13 +810,15 @@ def show_initial_distribution(
806
  n : int
807
  Number of qubits per spatial dimension (grid size = 2^n per axis)
808
  init_state_name : str
809
- One of "dirac_delta", "sin", "gaussian"
810
  sine_k_x, sine_k_y, sine_k_z : float
811
  Frequency multipliers for sinusoidal distribution (default=1.0)
812
  gauss_cx, gauss_cy, gauss_cz : float
813
  Center coordinates in [0,1] for Gaussian (default=0.5)
814
  gauss_sigma : float
815
  Spread of Gaussian in normalized units (default=0.2)
 
 
816
  plot : bool
817
  Whether to display the 3D isosurface plot (default=True)
818
  return_data : bool
@@ -850,6 +856,9 @@ def show_initial_distribution(
850
  gauss_cy=gauss_cy,
851
  gauss_cz=gauss_cz,
852
  gauss_sigma=gauss_sigma,
 
 
 
853
  )
854
 
855
  # Run the circuit on statevector simulator to extract the initial state
@@ -885,6 +894,9 @@ def show_initial_distribution(
885
  cz = float(gauss_cz) if gauss_cz is not None else 0.5
886
  sigma = float(gauss_sigma) if gauss_sigma is not None else 0.2
887
  print(f"Gaussian center: ({cx}, {cy}, {cz}), sigma={sigma}")
 
 
 
888
 
889
  print("Distribution stats:")
890
  print(f" Min: {np.min(C):.6f}, Max: {np.max(C):.6f}")
 
792
  gauss_cy: float = None,
793
  gauss_cz: float = None,
794
  gauss_sigma: float = None,
795
+ # Multi-dirac-delta parameters
796
+ mdd_kx_log2: int = 1,
797
+ mdd_ky_log2: int = 1,
798
+ mdd_kz_log2: int = 1,
799
  # Display options
800
  plot: bool = True,
801
  return_data: bool = False,
 
810
  n : int
811
  Number of qubits per spatial dimension (grid size = 2^n per axis)
812
  init_state_name : str
813
+ One of "dirac_delta", "sin", "gaussian", "multi_dirac_delta"
814
  sine_k_x, sine_k_y, sine_k_z : float
815
  Frequency multipliers for sinusoidal distribution (default=1.0)
816
  gauss_cx, gauss_cy, gauss_cz : float
817
  Center coordinates in [0,1] for Gaussian (default=0.5)
818
  gauss_sigma : float
819
  Spread of Gaussian in normalized units (default=0.2)
820
+ mdd_kx_log2, mdd_ky_log2, mdd_kz_log2 : int
821
+ log2 of frequency multipliers for multi-dirac-delta distribution (default=1)
822
  plot : bool
823
  Whether to display the 3D isosurface plot (default=True)
824
  return_data : bool
 
856
  gauss_cy=gauss_cy,
857
  gauss_cz=gauss_cz,
858
  gauss_sigma=gauss_sigma,
859
+ mdd_kx_log2=mdd_kx_log2,
860
+ mdd_ky_log2=mdd_ky_log2,
861
+ mdd_kz_log2=mdd_kz_log2,
862
  )
863
 
864
  # Run the circuit on statevector simulator to extract the initial state
 
894
  cz = float(gauss_cz) if gauss_cz is not None else 0.5
895
  sigma = float(gauss_sigma) if gauss_sigma is not None else 0.2
896
  print(f"Gaussian center: ({cx}, {cy}, {cz}), sigma={sigma}")
897
+ elif init_state_name == "multi_dirac_delta":
898
+ print(f"Multi-Dirac-Delta: kx_log2={mdd_kx_log2}, ky_log2={mdd_ky_log2}, kz_log2={mdd_kz_log2}")
899
+ print(f" Number of peaks: {2**mdd_kx_log2} x {2**mdd_ky_log2} x {2**mdd_kz_log2}")
900
 
901
  print("Distribution stats:")
902
  print(f" Min: {np.min(C):.6f}, Max: {np.max(C):.6f}")
qlbm_embedded.py CHANGED
@@ -123,7 +123,7 @@ def init_state():
123
  "qlbm_show_progress": False,
124
 
125
  # Distribution
126
- "qlbm_dist_modes": ["Sinusoidal", "Gaussian"],
127
  "qlbm_dist_type": None,
128
  "qlbm_nx": 32,
129
  "qlbm_show_edges": False,
@@ -140,6 +140,11 @@ def init_state():
140
  "qlbm_gauss_cz": 16.0,
141
  "qlbm_gauss_sigma": 6.0,
142
 
 
 
 
 
 
143
  # Problem & Geometry
144
  "qlbm_qlbm_problems": [
145
  "Scalar advection-diffusion in a box",
@@ -411,6 +416,42 @@ def get_initial_distribution_figure(distribution_type, N, show_edges=False):
411
  (z - cz)**2 / (2 * sigma**2))) * 1.8 + 0.2
412
  title = f"Gaussian Distribution (N={N})"
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  else:
415
  return go.Figure()
416
 
@@ -906,6 +947,8 @@ def _map_state_to_qiskit_params():
906
  init_state_name = "sin"
907
  elif dist_type == "Gaussian":
908
  init_state_name = "gaussian"
 
 
909
  else:
910
  init_state_name = "sin" # Default
911
 
@@ -939,6 +982,9 @@ def _map_state_to_qiskit_params():
939
  "gauss_cy": gauss_cy,
940
  "gauss_cz": gauss_cz,
941
  "gauss_sigma": gauss_sigma,
 
 
 
942
  "vx_expr": str(_state.qlbm_vx_expr),
943
  "vy_expr": str(_state.qlbm_vy_expr),
944
  "vz_expr": str(_state.qlbm_vz_expr),
@@ -993,6 +1039,9 @@ def _run_qiskit_simulation(progress_callback=None):
993
  gauss_cy=params["gauss_cy"],
994
  gauss_cz=params["gauss_cz"],
995
  gauss_sigma=params["gauss_sigma"],
 
 
 
996
  )
997
 
998
  if progress_callback:
@@ -1122,6 +1171,9 @@ def run_simulation():
1122
  gauss_cy=params["gauss_cy"],
1123
  gauss_cz=params["gauss_cz"],
1124
  gauss_sigma=params["gauss_sigma"],
 
 
 
1125
  )
1126
 
1127
  log_to_console("Submitting job to IBM Quantum...")
@@ -1413,7 +1465,8 @@ def _register_handlers():
1413
  _apply_workflow_highlights(_determine_workflow_step())
1414
 
1415
  @_state.change("qlbm_show_edges", "qlbm_sine_k_x", "qlbm_sine_k_y", "qlbm_sine_k_z",
1416
- "qlbm_gauss_cx", "qlbm_gauss_cy", "qlbm_gauss_cz", "qlbm_gauss_sigma")
 
1417
  def on_param_change(**kwargs):
1418
  update_view()
1419
  _apply_workflow_highlights(_determine_workflow_step())
@@ -1568,6 +1621,19 @@ def _build_control_panels(plotter):
1568
  thumb_label="always", density="compact"
1569
  )
1570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1571
  # Boundary Conditions
1572
  with vuetify3.VCard(classes="mb-2"):
1573
  vuetify3.VCardTitle("Boundary Conditions", classes="text-subtitle-2 font-weight-bold text-primary")
 
123
  "qlbm_show_progress": False,
124
 
125
  # Distribution
126
+ "qlbm_dist_modes": ["Sinusoidal", "Gaussian", "Multi-Dirac-Delta"],
127
  "qlbm_dist_type": None,
128
  "qlbm_nx": 32,
129
  "qlbm_show_edges": False,
 
140
  "qlbm_gauss_cz": 16.0,
141
  "qlbm_gauss_sigma": 6.0,
142
 
143
+ # Multi-Dirac-Delta params (log2 of frequency multipliers)
144
+ "qlbm_mdd_kx_log2": 1,
145
+ "qlbm_mdd_ky_log2": 1,
146
+ "qlbm_mdd_kz_log2": 1,
147
+
148
  # Problem & Geometry
149
  "qlbm_qlbm_problems": [
150
  "Scalar advection-diffusion in a box",
 
416
  (z - cz)**2 / (2 * sigma**2))) * 1.8 + 0.2
417
  title = f"Gaussian Distribution (N={N})"
418
 
419
+ elif distribution_type == "Multi-Dirac-Delta":
420
+ # Get log2 frequency multipliers from state
421
+ kx_log2 = int(_state.qlbm_mdd_kx_log2) if hasattr(_state, "qlbm_mdd_kx_log2") else 1
422
+ ky_log2 = int(_state.qlbm_mdd_ky_log2) if hasattr(_state, "qlbm_mdd_ky_log2") else 1
423
+ kz_log2 = int(_state.qlbm_mdd_kz_log2) if hasattr(_state, "qlbm_mdd_kz_log2") else 1
424
+
425
+ # Number of peaks per axis
426
+ num_peaks_x = 2 ** kx_log2
427
+ num_peaks_y = 2 ** ky_log2
428
+ num_peaks_z = 2 ** kz_log2
429
+
430
+ # Create a function that produces peaks at regular intervals
431
+ # Peaks are located at positions: N/(2*num_peaks) + i*N/num_peaks for i in 0..num_peaks-1
432
+ def multi_dirac_func(x, y, z):
433
+ # Use narrow Gaussians to approximate delta functions
434
+ delta_width = max(0.5, N / (8 * max(num_peaks_x, num_peaks_y, num_peaks_z)))
435
+ result = np.zeros_like(x, dtype=float)
436
+
437
+ for ix in range(num_peaks_x):
438
+ peak_x = (0.5 + ix) * N / num_peaks_x
439
+ for iy in range(num_peaks_y):
440
+ peak_y = (0.5 + iy) * N / num_peaks_y
441
+ for iz in range(num_peaks_z):
442
+ peak_z = (0.5 + iz) * N / num_peaks_z
443
+ result += np.exp(-(
444
+ (x - peak_x)**2 + (y - peak_y)**2 + (z - peak_z)**2
445
+ ) / (2 * delta_width**2))
446
+
447
+ # Normalize to range [0.2, 2.0] for visibility
448
+ if result.max() > 0:
449
+ result = result / result.max() * 1.8 + 0.2
450
+ return result
451
+
452
+ selected_func = multi_dirac_func
453
+ title = f"Multi-Dirac-Delta (kx={num_peaks_x}, ky={num_peaks_y}, kz={num_peaks_z})"
454
+
455
  else:
456
  return go.Figure()
457
 
 
947
  init_state_name = "sin"
948
  elif dist_type == "Gaussian":
949
  init_state_name = "gaussian"
950
+ elif dist_type == "Multi-Dirac-Delta":
951
+ init_state_name = "multi_dirac_delta"
952
  else:
953
  init_state_name = "sin" # Default
954
 
 
982
  "gauss_cy": gauss_cy,
983
  "gauss_cz": gauss_cz,
984
  "gauss_sigma": gauss_sigma,
985
+ "mdd_kx_log2": int(_state.qlbm_mdd_kx_log2) if hasattr(_state, "qlbm_mdd_kx_log2") else 1,
986
+ "mdd_ky_log2": int(_state.qlbm_mdd_ky_log2) if hasattr(_state, "qlbm_mdd_ky_log2") else 1,
987
+ "mdd_kz_log2": int(_state.qlbm_mdd_kz_log2) if hasattr(_state, "qlbm_mdd_kz_log2") else 1,
988
  "vx_expr": str(_state.qlbm_vx_expr),
989
  "vy_expr": str(_state.qlbm_vy_expr),
990
  "vz_expr": str(_state.qlbm_vz_expr),
 
1039
  gauss_cy=params["gauss_cy"],
1040
  gauss_cz=params["gauss_cz"],
1041
  gauss_sigma=params["gauss_sigma"],
1042
+ mdd_kx_log2=params["mdd_kx_log2"],
1043
+ mdd_ky_log2=params["mdd_ky_log2"],
1044
+ mdd_kz_log2=params["mdd_kz_log2"],
1045
  )
1046
 
1047
  if progress_callback:
 
1171
  gauss_cy=params["gauss_cy"],
1172
  gauss_cz=params["gauss_cz"],
1173
  gauss_sigma=params["gauss_sigma"],
1174
+ mdd_kx_log2=params["mdd_kx_log2"],
1175
+ mdd_ky_log2=params["mdd_ky_log2"],
1176
+ mdd_kz_log2=params["mdd_kz_log2"],
1177
  )
1178
 
1179
  log_to_console("Submitting job to IBM Quantum...")
 
1465
  _apply_workflow_highlights(_determine_workflow_step())
1466
 
1467
  @_state.change("qlbm_show_edges", "qlbm_sine_k_x", "qlbm_sine_k_y", "qlbm_sine_k_z",
1468
+ "qlbm_gauss_cx", "qlbm_gauss_cy", "qlbm_gauss_cz", "qlbm_gauss_sigma",
1469
+ "qlbm_mdd_kx_log2", "qlbm_mdd_ky_log2", "qlbm_mdd_kz_log2")
1470
  def on_param_change(**kwargs):
1471
  update_view()
1472
  _apply_workflow_highlights(_determine_workflow_step())
 
1621
  thumb_label="always", density="compact"
1622
  )
1623
 
1624
+ # Multi-Dirac-Delta controls
1625
+ with vuetify3.VCard(classes="mb-2", v_if="qlbm_custom_dist_params && qlbm_dist_type === 'Multi-Dirac-Delta'"):
1626
+ vuetify3.VCardTitle("Multi-Dirac-Delta Parameters")
1627
+ with vuetify3.VCardText():
1628
+ vuetify3.VCardSubtitle("Number of delta peaks per axis = 2^k", classes="text-caption mb-2")
1629
+ for axis in ['x', 'y', 'z']:
1630
+ vuetify3.VSlider(
1631
+ label=f"k_{axis.upper()} (log₂)",
1632
+ v_model=(f"qlbm_mdd_k{axis}_log2", 1),
1633
+ min=1, max=4, step=1,
1634
+ thumb_label="always", density="compact"
1635
+ )
1636
+
1637
  # Boundary Conditions
1638
  with vuetify3.VCard(classes="mb-2"):
1639
  vuetify3.VCardTitle("Boundary Conditions", classes="text-subtitle-2 font-weight-bold text-primary")