Spaces:
Paused
Paused
Commit
·
5f3a14a
1
Parent(s):
c68dfcb
clean up the console logging for the IBM QPU workflow.
Browse files- em/ui.py +0 -11
- qlbm/qlbm_sample_app.py +59 -39
- qlbm_embedded.py +3 -12
em/ui.py
CHANGED
|
@@ -138,17 +138,6 @@ def _build_overview_card():
|
|
| 138 |
density="compact",
|
| 139 |
color="primary",
|
| 140 |
)
|
| 141 |
-
vuetify3.VDivider(classes="my-0")
|
| 142 |
-
vuetify3.VCardSubtitle("Governing Equations", classes="text-caption font-weight-bold mt-0", style="font-size: 0.7rem;")
|
| 143 |
-
vuetify3.VDivider(classes="mb-0")
|
| 144 |
-
vuetify3.VListItemTitle("Maxwell's time-domain, 2D, TEz polarized.", classes="text-caption", style="font-size: 0.7rem;")
|
| 145 |
-
vuetify3.VCardSubtitle("Inputs", classes="text-caption font-weight-bold mt-0", style="font-size: 0.7rem;")
|
| 146 |
-
vuetify3.VDivider(classes="mb-0")
|
| 147 |
-
vuetify3.VListItemTitle("Geometry, excitation, medium, output visualization preferences.", classes="text-caption", style="font-size: 0.7rem;")
|
| 148 |
-
vuetify3.VCardSubtitle("Outputs", classes="text-caption font-weight-bold mt-0", style="font-size: 0.7rem;")
|
| 149 |
-
vuetify3.VDivider(classes="mb-0")
|
| 150 |
-
vuetify3.VListItemTitle("Surface plots of field components OR time evolution of field components at specified points.", classes="text-caption", style="font-size: 0.7rem;")
|
| 151 |
-
|
| 152 |
|
| 153 |
def _build_geometry_card():
|
| 154 |
"""Build the Geometry configuration card."""
|
|
|
|
| 138 |
density="compact",
|
| 139 |
color="primary",
|
| 140 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
def _build_geometry_card():
|
| 143 |
"""Build the Geometry configuration card."""
|
qlbm/qlbm_sample_app.py
CHANGED
|
@@ -519,38 +519,25 @@ def run_sampling_hw_ibm(
|
|
| 519 |
|
| 520 |
def get_job_result(j):
|
| 521 |
result = j.result() # PrimitiveResult (a container of PubResults)
|
| 522 |
-
log(
|
| 523 |
|
| 524 |
output=[]
|
| 525 |
|
| 526 |
for T_total,pub in zip(T_list,result):
|
| 527 |
|
| 528 |
-
#
|
| 529 |
-
log(f"PUB metadata: {pub.metadata if hasattr(pub, 'metadata') else '<no metadata>'}")
|
| 530 |
-
|
| 531 |
-
# 1) Try to obtain counts via the recommended API
|
| 532 |
-
try:
|
| 533 |
-
counts = pub.data.meas.get_counts()
|
| 534 |
-
log("\nCounts (pub.data.meas.get_counts()) sample:")
|
| 535 |
-
log(str({k: counts[k] for k in list(counts)[:10]}))
|
| 536 |
-
except Exception as e:
|
| 537 |
-
log(f"Couldn't call pub.data.meas.get_counts(): {e}")
|
| 538 |
-
counts = None
|
| 539 |
-
|
| 540 |
-
# 2) Try join_data() (to combine multiple regs) and get_counts() on it
|
| 541 |
try:
|
| 542 |
joined = pub.join_data() # join_data concatenates registers along bits axis
|
| 543 |
joined_counts = joined.get_counts()
|
| 544 |
-
log("\nJoined counts (pub.join_data().get_counts()) sample:")
|
| 545 |
-
log(str({k: joined_counts[k] for k in list(joined_counts)[:10]}))
|
| 546 |
except Exception as e:
|
| 547 |
-
log(f"
|
| 548 |
joined_counts = None
|
| 549 |
|
| 550 |
-
|
| 551 |
-
pts, counts = load_samples(joined_counts, T_total, logger=
|
| 552 |
output+=[estimate_density(pts, counts, bandwidth=0.05, grid_size=output_resolution)]
|
| 553 |
|
|
|
|
| 554 |
fig = plot_density_isosurface_slider(output, T_list)
|
| 555 |
return output, fig
|
| 556 |
|
|
@@ -590,16 +577,29 @@ def run_sampling_sim(
|
|
| 590 |
output : list[ndarray]
|
| 591 |
List of 3D density arrays, one per timestep
|
| 592 |
fig : go.Figure
|
| 593 |
-
|
| 594 |
"""
|
| 595 |
|
| 596 |
if type(ux)==str:
|
| 597 |
ux,uy,uz=str_to_lambda(ux,uy,uz)
|
| 598 |
|
| 599 |
# Convert string init_state_prep_circ to circuit if needed (matches original logic)
|
| 600 |
-
if
|
|
|
|
| 601 |
init_state_prep_circ=get_named_init_state_circuit(n,init_state_prep_circ)
|
| 602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
qc_list=get_circuit(n,ux,uy,uz,init_state_prep_circ,T_list,vel_resolution,measure=False)
|
| 604 |
backend = AerSimulator(method = 'statevector')
|
| 605 |
output=[]
|
|
@@ -655,8 +655,18 @@ def run_sampling_sim(
|
|
| 655 |
x_coords = np.linspace(0, 1, 2**n)
|
| 656 |
X = np.meshgrid(x_coords, x_coords, x_coords, indexing='ij')
|
| 657 |
|
| 658 |
-
|
| 659 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
return output, fig
|
| 661 |
|
| 662 |
|
|
@@ -739,8 +749,8 @@ def _create_slider_figure(output_list, T_list, X):
|
|
| 739 |
|
| 740 |
|
| 741 |
def show_initial_distribution(
|
| 742 |
-
|
| 743 |
-
|
| 744 |
# Sinusoidal parameters (frequency multipliers)
|
| 745 |
sine_k_x: float = 1.0,
|
| 746 |
sine_k_y: float = 1.0,
|
|
@@ -751,8 +761,9 @@ def show_initial_distribution(
|
|
| 751 |
gauss_cz: float = None,
|
| 752 |
gauss_sigma: float = None,
|
| 753 |
# Display options
|
| 754 |
-
|
| 755 |
-
|
|
|
|
| 756 |
):
|
| 757 |
"""
|
| 758 |
Visualize the initial distribution by running the state preparation circuit
|
|
@@ -774,6 +785,10 @@ def show_initial_distribution(
|
|
| 774 |
Whether to display the 3D isosurface plot (default=True)
|
| 775 |
return_data : bool
|
| 776 |
Whether to return the distribution data (default=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 777 |
|
| 778 |
Returns
|
| 779 |
-------
|
|
@@ -787,18 +802,23 @@ def show_initial_distribution(
|
|
| 787 |
"""
|
| 788 |
N = 2**n
|
| 789 |
|
| 790 |
-
#
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 802 |
|
| 803 |
# Run the circuit on statevector simulator to extract the initial state
|
| 804 |
backend = AerSimulator(method='statevector')
|
|
|
|
| 519 |
|
| 520 |
def get_job_result(j):
|
| 521 |
result = j.result() # PrimitiveResult (a container of PubResults)
|
| 522 |
+
log("Waiting for job results (this may take time)...")
|
| 523 |
|
| 524 |
output=[]
|
| 525 |
|
| 526 |
for T_total,pub in zip(T_list,result):
|
| 527 |
|
| 528 |
+
# Try join_data() to combine multiple regs and get_counts() on it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
try:
|
| 530 |
joined = pub.join_data() # join_data concatenates registers along bits axis
|
| 531 |
joined_counts = joined.get_counts()
|
|
|
|
|
|
|
| 532 |
except Exception as e:
|
| 533 |
+
log(f"Error retrieving counts: {e}")
|
| 534 |
joined_counts = None
|
| 535 |
|
| 536 |
+
# Suppress verbose logging by passing None as logger
|
| 537 |
+
pts, counts = load_samples(joined_counts, T_total, logger=None)
|
| 538 |
output+=[estimate_density(pts, counts, bandwidth=0.05, grid_size=output_resolution)]
|
| 539 |
|
| 540 |
+
log(f"Processing complete: {len(output)} timestep(s)")
|
| 541 |
fig = plot_density_isosurface_slider(output, T_list)
|
| 542 |
return output, fig
|
| 543 |
|
|
|
|
| 577 |
output : list[ndarray]
|
| 578 |
List of 3D density arrays, one per timestep
|
| 579 |
fig : go.Figure
|
| 580 |
+
Plotly figure with slider animation through all timesteps (includes T=0 snapshot when available)
|
| 581 |
"""
|
| 582 |
|
| 583 |
if type(ux)==str:
|
| 584 |
ux,uy,uz=str_to_lambda(ux,uy,uz)
|
| 585 |
|
| 586 |
# Convert string init_state_prep_circ to circuit if needed (matches original logic)
|
| 587 |
+
init_state_label = init_state_prep_circ if isinstance(init_state_prep_circ, str) else "custom"
|
| 588 |
+
if isinstance(init_state_prep_circ, str):
|
| 589 |
init_state_prep_circ=get_named_init_state_circuit(n,init_state_prep_circ)
|
| 590 |
|
| 591 |
+
initial_snapshot = None
|
| 592 |
+
try:
|
| 593 |
+
initial_snapshot = show_initial_distribution(
|
| 594 |
+
n=n,
|
| 595 |
+
init_state_name=str(init_state_label),
|
| 596 |
+
plot=False,
|
| 597 |
+
return_data=True,
|
| 598 |
+
init_state_circuit=init_state_prep_circ,
|
| 599 |
+
)
|
| 600 |
+
except Exception as exc:
|
| 601 |
+
print(f"Warning: Unable to compute initial distribution snapshot: {exc}")
|
| 602 |
+
|
| 603 |
qc_list=get_circuit(n,ux,uy,uz,init_state_prep_circ,T_list,vel_resolution,measure=False)
|
| 604 |
backend = AerSimulator(method = 'statevector')
|
| 605 |
output=[]
|
|
|
|
| 655 |
x_coords = np.linspace(0, 1, 2**n)
|
| 656 |
X = np.meshgrid(x_coords, x_coords, x_coords, indexing='ij')
|
| 657 |
|
| 658 |
+
outputs_for_plot = output.copy()
|
| 659 |
+
times_for_plot = list(T_list)
|
| 660 |
+
if initial_snapshot is not None:
|
| 661 |
+
initial_density, _ = initial_snapshot
|
| 662 |
+
if times_for_plot and times_for_plot[0] == 0:
|
| 663 |
+
outputs_for_plot[0] = initial_density
|
| 664 |
+
else:
|
| 665 |
+
outputs_for_plot = [initial_density] + outputs_for_plot
|
| 666 |
+
times_for_plot = [0] + times_for_plot
|
| 667 |
+
|
| 668 |
+
# Create figure with slider for all timesteps (including T=0 if available)
|
| 669 |
+
fig = _create_slider_figure(outputs_for_plot, times_for_plot, X)
|
| 670 |
return output, fig
|
| 671 |
|
| 672 |
|
|
|
|
| 749 |
|
| 750 |
|
| 751 |
def show_initial_distribution(
|
| 752 |
+
n: int,
|
| 753 |
+
init_state_name: str = "sin",
|
| 754 |
# Sinusoidal parameters (frequency multipliers)
|
| 755 |
sine_k_x: float = 1.0,
|
| 756 |
sine_k_y: float = 1.0,
|
|
|
|
| 761 |
gauss_cz: float = None,
|
| 762 |
gauss_sigma: float = None,
|
| 763 |
# Display options
|
| 764 |
+
plot: bool = True,
|
| 765 |
+
return_data: bool = False,
|
| 766 |
+
init_state_circuit=None,
|
| 767 |
):
|
| 768 |
"""
|
| 769 |
Visualize the initial distribution by running the state preparation circuit
|
|
|
|
| 785 |
Whether to display the 3D isosurface plot (default=True)
|
| 786 |
return_data : bool
|
| 787 |
Whether to return the distribution data (default=False)
|
| 788 |
+
init_state_circuit : QuantumCircuit, optional
|
| 789 |
+
Pre-built circuit to evaluate. When provided, ``init_state_name`` and the
|
| 790 |
+
associated parameters are ignored and the supplied circuit is simulated
|
| 791 |
+
directly.
|
| 792 |
|
| 793 |
Returns
|
| 794 |
-------
|
|
|
|
| 802 |
"""
|
| 803 |
N = 2**n
|
| 804 |
|
| 805 |
+
# Determine the state preparation circuit. Either use the provided circuit
|
| 806 |
+
# (useful when custom circuits are passed in) or construct one from the
|
| 807 |
+
# named presets for standalone previews.
|
| 808 |
+
if init_state_circuit is not None:
|
| 809 |
+
init_state_prep_circ = init_state_circuit.copy()
|
| 810 |
+
else:
|
| 811 |
+
init_state_prep_circ = get_named_init_state_circuit(
|
| 812 |
+
n,
|
| 813 |
+
init_state_name,
|
| 814 |
+
sine_k_x=sine_k_x,
|
| 815 |
+
sine_k_y=sine_k_y,
|
| 816 |
+
sine_k_z=sine_k_z,
|
| 817 |
+
gauss_cx=gauss_cx,
|
| 818 |
+
gauss_cy=gauss_cy,
|
| 819 |
+
gauss_cz=gauss_cz,
|
| 820 |
+
gauss_sigma=gauss_sigma,
|
| 821 |
+
)
|
| 822 |
|
| 823 |
# Run the circuit on statevector simulator to extract the initial state
|
| 824 |
backend = AerSimulator(method='statevector')
|
qlbm_embedded.py
CHANGED
|
@@ -674,7 +674,7 @@ def _create_box_figure(lx, ly, lz, title):
|
|
| 674 |
j=[3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
|
| 675 |
k=[0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
|
| 676 |
opacity=0.2,
|
| 677 |
-
color=
|
| 678 |
flatshading=True,
|
| 679 |
name=title,
|
| 680 |
showscale=False
|
|
@@ -1064,17 +1064,8 @@ def run_simulation():
|
|
| 1064 |
elif _state.qlbm_backend_type == "QPU":
|
| 1065 |
backend_info += f" - {_state.qlbm_selected_qpu}"
|
| 1066 |
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
f" Grid Size: {_state.qlbm_grid_size} × {_state.qlbm_grid_size} × {_state.qlbm_grid_size}",
|
| 1070 |
-
f" Time Steps: {_state.qlbm_time_steps}",
|
| 1071 |
-
f" Distribution: {_state.qlbm_dist_type}",
|
| 1072 |
-
f" Boundary: {_state.qlbm_boundary_condition}",
|
| 1073 |
-
f" Backend: {backend_info}",
|
| 1074 |
-
f" Velocity: vx={_state.qlbm_vx_expr}, vy={_state.qlbm_vy_expr}, vz={_state.qlbm_vz_expr}",
|
| 1075 |
-
]
|
| 1076 |
-
for line in config_lines:
|
| 1077 |
-
log_to_console(line)
|
| 1078 |
|
| 1079 |
last_logged_percent = 0
|
| 1080 |
def _progress_callback(percent):
|
|
|
|
| 674 |
j=[3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
|
| 675 |
k=[0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
|
| 676 |
opacity=0.2,
|
| 677 |
+
color="rgba(255,218,185,0.25)",
|
| 678 |
flatshading=True,
|
| 679 |
name=title,
|
| 680 |
showscale=False
|
|
|
|
| 1064 |
elif _state.qlbm_backend_type == "QPU":
|
| 1065 |
backend_info += f" - {_state.qlbm_selected_qpu}"
|
| 1066 |
|
| 1067 |
+
log_to_console("Job Initiated")
|
| 1068 |
+
log_to_console(f"Grid Size: {_state.qlbm_grid_size}×{_state.qlbm_grid_size}×{_state.qlbm_grid_size}, Time Steps: {_state.qlbm_time_steps}, Distribution: {_state.qlbm_dist_type}, Boundary: {_state.qlbm_boundary_condition}, Backend: {backend_info}, Velocity: vx={_state.qlbm_vx_expr}, vy={_state.qlbm_vy_expr}, vz={_state.qlbm_vz_expr}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1069 |
|
| 1070 |
last_logged_percent = 0
|
| 1071 |
def _progress_callback(percent):
|