-
Notifications
You must be signed in to change notification settings - Fork 143
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
warning if dt is modified during kernel returning SUCCESS #657
Conversation
So we decided that the code should crash if dt is modified without REPEAT error. Now, we have a problem with RK45. RK45 does either divide dt by 2 if accuracy is bad, or multiply it by 2 if accuracy really good. We were not repeating the kernel in the last case (which was wrong). But if RK45 requests to multiply dt by 2, but dt can't be increased since t+dt > tend, them we are stuck in an infinite loop. |
Solution might be the following: We wanted to do "if dt is modified, code crashes" by modified*, I mean modified between "before kernel call" and "after kernel call + adjustment due to tend" I think this would make sense |
Yes, I agree. |
Limitation is that if kernel does I'll implement this then. |
except if end of simu. -> This is wrong, since this "except" is bad for the integration of the kernels!
special care of dt modified for next kernel
parcels/kernel.py
Outdated
@@ -275,8 +275,11 @@ def execute_python(self, pset, endtime, dt): | |||
for var in ptype.variables: | |||
p_var_back[var.name] = getattr(p, var.name) | |||
try: | |||
p.dt = sign_dt * dt_pos | |||
pdt = sign_dt * dt_pos | |||
p.dt = pdt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines are somewhat unclear. Would it help to rename pdt
to something clearer, e.g.
p.dt = sign_dt * dt_pos
pdt_prekernels = p.dt
and then check ... not np.isclose(p.dt, pdt_prekernels)
below?
This PR captures if a kernel has modified
particle.dt
.This leads to problems in many situations:
particle.time
will be updated using thedt
before the kernel call, ignoring thedt
, which will be used at next kernel call (so one time step later)particle.dt
will then be executed with the wrong dt-> There is no problem if after modifying dt, the kernel returns
REPEAT
, in which case, all variables are reset to their value before the kernel call (except dt) and the kernel is rerunProblems:
Solution? Why do we want to raise a warning? Why don't deleting the particle (or even killing the run?). Modifying dt during kernel execution is dangerous. Some users could use such operation correctly. But they could also do the same job without modifying the dt like this. It's better to completely disable such operation