-
Notifications
You must be signed in to change notification settings - Fork 195
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
Redesigning Simulation
and run!
#1138
Comments
We also may want to make the list of simulation.callbacks[:NaNChecker].schedule = IterationInterval(1) If can overload simulation.callbacks.NaNChecker.schedule = IterationInterval(1) |
I'll add a sixth feature (from #1251):
|
I'll also add a seventh feature (from #1250):
@glwagner also suggested that all the callbacks should be initialized at the beginning of run. |
To clarify, there's two possibilities:
or both. Which do we want? There won't be a |
I was envisioning option 2 (or both if we feel that An important practical reason to have option 2 is that some callbacks will only be called very infrequently so it's better to quickly find out that there's a typo or mistake in your callbacks before the simulation runs for 1,000,000 iterations if the callback's schedule is |
That makes sense. We can also let users assume that "iteration = 0" means "initialization". This doesn't cover cases where simulations are run from iterations other than 0 though. |
A vaguely related feature that could be addressed in this PR are " |
This sounds like good progress here and thank you for doing it. On a perhaps tangential note, I noticed when I tried the wizard and |
@francispoulin I think you can give a minimum Δt to |
@francispoulin Ah the warning about Δt = 0 is probably specific to the I think we agreed in #1255 to avoid calling Taking this thought further: I guess the responsibility for not taking zero time steps lies with the |
Thanks @ali-ramadhan . There is a I agree that |
I'd like to resurrect this issue. We've implemented 5, but we don't have callbacks. I think we should just add a callback layer to The key change is that struct Callback{F, S}
func :: F
schedule :: S
end Usage would be something like progress(sim) = println("Iteration $(sim.model.clock.iteration)")
progress_printer = Callback(progress, schedule = IterationInterval(100))
wizard = TimeStepWizard(cfl=0.1, initial_dt = 2minutes, schedule = IterationInterval(10))
simulation = Simulation(model, stop_time=2hours, callbacks = [progress_printer, wizard]) In other words, the |
This was resolved by #1971 |
@ali-ramadhan and I have discussed a potential redesign of
Simulation
andrun!
that has several key features:Coalesce all of the "callbacks" (arbitrary functions that are executed during a time-stepping loop) other than
OutputWriter
s into a single list. Current objects that we can classify / redesign as callbacks are: stop criteria,TimeStepWizard
, and diagnostics. All callbacks are required to possesscallback.schedule
, and we can provide convenience objects for coupling simple callback functions toAbstractSchedule
.Within the time-stepping loop, execute
simulation.callbacks
prior to writing output. This ensures that data calculated in a callback can be output during the same time-step, such asWindowedTimeAverage
and other non-local-in-time output.Wrap the time-stepping loop inside a
try / catch
block and throw exceptions to stop a simulation. This generalizes the concept of stopping a simulation and also means that a simulation can be stopped inside any callback. Further, when anAbstractStopException
is called we will loop over theOutputWriter
callbacks a final time, passing the exception into theOutputWriter
callback functions. This allows output behavior specialized on the type of exception. For example:NaNsDetected
is thrown, no output will be written.WallTimeExceeded
is thrown, the checkpointer may write output.simulation.Δt
becomes a number corresponding to the next time-step, always (rather than sometimes being aTimeStepWizard
). TheTimeStepWizard
callback changes this number on itsschedule
. Otherwise, the time-step is held constant. This changes the API, since the initial time-step must now be provided toSimulation
.(Somewhat unrelated, but enabled by the new pattern) Use a new function
align!(simulation.Δt, writer.schedule, simulation.model)
to adjust a subsequent time-step if output writing is scheduled. This ensures output writing onTimeInterval
s will always be onschedule
rather than chronically late as it is now. Since output is called after all the other callbacks, the output writers get the final say as to the next time-step.These changes will break the existing API. Notably, we'll use
rather than setting
simulation.Δt
to be aTimeStepWizard
. This is probably an improvement. We can still provide the keywordsstop_time
andstop_iteration
in theSimulation
constructor as a convenience; however rather than being properties ofSimulation
we will create callback objects that get scheduled every iteration and add them tosimulation.callbacks
.I think we should also provide a few other features, like to ability to pass
Δt
torun!
, perhaps along with a few otherrun!
-specific objects.The text was updated successfully, but these errors were encountered: