Conversation
(cherry picked from commit 376ee1c)
kris-brown
left a comment
There was a problem hiding this comment.
Thanks, this is definitely an improvement!
I think I originally chose this weird secret behavior of maxevent getting ignored when a maxtime is specified because the default maxevent is quite arbitrary (100). And I picked a finite, arbitrary value because I wanted it to be possible to call run! without any user supplied keyword arguments.
But now I see that the cleanest thing is to have maxevent default to typemax(Inf) just like maxtime defaults to Inf!
| @@ -486,7 +486,6 @@ end | |||
|
|
|||
| function run!(abm::ABM, rt::RuntimeABM, output::Traj; | |||
| save=_->nothing, maxevent=MAXEVENT, maxtime=Inf, dt=0.1) | |||
There was a problem hiding this comment.
I suppose the default for maxevent should be typemax(Int) and the default for maxtime can be Inf. There should be an error in the first line if neither has been specified by the caller.
There was a problem hiding this comment.
Note that, once this is done, any tests which do not supply maxevent or maxtime will be broken, and they would have to be changed (e.g. to add the kwarg maxevent=100) in order to work again.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Updated this PR to match the review direction: |
Problem
run!accepted bothmaxeventandmaxtime, but previously a finitemaxtimesilently disabled the caller-suppliedmaxeventby replacing it withtypemax(Int).That meant callers asking for "stop after at most N events, but no later than time T" were only getting the time bound. It also left the API with an arbitrary hidden default event cap (
100) when no stopping criterion was supplied.Fix
This PR now does two things:
maxeventdefaults totypemax(Int)rather than an arbitrary finite cap.run!now errors if the caller leaves both bounds unbounded, i.e.maxevent == typemax(Int)andmaxtime == Inf.With that change, finite
maxeventand finitemaxtimecompose cleanly, and calls that would otherwise run without any stopping criterion now fail with a clear message asking the caller to specify at least one bound.Testing
maxevent=2andmaxtime=10.0stop after exactly two eventsrun!(...)without any finite bound throws a helpful error