Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trame Dashboard #651

Merged
merged 112 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
87c7149
Added trame dashboard
proy30 Jul 22, 2024
490b747
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 22, 2024
5c172f4
Added 'variable referencing' tab in lattice settings
proy30 Jul 22, 2024
5cff7a4
Fix merge conflict
proy30 Jul 22, 2024
8e30ff0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 22, 2024
76e53da
Imported elements module for proper simulation running
proy30 Jul 23, 2024
e094e65
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Jul 23, 2024
261e436
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
40b6d68
Labeled static methods in analyzeFunctions
proy30 Jul 23, 2024
fd7fdc3
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Jul 23, 2024
62ae889
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
2267efe
Added static methods across all files which need
proy30 Jul 23, 2024
30ee774
fix: fixed CodeQL warning
proy30 Jul 23, 2024
cd0b99e
fix: ensuring itrable input in generalFunctions.py
proy30 Jul 23, 2024
ea303ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
87bd1b8
Fixed minor CodeQL errors
proy30 Jul 24, 2024
cf51f35
Added base functionality to print in terminal view
proy30 Jul 24, 2024
0581082
Added files to .gitignore for Trame Dashboard
proy30 Aug 1, 2024
8391a8e
Minor format update and remove obsolete file now in .gitignore
proy30 Aug 1, 2024
dfb421b
Nearly completed terminal integration
proy30 Aug 1, 2024
aeb2bc2
Updated Trame Dashboard .gitignore
proy30 Aug 1, 2024
f9e98ce
Removed file reading for beam distribution and lattice elements
proy30 Aug 1, 2024
11608f4
Removed 'workflow' options
proy30 Aug 2, 2024
caaeacd
Added entry point to impactx-dashboard
proy30 Aug 2, 2024
b2ed9fa
Added __init__ files
proy30 Aug 2, 2024
de0795b
Created entry point
proy30 Aug 2, 2024
3f4edd5
File references are relative paths
proy30 Aug 2, 2024
8e3e30e
Deletion of main.py (part of file rename)
proy30 Aug 2, 2024
9f0efa8
Updated .gitignore
proy30 Aug 2, 2024
f683975
Updated file path reference for plotting over position plot
proy30 Aug 2, 2024
a75fe11
distribution and lattice variables call another function
proy30 Aug 2, 2024
2b80bd6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2024
74dc33f
Renamed class names
proy30 Aug 3, 2024
214b9e3
fixing pre-commit.ci errors
proy30 Aug 3, 2024
77173ff
Removed unused code in simulation
proy30 Aug 3, 2024
2f93347
Fixed convention and updated docstring/function names for Distributio…
proy30 Aug 3, 2024
9b8c4f3
Updated docstrings
proy30 Aug 3, 2024
9e82486
Fixed function convention spacing
proy30 Aug 3, 2024
160e7ee
Updated function conventions/renamed
proy30 Aug 3, 2024
0802ad8
Renamed files
proy30 Aug 3, 2024
f9f0e51
Deleted/removed unused files, some format update
proy30 Aug 3, 2024
5b2d022
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 3, 2024
da7eb88
Fixing pre-commit.ci
proy30 Aug 3, 2024
a25a080
Corrected f-string formatting
proy30 Aug 3, 2024
172a901
update .gitignore
proy30 Aug 3, 2024
b0e1315
moved main() to own file, jupyter-specific code in own file
proy30 Aug 4, 2024
0dd5ec7
Added class docstrings
proy30 Aug 4, 2024
e37c617
Updated requirements.txt
proy30 Aug 4, 2024
ffe6cd5
Modified code to follow Python/ImpactX styling and convention
proy30 Aug 4, 2024
12903a7
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 4, 2024
f52b0e1
Fixing some more conventions
proy30 Aug 4, 2024
98c1e96
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2024
736ed10
Allow phase space projections to display
proy30 Aug 4, 2024
a6adc6d
Squash, Adding originalPhaseSpaceProjections plot to Trame
proy30 Aug 4, 2024
14694d0
Squash, removed histogram from originalPlot and changed to scatter
proy30 Aug 4, 2024
14d062e
Squash
proy30 Aug 4, 2024
429d055
Updated phase space projection
proy30 Aug 5, 2024
6692ea7
Disabled not fully completed functionalities
proy30 Aug 5, 2024
c481e5b
fixed class naming convention
proy30 Aug 5, 2024
8282410
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 5, 2024
d40b5fd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
cd75577
Added trame_setup.py
proy30 Aug 5, 2024
47da53e
Updated requirements.txt
proy30 Aug 5, 2024
ecd281c
Added ability to switch between png and interactive for phase space
proy30 Aug 5, 2024
89aa970
Updated gitignore
proy30 Aug 5, 2024
0a32b52
Disabled non-completed features
proy30 Aug 5, 2024
d3427a4
Added initial doxygen
proy30 Aug 5, 2024
5fa1120
Added xterm with broken functionality
proy30 Aug 5, 2024
c0e73a9
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 5, 2024
c5f45b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
16c3ec1
Added xterm library
proy30 Aug 5, 2024
b7d04a5
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 5, 2024
41b5192
xTerm init function created
proy30 Aug 7, 2024
2d376ab
Fixed simulation code
proy30 Aug 7, 2024
1257e38
Added simple integration of simulation progress in terminal
proy30 Aug 7, 2024
1f19694
Attempt at fixing loading diags file
proy30 Aug 7, 2024
dcb1ad0
Commented out unused toolbar elements
proy30 Aug 7, 2024
82ad3a3
delete code for unused toolbar elements
proy30 Aug 7, 2024
664ac96
Removed commented out code and fixed some format
proy30 Aug 7, 2024
5c3b351
Modified doxygen for dashboard
proy30 Aug 7, 2024
42b15dd
Updated minor bugs
proy30 Aug 7, 2024
2ae0f79
Removed code that is not used
proy30 Aug 7, 2024
e80563e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2024
2811b5a
MPI support in phase_space
proy30 Aug 7, 2024
b591d2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2024
df15f65
MPI support in phase_space
proy30 Aug 7, 2024
ad4e331
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 7, 2024
e637917
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2024
9d7051c
Doc: Update Dashboard
ax3l Aug 8, 2024
997eb84
Jupyter: Simplify/Rename Imports
ax3l Aug 8, 2024
bab94e0
Update Screenshot
ax3l Aug 8, 2024
075f99e
Run `dos2unix` on all files
ax3l Aug 8, 2024
c979354
Docs: Developer Module
ax3l Aug 8, 2024
a3be9d9
Copyright Headers
ax3l Aug 8, 2024
f72b2c2
Removed debug statements
proy30 Aug 8, 2024
4f2cf0c
Removed validation check for pos. number
proy30 Aug 8, 2024
05511a5
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 8, 2024
a883e3a
Update Doc Lingo
ax3l Aug 8, 2024
56fc74a
Usage Navigation
ax3l Aug 8, 2024
65ba614
removed unused code
proy30 Aug 8, 2024
c58de55
Adjusted plotting over s default columns
proy30 Aug 8, 2024
ef4d68b
Set slice_step_diagnostics to True
proy30 Aug 8, 2024
f88255e
Updated diags file paths to use globbing for flexible naming
proy30 Aug 8, 2024
4baeee9
Removed all print debug statements
proy30 Aug 8, 2024
fa3719a
Moved reading of diags filed to once simulation is ran
proy30 Aug 8, 2024
c11c455
Renamed save_distribution/lattice functions
proy30 Aug 8, 2024
ca16f77
renamed simulation variables
proy30 Aug 8, 2024
6b73060
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
6829202
Removed 'step' and 's' headers for user selection for plot_over_s
proy30 Aug 8, 2024
083d8fd
Added 'keV' to kin_energy units option
proy30 Aug 9, 2024
ea65aa3
Merge branch 'development' of github.com:proy30/impactx into development
proy30 Aug 9, 2024
5b7a7df
Docs: Developer Deps for Trame
ax3l Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ cmake-build-*/
.DS_Store
.AppleDouble
.LSOverride

#####################
# Trame Dashboard (output files are temporary) #
#####################
src/python/impactx/diags*
src/python/impactx/*.png
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Usage
usage/examples
usage/python
usage/parameters
usage/dashboard
usage/workflows

Data Analysis
Expand Down
87 changes: 87 additions & 0 deletions docs/source/usage/dashboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
.. _usage-dashboard:

Dashboard
=========

ImpactX Dashboard is a browser-based interface to ImpactX.
It provides a graphical interface to a subset of ImpactX functionality.

.. note::

ImpactX Dashboard is provided as a preview and continues to be developed.
Let us know in GitHub `discussions <https://github.com/ECP-WarpX/impactx/discussions>`__ and `issues <https://github.com/ECP-WarpX/impactx/issues>`__ how it works for you and what kind of workflows you would like to run in it.


Launching the Dashboard
-----------------------

The ImpactX Dashboard can be run in two modes, as a standalone browser application or inside a Jupyter notebook.

1. **Standalone browser application:**
After installation of ImpactX including the Python modules, launch:

.. code-block:: bash

impactx-dashboard

2. **JupyterLab:**
Start `JupyterLab <https://jupyter.org/install>`__, e.g., logging into a Jupyter service at an HPC center or locally on your computer using:

.. code-block:: bash

jupyter-lab

Inside JupyterLab, run the following Python code in a notebook to initialize and display the dashboard:

.. code-block:: python

from impactx.dashboard import JupyterApp

# Create new application instance
app = JupyterApp()

# Start the server and wait for the UI to be ready
await app.ui.ready

# Display the UI in the JupyterLab notebook
app.ui


Navigation
----------

The user-friendly interface includes multiple tabs and menu options, intended to be navigated from top to bottom:

- **Input Tab**: Allows to adjust simulation input parameters.
- **Run Tab**: Enables to run simulations and monitor their progress.
- **Analyze Tab**: Provides tools to visualize and analyze simulation results.

.. figure:: https://gist.githubusercontent.com/ax3l/b56aa3c3261f9612e276f3198b34f771/raw/11bfe461a24e1daa7fd2d663c686b0fcc2b6e305/dashboard.png
:align: center
:width: 75%
:alt: phase space ellipse

Input section in the dashboard.


Developers
----------

Additional Dependencies
"""""""""""""""""""""""

Additional dependencies to ImpactX for the dashboard are included relative ImpactX source directory:

.. code-block:: bash

python -m pip install -r src/python/impactx/dashboard/requirements.txt

Python Module
"""""""""""""

After installing only the ImpactX Python bindings, one can directly run the dashboard modules from the source tree during development, too.
For this, navigate in the ImpactX source directory to the ``src/python/impactx`` directory and run:

.. code-block:: bash

python -m dashboard
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,9 @@ def build_extension(self, ext):
# new PEP 639 format
license="BSD-3-Clause-LBNL",
license_files=["LICENSE"],
entry_points={
"console_scripts": [
"impactx-dashboard=impactx.dashboard.__main__:main",
],
},
)
Empty file.
101 changes: 101 additions & 0 deletions src/python/impactx/dashboard/Analyze/analyzeFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""
This file is part of ImpactX

Copyright 2024 ImpactX contributors
Authors: Parthib Roy, Axel Huebl
License: BSD-3-Clause-LBNL
"""

import pandas as pd

from ..trame_setup import setup_server

server, state, ctrl = setup_server()

# -----------------------------------------------------------------------------
# Content
# -----------------------------------------------------------------------------


class AnalyzeFunctions:
"""
Helper functions for
preparing the contents for the 'Analyze' page
"""

# -----------------------------------------------------------------------------
# Functions for Beam Characteristic and Ref particle data table
# -----------------------------------------------------------------------------

@staticmethod
def load_data(file_path):
"""
Reads data from the provided file path.
:param file_path: The path to the file to be read.
:return: A DataFrame containing the data from the file.
"""

df = pd.read_csv(file_path, sep=" ")
return df

@staticmethod
def convert_to_dict(combined_data):
"""
Converts data to dictionary format
for Vuetify data table.
:param combined_data: The DataFrame to be converted.
:return: A tuple containing the data as a list of dictionaries and the headers.
"""

dictionary = combined_data.to_dict(orient="records")
columns = combined_data.columns
headers = [
{"text": column.strip(), "value": column.strip()} for column in columns
]
return dictionary, headers

@staticmethod
def combine_files(file1_name, file2_name):
"""
Merges two files together.
:param file1_name: The name of the first file.
:param file2_name: The name of the second file.
:return: A DataFrame containing the merged data from the two files.
"""

file1 = AnalyzeFunctions.load_data(file1_name)
file2 = AnalyzeFunctions.load_data(file2_name)
return pd.merge(file1, file2, how="outer")

@staticmethod
def filter_headers(allHeaders, selected_headers):
"""
Retrieves only user-selected headers.
:param allHeaders: The list of all headers.
:param selected_headers: The list of headers selected by the user.
:return: A list of filtered headers based on user selection.
"""

filtered_headers = []
for selectedHeader in allHeaders:
if selectedHeader["value"] in selected_headers:
filtered_headers.append(selectedHeader)
return filtered_headers

@staticmethod
def filter_data(allData, selected_headers):
"""
Retrieves data for user-selected headers.
:param allData: The list of all data.
:param selected_headers: The list of headers selected by the user.
:return: A list of filtered data based on user selection.
"""

filtered_data = []
for row in allData:
filtered_row = {}
for key, value in row.items():
if key in selected_headers:
filtered_row[key] = value
filtered_data.append(filtered_row)
return filtered_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
This file is part of ImpactX

Copyright 2024 ImpactX contributors
Authors: Parthib Roy, Axel Huebl
License: BSD-3-Clause-LBNL
"""

import plotly.graph_objects as go


def line_plot_1d(selected_headers, filtered_data):
"""
Generates a 1D line plot using Plotly based on selected headers and filtered data.
"""

x_axis = selected_headers[0] if len(selected_headers) > 1 else None
y_axis = selected_headers[1:] if len(selected_headers) > 2 else None

x = [row[x_axis] for row in filtered_data] if x_axis else []

figure_data = []
if y_axis:
for column in y_axis:
y = [row[column] for row in filtered_data]
trace = go.Scatter(
x=x,
y=y,
mode="lines+markers",
name=column,
line=dict(width=2),
marker=dict(size=8),
)
figure_data.append(trace)

return go.Figure(
data=figure_data,
layout=go.Layout(
title="Plot Over S",
xaxis=dict(title="s"),
yaxis=dict(title=""),
margin=dict(l=20, r=20, t=25, b=30),
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
This file is part of ImpactX

Copyright 2024 ImpactX contributors
Authors: Parthib Roy, Axel Huebl
License: BSD-3-Clause-LBNL
"""

from ...trame_setup import setup_server

server, state, ctrl = setup_server()

import base64
import io

from impactx import Config, ImpactX

from ...Input.distributionParameters.distributionMain import distribution_parameters
from ...Input.latticeConfiguration.latticeMain import lattice_elements
from ..plot_PhaseSpaceProjections.phaseSpaceSettings import adjusted_settings_plot

# Call MPI_Init and MPI_Finalize only once:
if Config.have_mpi:
from mpi4py import MPI # noqa


def fig_to_base64(fig):
"""
Puts png in trame-compatible form
"""
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
return base64.b64encode(buf.read()).decode("utf-8")


def run_simulation():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up PR, let's move this out to separate run logic controls.

"""
This tests using ImpactX and Pandas Dataframes
"""
sim = ImpactX()

sim.particle_shape = state.particle_shape
sim.space_charge = False
sim.slice_step_diagnostics = True
sim.init_grids()

# init particle beam
kin_energy_MeV = state.kin_energy_MeV
bunch_charge_C = state.bunch_charge_C
npart = state.npart

# reference particle
pc = sim.particle_container()
ref = pc.ref_particle()
ref.set_charge_qe(-1.0).set_mass_MeV(0.510998950).set_kin_energy_MeV(kin_energy_MeV)

distribution = distribution_parameters()
sim.add_particles(bunch_charge_C, distribution, npart)

lattice_configuration = lattice_elements()

sim.lattice.extend(lattice_configuration)

# simulate
sim.evolve()

fig = adjusted_settings_plot(pc)
fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.image_data = f"data:image/png;base64, {image_base64}"

sim.finalize()

return fig
Loading
Loading