Spaces:
Runtime error
Runtime error
harishaseebat92
commited on
Commit
·
9dd58b1
1
Parent(s):
e507df4
QLBM: Upload Window
Browse files- qlbm_embedded.py +29 -81
qlbm_embedded.py
CHANGED
|
@@ -1239,13 +1239,21 @@ def process_uploaded_job_result():
|
|
| 1239 |
_state.qlbm_job_upload_filename = filename
|
| 1240 |
log_to_console(f"Processing file: {filename}")
|
| 1241 |
|
| 1242 |
-
# Decode base64
|
| 1243 |
content = file_data.get("content", "") if isinstance(file_data, dict) else ""
|
| 1244 |
-
if content.startswith("data:"):
|
| 1245 |
-
content = content.split(",", 1)[1] # Remove data URI prefix
|
| 1246 |
|
| 1247 |
-
|
| 1248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1249 |
|
| 1250 |
# Parse timesteps from user input
|
| 1251 |
# User provides Total Time T, we generate T_list = [1, 2, ..., T]
|
|
@@ -1375,8 +1383,8 @@ def process_uploaded_job_result():
|
|
| 1375 |
_state.qlbm_job_upload_success = f"✓ Successfully processed {len(output)} timestep(s) from {filename}"
|
| 1376 |
|
| 1377 |
# Update the Plotly figure widget
|
| 1378 |
-
if hasattr(_ctrl, "
|
| 1379 |
-
_ctrl.
|
| 1380 |
|
| 1381 |
log_to_console(f"Results ready! {len(output)} frames generated.")
|
| 1382 |
|
|
@@ -1579,48 +1587,18 @@ async def _run_simulation_async():
|
|
| 1579 |
|
| 1580 |
output, plotly_fig, init_state_prep_circ = await loop.run_in_executor(executor, _run_ibm_qpu_blocking)
|
| 1581 |
|
| 1582 |
-
# Step 3:
|
| 1583 |
_state.qlbm_simulation_progress = 92
|
| 1584 |
-
_state.qlbm_status_message = "Step 3:
|
| 1585 |
await _qlbm_flush_async()
|
| 1586 |
|
| 1587 |
-
#
|
| 1588 |
-
|
| 1589 |
-
|
| 1590 |
-
initial_snapshot = show_initial_distribution(
|
| 1591 |
-
n=params["n"],
|
| 1592 |
-
init_state_name=params["init_state_name"],
|
| 1593 |
-
sine_k_x=params["sine_k_x"],
|
| 1594 |
-
sine_k_y=params["sine_k_y"],
|
| 1595 |
-
sine_k_z=params["sine_k_z"],
|
| 1596 |
-
gauss_cx=params["gauss_cx"],
|
| 1597 |
-
gauss_cy=params["gauss_cy"],
|
| 1598 |
-
gauss_cz=params["gauss_cz"],
|
| 1599 |
-
gauss_sigma=params["gauss_sigma"],
|
| 1600 |
-
mdd_kx_log2=params["mdd_kx_log2"],
|
| 1601 |
-
mdd_ky_log2=params["mdd_ky_log2"],
|
| 1602 |
-
mdd_kz_log2=params["mdd_kz_log2"],
|
| 1603 |
-
plot=False,
|
| 1604 |
-
return_data=True,
|
| 1605 |
-
init_state_circuit=init_state_prep_circ,
|
| 1606 |
-
)
|
| 1607 |
-
if initial_snapshot is not None:
|
| 1608 |
-
initial_density, X = initial_snapshot
|
| 1609 |
-
# Prepend T=0 to outputs
|
| 1610 |
-
output = [initial_density] + list(output)
|
| 1611 |
-
extended_T_list = [0] + list(params["T_list"])
|
| 1612 |
-
# Recreate figure with T=0 included
|
| 1613 |
-
plotly_fig = _create_slider_figure(output, extended_T_list, X)
|
| 1614 |
-
log_to_console("T=0 snapshot added successfully.")
|
| 1615 |
-
else:
|
| 1616 |
-
extended_T_list = params["T_list"]
|
| 1617 |
-
except Exception as exc:
|
| 1618 |
-
log_to_console(f"Warning: Could not generate T=0 snapshot: {exc}")
|
| 1619 |
-
extended_T_list = params["T_list"]
|
| 1620 |
|
| 1621 |
# Store results
|
| 1622 |
simulation_data_frames = output
|
| 1623 |
-
simulation_times = [float(t) for t in
|
| 1624 |
|
| 1625 |
# Update UI
|
| 1626 |
if hasattr(_ctrl, "qlbm_qiskit_result_update"):
|
|
@@ -1628,7 +1606,7 @@ async def _run_simulation_async():
|
|
| 1628 |
|
| 1629 |
_state.qlbm_max_time_step = len(output) - 1
|
| 1630 |
_state.qlbm_time_val = 0
|
| 1631 |
-
_state.qlbm_time_slider_labels = [f"T={t}" for t in
|
| 1632 |
_state.qlbm_simulation_has_run = True
|
| 1633 |
_state.qlbm_qiskit_mode = True
|
| 1634 |
|
|
@@ -1696,48 +1674,18 @@ async def _run_simulation_async():
|
|
| 1696 |
|
| 1697 |
output, plotly_fig, init_state_prep_circ = await loop.run_in_executor(executor, _run_ionq_qpu_blocking)
|
| 1698 |
|
| 1699 |
-
# Step 3:
|
| 1700 |
_state.qlbm_simulation_progress = 92
|
| 1701 |
-
_state.qlbm_status_message = "Step 3:
|
| 1702 |
await _qlbm_flush_async()
|
| 1703 |
|
| 1704 |
-
#
|
| 1705 |
-
|
| 1706 |
-
|
| 1707 |
-
initial_snapshot = show_initial_distribution(
|
| 1708 |
-
n=params["n"],
|
| 1709 |
-
init_state_name=params["init_state_name"],
|
| 1710 |
-
sine_k_x=params["sine_k_x"],
|
| 1711 |
-
sine_k_y=params["sine_k_y"],
|
| 1712 |
-
sine_k_z=params["sine_k_z"],
|
| 1713 |
-
gauss_cx=params["gauss_cx"],
|
| 1714 |
-
gauss_cy=params["gauss_cy"],
|
| 1715 |
-
gauss_cz=params["gauss_cz"],
|
| 1716 |
-
gauss_sigma=params["gauss_sigma"],
|
| 1717 |
-
mdd_kx_log2=params["mdd_kx_log2"],
|
| 1718 |
-
mdd_ky_log2=params["mdd_ky_log2"],
|
| 1719 |
-
mdd_kz_log2=params["mdd_kz_log2"],
|
| 1720 |
-
plot=False,
|
| 1721 |
-
return_data=True,
|
| 1722 |
-
init_state_circuit=init_state_prep_circ,
|
| 1723 |
-
)
|
| 1724 |
-
if initial_snapshot is not None:
|
| 1725 |
-
initial_density, X = initial_snapshot
|
| 1726 |
-
# Prepend T=0 to outputs
|
| 1727 |
-
output = [initial_density] + list(output)
|
| 1728 |
-
extended_T_list = [0] + list(params["T_list"])
|
| 1729 |
-
# Recreate figure with T=0 included
|
| 1730 |
-
plotly_fig = _create_slider_figure(output, extended_T_list, X)
|
| 1731 |
-
log_to_console("T=0 snapshot added successfully.")
|
| 1732 |
-
else:
|
| 1733 |
-
extended_T_list = params["T_list"]
|
| 1734 |
-
except Exception as exc:
|
| 1735 |
-
log_to_console(f"Warning: Could not generate T=0 snapshot: {exc}")
|
| 1736 |
-
extended_T_list = params["T_list"]
|
| 1737 |
|
| 1738 |
# Store results
|
| 1739 |
simulation_data_frames = output
|
| 1740 |
-
simulation_times = [float(t) for t in
|
| 1741 |
|
| 1742 |
# Update UI
|
| 1743 |
if hasattr(_ctrl, "qlbm_qiskit_result_update"):
|
|
@@ -1745,7 +1693,7 @@ async def _run_simulation_async():
|
|
| 1745 |
|
| 1746 |
_state.qlbm_max_time_step = len(output) - 1
|
| 1747 |
_state.qlbm_time_val = 0
|
| 1748 |
-
_state.qlbm_time_slider_labels = [f"T={t}" for t in
|
| 1749 |
_state.qlbm_simulation_has_run = True
|
| 1750 |
_state.qlbm_qiskit_mode = True
|
| 1751 |
|
|
|
|
| 1239 |
_state.qlbm_job_upload_filename = filename
|
| 1240 |
log_to_console(f"Processing file: {filename}")
|
| 1241 |
|
| 1242 |
+
# Decode content - handle both bytes and string (base64 data URI)
|
| 1243 |
content = file_data.get("content", "") if isinstance(file_data, dict) else ""
|
|
|
|
|
|
|
| 1244 |
|
| 1245 |
+
# Check if content is bytes or string
|
| 1246 |
+
if isinstance(content, bytes):
|
| 1247 |
+
# Content is already raw bytes, decode directly
|
| 1248 |
+
json_str = content.decode("utf-8")
|
| 1249 |
+
log_to_console("Content received as raw bytes")
|
| 1250 |
+
else:
|
| 1251 |
+
# Content is a string, possibly base64 data URI
|
| 1252 |
+
if content.startswith("data:"):
|
| 1253 |
+
content = content.split(",", 1)[1] # Remove data URI prefix
|
| 1254 |
+
raw_bytes = base64.b64decode(content)
|
| 1255 |
+
json_str = raw_bytes.decode("utf-8")
|
| 1256 |
+
log_to_console("Content decoded from base64 string")
|
| 1257 |
|
| 1258 |
# Parse timesteps from user input
|
| 1259 |
# User provides Total Time T, we generate T_list = [1, 2, ..., T]
|
|
|
|
| 1383 |
_state.qlbm_job_upload_success = f"✓ Successfully processed {len(output)} timestep(s) from {filename}"
|
| 1384 |
|
| 1385 |
# Update the Plotly figure widget
|
| 1386 |
+
if hasattr(_ctrl, "qlbm_qiskit_result_update"):
|
| 1387 |
+
_ctrl.qlbm_qiskit_result_update(fig)
|
| 1388 |
|
| 1389 |
log_to_console(f"Results ready! {len(output)} frames generated.")
|
| 1390 |
|
|
|
|
| 1587 |
|
| 1588 |
output, plotly_fig, init_state_prep_circ = await loop.run_in_executor(executor, _run_ibm_qpu_blocking)
|
| 1589 |
|
| 1590 |
+
# Step 3: Finalizing results (T=0 snapshot removed - only show T=1 onwards)
|
| 1591 |
_state.qlbm_simulation_progress = 92
|
| 1592 |
+
_state.qlbm_status_message = "Step 3: Finalizing results..."
|
| 1593 |
await _qlbm_flush_async()
|
| 1594 |
|
| 1595 |
+
# Use T_list directly (no T=0 prepend)
|
| 1596 |
+
result_T_list = list(params["T_list"])
|
| 1597 |
+
log_to_console(f"Results available for T={result_T_list}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1598 |
|
| 1599 |
# Store results
|
| 1600 |
simulation_data_frames = output
|
| 1601 |
+
simulation_times = [float(t) for t in result_T_list]
|
| 1602 |
|
| 1603 |
# Update UI
|
| 1604 |
if hasattr(_ctrl, "qlbm_qiskit_result_update"):
|
|
|
|
| 1606 |
|
| 1607 |
_state.qlbm_max_time_step = len(output) - 1
|
| 1608 |
_state.qlbm_time_val = 0
|
| 1609 |
+
_state.qlbm_time_slider_labels = [f"T={t}" for t in result_T_list]
|
| 1610 |
_state.qlbm_simulation_has_run = True
|
| 1611 |
_state.qlbm_qiskit_mode = True
|
| 1612 |
|
|
|
|
| 1674 |
|
| 1675 |
output, plotly_fig, init_state_prep_circ = await loop.run_in_executor(executor, _run_ionq_qpu_blocking)
|
| 1676 |
|
| 1677 |
+
# Step 3: Finalizing results (T=0 snapshot removed - only show T=1 onwards)
|
| 1678 |
_state.qlbm_simulation_progress = 92
|
| 1679 |
+
_state.qlbm_status_message = "Step 3: Finalizing results..."
|
| 1680 |
await _qlbm_flush_async()
|
| 1681 |
|
| 1682 |
+
# Use T_list directly (no T=0 prepend)
|
| 1683 |
+
result_T_list = list(params["T_list"])
|
| 1684 |
+
log_to_console(f"Results available for T={result_T_list}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1685 |
|
| 1686 |
# Store results
|
| 1687 |
simulation_data_frames = output
|
| 1688 |
+
simulation_times = [float(t) for t in result_T_list]
|
| 1689 |
|
| 1690 |
# Update UI
|
| 1691 |
if hasattr(_ctrl, "qlbm_qiskit_result_update"):
|
|
|
|
| 1693 |
|
| 1694 |
_state.qlbm_max_time_step = len(output) - 1
|
| 1695 |
_state.qlbm_time_val = 0
|
| 1696 |
+
_state.qlbm_time_slider_labels = [f"T={t}" for t in result_T_list]
|
| 1697 |
_state.qlbm_simulation_has_run = True
|
| 1698 |
_state.qlbm_qiskit_mode = True
|
| 1699 |
|