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

Relocated simulation file in dashboard #725

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from trame.widgets import matplotlib, plotly, vuetify
from wurlitzer import pipes

from ..simulation import run_simulation
Copy link
Member

@ax3l ax3l Oct 3, 2024

Choose a reason for hiding this comment

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

It is still a bit unstructured that run_simulation is called from an analysis sub-folder.

from ..trame_setup import setup_server
from .analyzeFunctions import AnalyzeFunctions
from .plot_ParameterEvolutionOverS.overS import line_plot_1d
from .plot_PhaseSpaceProjections.phaseSpace import run_simulation

server, state, ctrl = setup_server()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
"""
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():
"""
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(state.charge_qe).set_mass_MeV(state.mass_MeV).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
"""
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 .Analyze.plot_PhaseSpaceProjections.phaseSpaceSettings import (
adjusted_settings_plot,
)
from .Input.distributionParameters.distributionMain import distribution_parameters
from .Input.latticeConfiguration.latticeMain import lattice_elements

# 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():
"""
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(state.charge_qe).set_mass_MeV(state.mass_MeV).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