Fix halt continue + run every

I am unsure if this is a bug but when I use run every in conjunction with fix halt continue, the run command is continued instead of aborted.

variable t0 equal $t
variable delay equal v_t-v_t0
fix myhalt all halt 100 v_delay > 0.1 error continue 
run 100000 post no every 100 "if '$(v_disp) >= 2.0' then 'uncompute 1' 'compute 1 all displace/atom' 'variable t0 equal $t'"
(other commands including "run")

Expected behavior: when halt is triggered, the current run is stopped and subsequent commands are executed.
Observed behavior: halt is triggered but the current run command continues as if nothing had happened.

The alternative would be to have

fix myhalt all halt 100 v_delay > 0.1 error soft

but then any additional run commands are skipped (even when using unfix myhalt. I don’t know if this is normal as well)

This is documented behavior. “error continue” continues the calculation, just prints that the condition has been met.

They don’t have to be. Just issue the command timer timeout unlimited and the situation should be like it was before fix halt triggered. I noticed that this is not mentioned in the fix halt documentation and needs to be added.

P.S.: you have to be very careful what kind of commands you put into the “every” section of a run command. Because “run every” is effectively a shortcut for programming a loop in the LAMMPS input with using run pre no post no and thus all the limitations of run pre no apply. If you are making changes to the simulation that require the full setup/init (i.e. run pre yes), it will produce incorrect results with run every just as well.

Thank you for the answer.
The documentation says

If its value is continue, the behavior is the same as for soft, except subsequent run or minimize commands are executed. This allows your script to remedy the condition that triggered the halt, if necessary. Note that you may wish use the unfix command on the fix halt ID, so that the same condition is not immediately triggered in a subsequent run.

My understanding of this is that the current run command is and the lines that come after it are read normally (including any run command).

I don’t understand how this command would help but I will try that. Thank you for the suggestion!
EDIT: It worked perfectly. Thank you!

Alright. I am not sure which of the commands in the every statement raised the concern but I will be carefully testing it. I noticed that the documentation doesn’t warn about the every command pitfalls. Thanks for the comment!

You are correct. I misremembered the details of fix halt. However, the problem in your case is triggered by the “every” keyword. That will break down the single “run” command into many individual run internally and then with fix halt error continue the timer timeout will be reset and then each section will start with an newly initialized fix halt. So only fix halt with “error soft” will stop the subsequent run sections.

Again, this is my mistake. I was incorrectly assuming that “pre no post no” is automatically triggered when using “every”, but it is not. However, that means that your run is wasting quite a bit of time with re-initializing and finalizing each run section. Also, there is a lot more output. So run every makes most sense with “pre no post no” and only then you have to be careful with which commands to issue.

1 Like

Indeed. With pre no the compute seems to work as expected but the fix halt is never triggered, even when the condition is met. But I couldn’t figure out any other solution halt my simulation when the maximum displacement is above a threshold, so I guess I will increase the every intervals and continue with pre yes. Thank you!