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

Graceful exit on aborting a simulation with Ctrl-C #1876

Open
sloede opened this issue Mar 17, 2024 · 5 comments
Open

Graceful exit on aborting a simulation with Ctrl-C #1876

sloede opened this issue Mar 17, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@sloede
Copy link
Member

sloede commented Mar 17, 2024

Raise your hands if you haven't encountered this situation at least once before:

You tinker with a new feature implementation and/or simulation setup.
Finally, you get it to run.
For good measure, you wait a while to make sure it does not crash.
Satisfied, you hit Ctrl-C to abort
Now, you'd really like to look at the results using Plots.jl/Makie.jl.

But, alas, there is no way to visualize the result easily from within Julia because you do not have a sol object yet!

What I thus propose is to investigate possible ways to allow a "graceful abort" (an oxymoron if there ever was one) when running simulations from the REPL, discuss them, and then implement them for Trixi.jl. Ideally, I'd be looking at something like the following setup:

  • Hit Ctrl-C once and only once: Get a graceful exist after the next time step has finished. A soothing message to the user informs them of what an excellent choice they made in not hitting Ctrl-C multiple times out of frustration, and if they wait juuuust a little longer, they get a proper sol object.
  • Hit Ctrl-C repeatedly: Get out of dodge, and fast (i.e., as it does right now).
  • Obviously, there is no measurable performance impact for but the tiniest of simulation setups
  • It just "works" without user interaction
@sloede sloede added the enhancement New feature or request label Mar 17, 2024
@JoshuaLampert
Copy link
Member

I really like that idea!

@ranocha
Copy link
Member

ranocha commented Mar 17, 2024

I think this may require at least a yield() statement after a time step. On Julia v1.10, I get

julia> using BenchmarkTools

julia> @benchmark yield()
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  11.708 μs  53.166 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     12.500 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   12.770 μs ±  1.046 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

    ▁▁▁▁▁▃▄█▄▂▁▁▁▁▁                                           ▁
  ▆██████████████████▇▇█▇▇▇██▇█▆▇██▇▇▇█▇█▇▇▇▇▆▇▆▆▆▅▅▄▅▅▅▆▅▃▄▄ █
  11.7 μs      Histogram: log(frequency) by time      16.5 μs <

 Memory estimate: 0 bytes, allocs estimate: 0.

@andrewwinters5000
Copy link
Member

This is a nice idea! One follow-up question. Could this "graceful abort" also spit back the sol object if something like a negative density and/or pressure is encountered? This could help with debugging new shock capturing features. However, if it is too complicated or out of focus we can ignore this comment.

@ranocha
Copy link
Member

ranocha commented Mar 18, 2024

This is a nice idea! One follow-up question. Could this "graceful abort" also spit back the sol object if something like a negative density and/or pressure is encountered? This could help with debugging new shock capturing features. However, if it is too complicated or out of focus we can ignore this comment.

This should work already with the recent version of Trixi.jl (thanks to the work of @DanielDoehring on NaN-based sqrt etc.):

julia> trixi_include("examples/tree_2d_dgsem/elixir_euler_kelvin_helmholtz_instability.jl",
                     tspan = (0.0, 5.0), alpha_max = 0.0)
...
#timesteps:    840 │ Δt: 7.2692e-04 │ sim. time: 3.6513e+00 (73.026%)  │ run time: 5.8007e+00 s
#timesteps:    850 │ Δt: 3.0837e-04 │ sim. time: 3.6562e+00 (73.123%)  │ run time: 5.8773e+00 s
#timesteps:    860 │ Δt: 2.3219e-05 │ sim. time: 3.6575e+00 (73.151%)  │ run time: 5.9528e+00 s
┌ Warning: Instability detected. Aborting
└ @ SciMLBase ~/.julia/packages/SciMLBase/8XHkk/src/integrator_interface.jl:606

julia> sol.t
2-element Vector{Float64}:
 0.0
 3.657545463670625

@andrewwinters5000
Copy link
Member

Aha, then disregard most of my comment above. We only need to focus on the Ctrl + c exiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants