Spaces:
Paused
Paused
File size: 49,118 Bytes
7f9a25d b0f5437 7f9a25d 610d3d1 7f9a25d 610d3d1 7f9a25d b0f5437 7f9a25d b0f5437 7f9a25d c131b0b 7f9a25d b5dbacc 7f9a25d 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 6ca7a4a 610d3d1 7f9a25d c131b0b 7f9a25d 4f10fce 7f9a25d fcf8f5a 7f9a25d c131b0b 7f9a25d c131b0b 7f9a25d c131b0b 7f9a25d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
"""UI components and build_ui function for the EM module."""
from __future__ import annotations
from typing import TYPE_CHECKING
import plotly.graph_objects as go
from trame.widgets import html as trame_html, vuetify3, plotly as plotly_widgets
from pyvista.trame.ui import plotter_ui
from .state import state, ctrl, get_server
from .globals import plotter, GRID_SIZES
from .geometry import build_geometry_placeholder as _build_geometry_placeholder
from .excitation import build_excitation_placeholder as _build_excitation_placeholder
from .simulation import run_simulation_only, reset_to_defaults, stop_simulation_handler, process_uploaded_em_job_result
from .exports import (
export_vtk, export_vtk_all_frames, export_mp4,
export_sim_timeseries_csv, export_sim_timeseries_png, export_sim_timeseries_html,
export_qpu_timeseries_csv, export_qpu_timeseries_png, export_qpu_timeseries_html,
)
from .handlers import build_qubit_plot
if TYPE_CHECKING:
pass
# ---------------------------------------------------------------------------
# Placeholder builders for preview areas
# ---------------------------------------------------------------------------
def _build_empty_figure(message: str = "") -> go.Figure:
"""Build an empty placeholder figure with optional message."""
fig = go.Figure()
if message:
fig.add_annotation(
text=message,
x=0.5, y=0.5, showarrow=False,
font=dict(size=16, color="#888")
)
fig.update_layout(
margin=dict(l=20, r=20, t=40, b=20),
paper_bgcolor="#ffffff",
plot_bgcolor="#ffffff",
height=400,
)
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)
return fig
# ---------------------------------------------------------------------------
# Main UI Builder
# ---------------------------------------------------------------------------
def build_ui():
"""Render the EM UI inside the host layout."""
_server = get_server()
if _server is None or not state.bound or not ctrl.bound:
raise RuntimeError('Call set_server(server) before build_ui().')
with vuetify3.VContainer(fluid=True, classes="pa-0 fill-height"):
# Upload Dialog
with vuetify3.VDialog(v_model=("show_upload_dialog", False), max_width="500px"):
with vuetify3.VCard():
vuetify3.VCardTitle("Upload Geometry")
with vuetify3.VCardText(classes="py-1 px-2"):
vuetify3.VFileInput(
show_size=True,
label="Select geometry file",
accept=".vtp,.vtk,.glb,.stl",
update_binary=("uploaded_file_info", 1),
)
with vuetify3.VCardActions():
vuetify3.VSpacer()
vuetify3.VBtn("Cancel", click="show_upload_dialog = false")
# Snackbars for status messages
vuetify3.VSnackbar(
v_model=("show_upload_status", False),
children=["{{ upload_status_message }}"],
timeout=4000,
location="bottom right",
color="primary",
variant="tonal",
)
vuetify3.VSnackbar(
v_model=("show_export_status", False),
children=["{{ export_status_message }}"],
timeout=4000,
location="bottom right",
color="primary",
variant="tonal",
)
with vuetify3.VRow(no_gutters=True, classes="fill-height"):
# Left Column - Configuration
with vuetify3.VCol(cols=5, classes="pa-1 d-flex flex-column"):
_build_overview_card()
_build_geometry_card()
_build_excitation_card()
_build_material_card()
_build_time_card()
_build_meshing_card()
_build_backends_card()
_build_output_preferences_card()
_build_run_buttons()
_build_job_upload_card()
vuetify3.VSpacer()
_build_reset_button()
# Right Column - Visualization
with vuetify3.VCol(cols=7, classes="pa-1 d-flex flex-column"):
_build_output_config_card()
_build_main_plot_area()
_build_qpu_plot_area()
_build_no_geometry_placeholder()
_build_status_console()
# Floating status window
_build_status_window()
def _build_overview_card():
"""Build the Overview/Introduction card."""
with vuetify3.VCard(classes="mb-1", style=("overview_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Overview", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
vuetify3.VSelect(
label="Select a problem",
v_model=("problem_selection", None),
items=(
"problem_options",
[
"Propagation in a given medium (no bodies)",
"Scattering from a perfectly conducting body",
],
),
placeholder="Select a problem",
density="compact",
color="primary",
)
def _build_geometry_card():
"""Build the Geometry configuration card."""
with vuetify3.VCard(classes="mb-1", style=("geometry_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Geometry", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
vuetify3.VSelect(
label="Select",
v_model=("geometry_selection", None),
items=("geometry_options",),
placeholder="Select",
density="compact",
color="primary",
)
with vuetify3.VContainer(v_if="geometry_selection === 'Square Metallic Body'", classes="pa-0 mt-2"):
with vuetify3.VRow(dense=True):
with vuetify3.VCol():
with vuetify3.VTooltip("Square hole edge length s in domain units [0,1]. Must be ≤ 1. UI-only.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("hole_size_edge", 0.2),
label="Hole Edge Length [0 - 1]",
type="number",
step=0.05,
min=0,
density="compact",
color="primary",
)
with vuetify3.VCol():
with vuetify3.VTooltip("Hole center as (x, y). Both x and y must be strictly within (0,1). Example: (0.5, 0.5). UI-only.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("hole_center_pair", "(0.5, 0.5)"),
label="Hole Center (X, Y)",
density="compact",
color="primary",
)
with vuetify3.VRow(dense=True, classes="mt-1"):
with vuetify3.VCol(cols=12):
vuetify3.VSwitch(
v_model=("hole_snap", True),
label="Snap edges to nearest grid lines",
color="primary",
inset=True,
density="compact",
)
vuetify3.VAlert(
v_if="hole_error_message",
type="error",
variant="tonal",
density="compact",
children=["{{ hole_error_message }}"],
classes="mt-1",
)
def _build_excitation_card():
"""Build the Excitation/Initial State configuration card."""
with vuetify3.VCard(classes="mb-1", style=("excitation_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Excitation: Initial State", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
with vuetify3.VRow(classes="d-flex align-center", dense=True, no_gutters=True):
with vuetify3.VCol(classes="flex-grow-1"):
vuetify3.VSelect(
label="Select",
v_model=("dist_type", None),
items=("dist_type_options", ["None", "Delta", "Gaussian"]),
placeholder="Select",
density="compact",
color="primary",
)
with vuetify3.VCol(cols="auto", classes="ml-1"):
with vuetify3.VTooltip("Show or hide configuration for the selected excitation", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
with vuetify3.VBtn(
icon=True,
density="compact",
variant="text",
click="excitation_config_open = !excitation_config_open",
disabled=("!dist_type", False),
v_bind="props",
):
vuetify3.VIcon("mdi-cog", color=("excitation_config_open ? 'primary' : 'grey'",))
trame_html.Span("Toggle parameter inputs for the chosen excitation")
# Delta config
with vuetify3.VExpandTransition():
with vuetify3.VSheet(
v_if="excitation_config_open && dist_type === 'Delta'",
classes="pa-2 mt-1 rounded-lg",
style="background-color: rgba(95,37,159,0.03); border: 1px solid rgba(95,37,159,0.15);",
):
with vuetify3.VTooltip("Impulse position (x, y) in [0,1]. Example: (0.6, 0.6).", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("peak_pair", "(0.5, 0.5)"),
label="Peak (x, y) in [0,1]",
density="compact",
color="primary",
)
# Gaussian config
with vuetify3.VExpandTransition():
with vuetify3.VSheet(
v_if="excitation_config_open && dist_type === 'Gaussian'",
classes="pa-2 mt-1 rounded-lg",
style="background-color: rgba(95,37,159,0.03); border: 1px solid rgba(95,37,159,0.15);",
):
with vuetify3.VRow(dense=True):
with vuetify3.VCol():
with vuetify3.VTooltip("Gaussian center μ (x, y) in [0,1]. Example: (0.5, 0.5).", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("mu_pair", "(0.5, 0.5)"),
label="Mu (x, y) in [0,1]",
density="compact",
color="primary",
)
with vuetify3.VRow(dense=True, classes="mt-1"):
with vuetify3.VCol():
with vuetify3.VTooltip("Gaussian spread σx in [0,1] of domain length.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("sigma_x", 0.25),
label="Sigma X (0–1)",
type="number",
step="0.01",
density="compact",
color="primary",
)
with vuetify3.VCol():
with vuetify3.VTooltip("Gaussian spread σy in [0,1] of domain length.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("sigma_y", 0.15),
label="Sigma Y (0–1)",
type="number",
step="0.01",
density="compact",
color="primary",
)
vuetify3.VAlert(v_if="excitation_error_message", type="error", variant="tonal", density="compact", children=["{{ excitation_error_message }}"], classes="mt-1")
vuetify3.VAlert(
v_if="excitation_info_message",
type="info",
variant="tonal",
density="compact",
children=["{{ excitation_info_message }}"],
classes="mt-1",
style="white-space: pre-line;",
)
def _build_material_card():
"""Build the Material Properties card."""
with vuetify3.VCard(classes="mb-1", style="font-size: 0.8rem;"):
with vuetify3.VCardTitle("Material Properties (Medium)", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
with vuetify3.VRow(dense=True):
with vuetify3.VCol(cols="6"):
with vuetify3.VTooltip("Relative permittivity. ε_r = ε / ε₀. Default 1.0 (free space).", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(v_bind="props", v_model=("coeff_permittivity", 1.0), label="Permittivity (εr)", type="number", step="0.1", density="compact", color="primary")
with vuetify3.VCol(cols="6"):
with vuetify3.VTooltip("Relative permeability. μ_r = μ / μ₀. Default 1.0 (non-magnetic).", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(v_bind="props", v_model=("coeff_permeability", 1.0), label="Permeability (μr)", type="number", step="0.1", density="compact", color="primary")
def _build_time_card():
"""Build the Time configuration card."""
with vuetify3.VCard(classes="mb-1", style="font-size: 0.8rem;"):
with vuetify3.VCardTitle("Time", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
with vuetify3.VTooltip("Sets the total duration for the simulation to run.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
v_model=("T", 1.0),
label="Total Time (T)",
type="number",
step="0.1",
density="compact",
color="primary",
)
def _build_meshing_card():
"""Build the Meshing card with qubit plot hover."""
with vuetify3.VCard(classes="mb-1", style=("meshing_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Meshing", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
with vuetify3.Template(v_slot_activator="{ props }"):
with vuetify3.VSlider(
v_bind="props",
v_model=("nx_slider_index", None),
label="No. of points per direction:",
min=0,
max=len(GRID_SIZES) - 1,
step=1,
show_ticks="always",
thumb_label="always",
density="compact",
color="primary",
):
vuetify3.Template(
v_slot_thumb_label="{ modelValue }",
children=["{{ modelValue === null ? 'Select' : grid_size_labels[modelValue] }}"],
)
# Hover content: enlarged Plotly graph
with vuetify3.VSheet(classes="pa-2", elevation=6, rounded=True, style="width: 644px;"):
qubit_fig_widget = plotly_widgets.Figure(
figure=build_qubit_plot(int(state.nx or 16)),
responsive=True,
style="width: 616px; height: 364px; min-height: 364px;",
)
ctrl.qubit_plot_update = qubit_fig_widget.update
def _build_backends_card():
"""Build the Backends selection card."""
with vuetify3.VCard(classes="mb-1", style=("backend_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Backends", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
with vuetify3.VRow(dense=True, classes="mb-2"):
with vuetify3.VCol():
vuetify3.VAlert(
type="info",
color="primary",
variant="tonal",
density="compact",
children=[
"Selected: ",
"{{ backend_type || '—' }}",
" - ",
"{{ backend_type === 'Simulator' ? selected_simulator : (backend_type === 'QPU' ? selected_qpu : '—') }}",
],
)
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(v_bind="props", text="Choose Backend", color="primary", variant="tonal", block=True)
with vuetify3.VList(density="compact"):
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end", offset=8):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VListItem(v_bind="props", title="Simulator", prepend_icon="mdi-robot-outline", append_icon="mdi-chevron-right")
with vuetify3.VList(density="compact"):
vuetify3.VListItem(title="IBM Qiskit simulator", click="backend_type = 'Simulator'; selected_simulator = 'IBM Qiskit simulator'")
vuetify3.VListItem(title="Statevector Estimator", click="backend_type = 'Simulator'; selected_simulator = 'Statevector Estimator'")
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end", offset=8):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VListItem(v_bind="props", title="QPU", prepend_icon="mdi-chip", append_icon="mdi-chevron-right")
with vuetify3.VList(density="compact"):
vuetify3.VListItem(title="IBM QPU", click="backend_type = 'QPU'; selected_qpu = 'IBM QPU'")
vuetify3.VListItem(title="IonQ QPU", click="backend_type = 'QPU'; selected_qpu = 'IonQ QPU'")
def _build_output_preferences_card():
"""Build the Output Preferences card (appears after backend selection)."""
with vuetify3.VCard(v_if="backend_type", classes="mb-0", style=("output_card_style", "font-size: 0.8rem;")):
with vuetify3.VCardTitle("Output Preferences", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
vuetify3.VCardSubtitle("Select Δt intervals for plotting output snapshots", classes="text-caption font-weight-bold mt-1", style="font-size: 0.75rem;")
with vuetify3.VTooltip("Snapshot interval (Δt). Solver runs at fixed 0.1 s; frames are saved every Δt.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(v_bind="props", v_model=("dt_user", 0.1), label="Δt", type="number", step="0.1", density="compact", color="primary", classes="mt-1")
vuetify3.VAlert(v_if="temporal_warning", type="warning", variant="tonal", density="compact", children=["{{ temporal_warning }}"], classes="mt-1")
# IBM QPU monitor options (single field, single position ONLY)
with vuetify3.VContainer(v_if="backend_type === 'QPU' && selected_qpu === 'IBM QPU'", classes="pa-0 mt-2"):
vuetify3.VAlert(
type="info",
variant="tonal",
density="compact",
children=["IBM QPU: Only ONE field component and ONE monitor position supported."],
classes="mb-2",
)
with vuetify3.VRow(dense=True, classes="mb-1 align-center"):
with vuetify3.VCol(cols=4, sm=3, md=3):
vuetify3.VSelect(
label="Field",
v_model=("qpu_field_components", "Ez"),
items=("ibm_qpu_field_options", ["Ez", "Hx", "Hy"]),
density="compact",
color="primary",
hide_details=True,
style="max-width: 160px;",
)
with vuetify3.VCol(cols=8, sm=9, md=9):
vuetify3.VTextField(
label="Monitor position (x, y) in [0,1]",
v_model=("qpu_monitor_samples", "(0.5, 0.5)"),
density="compact",
color="primary",
hide_details=True,
style="max-width: 320px;",
hint="Single position only for IBM QPU",
)
vuetify3.VAlert(
v_if="qpu_monitor_sample_info",
type="info",
variant="tonal",
density="compact",
children=["{{ qpu_monitor_sample_info }}"],
classes="mb-1",
style="white-space: pre-line;",
)
# Statevector Estimator monitor options (supports multiple fields and positions)
with vuetify3.VContainer(v_if="backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator'", classes="pa-0 mt-2"):
with vuetify3.VRow(dense=True, classes="mb-1 align-center"):
with vuetify3.VCol(cols=4, sm=3, md=3):
vuetify3.VSelect(
label="Field",
v_model=("qpu_field_components", "Ez"),
items=("qpu_field_options", ["All", "Ez", "Hx", "Hy"]),
density="compact",
color="primary",
hide_details=True,
style="max-width: 160px;",
)
with vuetify3.VCol(cols=8, sm=9, md=9):
vuetify3.VTextField(
label="Sample position(s) (x, y) in [0,1]",
v_model=("qpu_monitor_samples", "(0.5, 0.5)"),
density="compact",
color="primary",
hide_details=True,
style="max-width: 320px;",
)
vuetify3.VAlert(
v_if="qpu_monitor_sample_info",
type="info",
variant="tonal",
density="compact",
children=["{{ qpu_monitor_sample_info }}"],
classes="mb-1",
style="white-space: pre-line;",
)
def _build_job_upload_card():
"""Build the Job Result Upload card for loading previously saved QPU results."""
with vuetify3.VCard(classes="mb-1", style="font-size: 0.8rem;"):
with vuetify3.VCardTitle("Upload Results", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2"):
trame_html.Div(
"Retrieve completed job results from IBM or IonQ using the Job ID",
classes="text-caption text-medium-emphasis mb-2",
)
# Platform selector
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VSelect(
v_bind="props",
label="Platform",
v_model=("em_job_platform", "IBM"),
items=("['IBM', 'IonQ']",),
density="compact",
hide_details=True,
color="primary",
classes="mb-2",
prepend_icon="mdi-chip",
)
trame_html.Span("Select the quantum hardware provider (IBM or IonQ)")
# Job ID input
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
label="Job ID",
v_model=("em_job_id", ""),
density="compact",
hide_details=True,
color="primary",
classes="mb-2",
placeholder="e.g., 019b368e-6e22-7525-8512-fd16e0503673",
prepend_icon="mdi-identifier",
)
trame_html.Span("Enter the Job ID (UUID format from IBM or IonQ)")
# Field / monitor / time parameters
with vuetify3.VRow(dense=True, classes="mb-2"):
with vuetify3.VCol(cols=6):
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VSelect(
v_bind="props",
label="Field Type",
v_model=("em_job_field_type", "Ez"),
items=("['Ez', 'Hx', 'Hy']",),
density="compact",
hide_details=True,
color="primary",
)
trame_html.Span("Select which field component to plot (Ez, Hx, Hy)")
with vuetify3.VCol(cols=6):
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
label="Monitor Point (x, y)",
v_model=("em_job_monitor_point", "(0, 0)"),
density="compact",
hide_details=True,
color="primary",
placeholder="(x, y)",
)
trame_html.Span("Integer grid indices of the monitor point")
with vuetify3.VRow(dense=True, classes="mb-2"):
with vuetify3.VCol(cols=4):
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
label="Total Time (T)",
v_model=("em_job_total_time", 1.0),
type="number",
density="compact",
hide_details=True,
color="primary",
)
trame_html.Span("Total simulation time")
with vuetify3.VCol(cols=4):
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
label="Snapshot Δt",
v_model=("em_job_snapshot_dt", 0.1),
type="number",
density="compact",
hide_details=True,
color="primary",
)
trame_html.Span("Time between snapshots")
with vuetify3.VCol(cols=4):
with vuetify3.VTooltip(location="top"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VTextField(
v_bind="props",
label="No. of Points per Direction",
v_model=("em_job_nx", 4),
type="number",
density="compact",
hide_details=True,
color="primary",
)
trame_html.Span("Grid dimension nx (grid is nx × nx)")
vuetify3.VBtn(
text="Retrieve & Generate Plot",
color="secondary",
variant="tonal",
block=True,
disabled=("!em_job_id || em_job_is_processing", True),
loading=("em_job_is_processing", False),
click=process_uploaded_em_job_result,
prepend_icon="mdi-chart-box-outline",
classes="mb-2",
)
# Success message
vuetify3.VAlert(
v_if="em_job_upload_success",
type="success",
variant="tonal",
density="compact",
closable=True,
children=["{{ em_job_upload_success }}"],
classes="mt-2",
)
# Error message
vuetify3.VAlert(
v_if="em_job_upload_error",
type="error",
variant="tonal",
density="compact",
closable=True,
children=["{{ em_job_upload_error }}"],
classes="mt-2",
)
def _build_run_buttons():
"""Build the Run and Stop buttons row."""
with vuetify3.VRow(dense=True, classes="mb-2"):
with vuetify3.VCol(cols=9):
with vuetify3.VTooltip("Starts the quantum simulation with the specified parameters.", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(
v_bind="props",
text=("run_button_text", "RUN!"),
click=run_simulation_only,
color="primary",
block=True,
disabled=("is_running || run_button_text === 'Successful!' || !geometry_selection || !dist_type || !!temporal_warning || nx === null || !backend_type", False),
)
with vuetify3.VCol(cols=3):
with vuetify3.VTooltip("Stop the running simulation", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(
v_bind="props",
text="Stop",
click=stop_simulation_handler,
color="error",
block=True,
disabled=("stop_button_disabled", True),
)
def _build_reset_button():
"""Build the Reset button."""
with trame_html.Div(style="flex: 0 0 auto;"):
with vuetify3.VTooltip("Reset all parameters to their default values", location="bottom", color="primary"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(
v_bind="props",
text="Reset",
click=reset_to_defaults,
color="secondary",
block=True,
)
def _build_output_config_card():
"""Build the Output Configuration card (appears after simulation, not for QPU)."""
with vuetify3.VCard(v_if="simulation_has_run && backend_type !== 'QPU' && !(backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator')", classes="mb-1", style="font-size: 0.8rem;"):
with vuetify3.VCardSubtitle("Output Configuration", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px; font-weight: 600; color: #1A1A1A;"):
with vuetify3.VCardText(classes="py-1 px-2", style="color: #1A1A1A;"):
with vuetify3.VRadioGroup(v_model=("output_type", "Surface Plot"), row=True, density="compact", color="primary"):
vuetify3.VRadio(label="Surface", value="Surface Plot", style="font-weight: 500;")
vuetify3.VRadio(label="Time Series", value="Time Series Plot", style="font-weight: 500;")
# Surface Plot options
with vuetify3.VContainer(v_if="output_type === 'Surface Plot'", classes="pa-0"):
vuetify3.VSelect(v_model=("surface_field", "Ez"), items=("surface_field_options", ["Ez", "Hx", "Hy"]), label="Field Component", density="compact", color="primary", style="font-weight: 500;")
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(v_bind="props", text="DOWNLOAD", color="primary", variant="tonal", block=True, classes="mt-1")
with vuetify3.VList(density="compact"):
vuetify3.VListSubheader("VTK")
vuetify3.VListItem(title="Current frame (VTK)", prepend_icon="mdi-download", click=export_vtk)
vuetify3.VListItem(title="All frames (VTK sequence)", prepend_icon="mdi-download-multiple", click=export_vtk_all_frames)
vuetify3.VDivider()
vuetify3.VListItem(title="Animation (MP4)", prepend_icon="mdi-movie", click=export_mp4)
# Time Series options
with vuetify3.VContainer(v_if="output_type === 'Time Series Plot'", classes="pa-0"):
vuetify3.VSelect(v_model=("timeseries_field", "Ez"), items=("timeseries_field_options", ["All", "Ez", "Hx", "Hy"]), label="Field Component", density="compact", color="primary", style="font-weight: 500;")
vuetify3.VTextarea(
v_model=("timeseries_points", "(0.5, 0.5)"),
label="Monitor Position(s) (x, y) in [0,1]",
hint="e.g., (0.50, 0.50) or multiple comma-separated pairs",
rows=2,
auto_grow=True,
color="primary",
style="font-weight: 500;",
)
vuetify3.VAlert(
v_if="timeseries_point_info",
type="info",
variant="tonal",
density="compact",
children=["{{ timeseries_point_info }}"],
classes="mt-1",
style="white-space: pre-line;",
)
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end"):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(v_bind="props", text="DOWNLOAD", color="primary", variant="tonal", block=True, classes="mt-1")
with vuetify3.VList(density="compact"):
vuetify3.VListItem(title="Download CSV", prepend_icon="mdi-download", click=export_sim_timeseries_csv)
vuetify3.VListItem(title="Download PNG", prepend_icon="mdi-image", click=export_sim_timeseries_png)
vuetify3.VListItem(title="Download HTML", prepend_icon="mdi-file-html", click=export_sim_timeseries_html)
def _build_main_plot_area():
"""Build the main plot area (PyVista for Simulator)."""
with vuetify3.VCard(
v_if="geometry_selection && ((backend_type !== 'QPU' && !(backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator')) || !qpu_ts_ready) && !(is_running && (backend_type === 'QPU' || (backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator')))",
classes="mb-1 flex-grow-1 d-flex flex-column",
style="min-height: 0;",
):
# Running indicator
with vuetify3.VContainer(v_if="is_running", fluid=True, classes="fill-height d-flex flex-column align-center justify-center"):
vuetify3.VProgressCircular(indeterminate=True, size=64, color="primary")
vuetify3.VCardSubtitle("Running simulation...", classes="mt-4")
# Geometry preview (no excitation selected yet)
with vuetify3.VContainer(
v_if="!is_running && geometry_selection && !dist_type",
fluid=True,
classes="pa-0 flex-grow-1 d-flex align-center justify-center",
style="width: 100%; min-height: 560px;",
):
geometry_preview_widget = plotly_widgets.Figure(
figure=_build_geometry_placeholder("Select a geometry to preview."),
responsive=True,
style="width: 100%; height: 100%;",
)
ctrl.geometry_preview_update = geometry_preview_widget.update
# Excitation preview (before simulation runs)
with vuetify3.VContainer(
v_if="!is_running && dist_type && !simulation_has_run",
fluid=True,
classes="pa-0 flex-grow-1 d-flex align-center justify-center",
style="width: 100%; min-height: 580px;",
):
excitation_preview_widget = plotly_widgets.Figure(
figure=_build_excitation_placeholder("Select an excitation to preview."),
responsive=True,
style="width: 100%; height: 100%;",
)
ctrl.excitation_preview_update = excitation_preview_widget.update
# Surface Plot: PyVista view
with vuetify3.VContainer(v_if="!is_running && simulation_has_run && output_type === 'Surface Plot'", fluid=True, classes="pa-0", style=("pyvista_view_style", "aspect-ratio: 1 / 1; width: 100%;")):
view = plotter_ui(plotter)
ctrl.view_update = view.update
# Time Series: Plotly figure
with vuetify3.VContainer(v_if="!is_running && simulation_has_run && output_type === 'Time Series Plot'", fluid=True, classes="d-flex align-center justify-center pa-2", style="overflow: hidden;"):
sim_ts = plotly_widgets.Figure(
figure=go.Figure(layout=dict(width=900, height=660)),
responsive=False,
style="width: 900px; height: 660px;",
)
ctrl.sim_ts_update = sim_ts.update
# Time slider for surface plot
with vuetify3.VContainer(v_if="simulation_has_run && output_type === 'Surface Plot' && backend_type !== 'QPU' && !(backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator')", fluid=True, classes="pa-0 mt-2"):
vuetify3.VSlider(v_model=("time_val", 0.0), label="Time", min=0, max=("T", 10.0), step=("dt_user", 0.1), thumb_label="always", density="compact", color="primary")
def _build_qpu_plot_area():
"""Build the QPU plot area (Plotly time series)."""
with vuetify3.VCard(v_if="geometry_selection && (backend_type === 'QPU' || (backend_type === 'Simulator' && selected_simulator === 'Statevector Estimator')) && (is_running || qpu_ts_ready)", classes="flex-grow-1", style="min-height: 0;"):
# Running indicator
with vuetify3.VContainer(v_if="is_running", fluid=True, classes="fill-height d-flex flex-column align-center justify-center"):
vuetify3.VProgressCircular(indeterminate=True, size=64, color="primary")
vuetify3.VCardSubtitle("Running {{ backend_type === 'QPU' ? selected_qpu : selected_simulator }}...", classes="mt-4")
# QPU timeseries with toolbar
with vuetify3.VContainer(v_if="!is_running && qpu_ts_ready", fluid=True, classes="pa-2"):
with vuetify3.VToolbar(density="compact", flat=True, color="transparent", classes="px-0"):
vuetify3.VSelect(
label="Component",
v_model=("qpu_plot_filter", "All"),
items=("qpu_plot_field_options", ["All"]),
density="compact",
color="primary",
hide_details=True,
style="max-width: 180px; margin-right: 8px;",
disabled=("!qpu_ts_ready", True),
update_modelValue=(ctrl.qpu_set_plot_filter, "[$event]")
)
vuetify3.VSelect(
label="Position",
v_model=("qpu_plot_position_filter", "All positions"),
items=("qpu_plot_position_options", ["All positions"]),
density="compact",
color="primary",
hide_details=True,
style="max-width: 200px; margin-right: 8px;",
disabled=("!qpu_ts_ready", True),
update_modelValue=(ctrl.qpu_set_plot_position_filter, "[$event]")
)
vuetify3.VSpacer()
vuetify3.VBtn(
text="Clear Selection",
color="secondary",
variant="text",
click=ctrl.on_qpu_ts_clear,
disabled=("!qpu_ts_ready", True),
)
with vuetify3.VMenu(open_on_hover=True, close_on_content_click=True, location="end", offset=8):
with vuetify3.Template(v_slot_activator="{ props }"):
vuetify3.VBtn(
v_bind="props",
text="DOWNLOAD",
color="primary",
variant="tonal",
disabled=("!qpu_ts_ready", True),
)
with vuetify3.VList(density="compact"):
vuetify3.VListItem(title="Download CSV", prepend_icon="mdi-download", click=export_qpu_timeseries_csv, disabled=("!qpu_ts_ready", True))
vuetify3.VListItem(title="Download PNG", prepend_icon="mdi-image", click=export_qpu_timeseries_png, disabled=("!qpu_ts_ready", True))
vuetify3.VListItem(title="Download HTML", prepend_icon="mdi-file-html", click=export_qpu_timeseries_html, disabled=("!qpu_ts_ready", True))
trame_html.Div(style="height: 6px;")
# Plotly figure for QPU timeseries
qpu_ts_widget = plotly_widgets.Figure(
figure=go.Figure(layout=dict(width=900, height=660)),
responsive=False,
style=("qpu_plot_style", "display: none; width: 900px; height: 660px; margin: 0 auto;"),
click=ctrl.on_qpu_ts_click,
)
ctrl.qpu_ts_update = qpu_ts_widget.update
def _build_no_geometry_placeholder():
"""Build placeholder when no geometry is selected."""
with vuetify3.VContainer(v_if="!geometry_selection", fluid=True, classes="flex-grow-1 d-flex align-center justify-center text-medium-emphasis"):
vuetify3.VCardText("Select a geometry to display the preview and results.")
def _build_status_console():
"""Build the Status/Console card."""
with vuetify3.VCard(classes="mt-2", style="font-size: 0.8rem;"):
with vuetify3.VCardTitle("Status", classes="text-subtitle-1 text-primary", style="font-size: 0.9rem; padding: 6px 10px;"):
pass
with vuetify3.VCardText(classes="py-1 px-2", style="height: 150px; overflow-y: auto; background-color: #f5f5f5; font-family: monospace;"):
vuetify3.VTextarea(
v_model=("console_output", ""),
readonly=True,
auto_grow=False,
rows=6,
variant="plain",
hide_details=True,
style="font-family: monospace; width: 100%; height: 100%;"
)
def _build_status_window():
"""Build the floating status window (bottom right)."""
with vuetify3.VCard(
v_if="status_visible",
style="position: fixed; bottom: 16px; right: 16px; z-index: 1000; min-width: 320px; max-width: 450px;",
elevation=8
):
with vuetify3.VCardTitle(classes="d-flex align-center", style="font-size: 0.95rem; padding: 8px 12px;"):
vuetify3.VIcon("mdi-information-outline", size="small", classes="mr-2")
trame_html.Span("Simulation Status")
vuetify3.VSpacer()
vuetify3.VBtn(
icon="mdi-close",
size="x-small",
variant="text",
click="status_visible = false"
)
vuetify3.VDivider()
with vuetify3.VCardText(classes="py-2 px-3"):
vuetify3.VAlert(
type=("status_type", "info"),
variant="tonal",
density="compact",
children=["{{ status_message }}"]
)
with vuetify3.VContainer(v_if="show_progress", classes="pa-0 mt-2"):
vuetify3.VProgressLinear(
model_value=("simulation_progress", 0),
color="primary",
height=6,
striped=True
)
trame_html.Div(
"{{ simulation_progress }}% complete",
classes="text-caption text-center mt-1",
style="font-size: 0.75rem;"
)
|