Skip to content

Commit

Permalink
Print simulation content after simulation runs (#718)
Browse files Browse the repository at this point in the history
Improvement from current, however it would be ideal that the contents stream out on the terminal view as the simulation runs, not just at once when the simulation is completed.

Using wurlitzer library for this
  • Loading branch information
proy30 authored Oct 2, 2024
1 parent 3f26348 commit 4a7da60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"""

import asyncio
import contextlib
import glob
import io
import os

from trame.widgets import matplotlib, plotly, vuetify
from wurlitzer import pipes

from ..trame_setup import setup_server
from .analyzeFunctions import AnalyzeFunctions
Expand Down Expand Up @@ -140,11 +140,11 @@ def update_plot():
def run_simulation_impactX():
buf = io.StringIO()

with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
with pipes(stdout=buf, stderr=buf):
state.simulation_data = run_simulation()

buf.seek(0)
lines = [line.strip() for line in buf]
lines = [line.strip() for line in buf.getvalue().splitlines()]

# Use $nextTick to ensure the terminal is fully rendered before printing
async def print_lines():
Expand Down
1 change: 1 addition & 0 deletions src/python/impactx/dashboard/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ trame-plotly>=3.0.2
trame-router>=2.2.0
trame-vuetify>=2.6.2
trame-xterm>=0.2.1
wurlitzer>=3.1.1

0 comments on commit 4a7da60

Please sign in to comment.