Requirement to initialize a variable when using the '-skiprun'

Dear LAMMPS Community,

I have encountered that LAMMPS requires initialization of the variable even if the -skiprun option is used. Let me first give you an MWE: (I didn’t care about the physical component, just to reproduce the error)

# Initialization

lattice fcc 0.001
region allbox block 0 100 0 100 0 100 side in units box
create_box 1 allbox
create_atoms 1 box

mass 1 1

pair_style lj/cut 2.5
pair_coeff 1 1 1 1

# Main part

compute neighs all coord/atom cutoff 1.5

variable is_monomer atom c_neighs==0
write_restart restart.a
group monomers variable is_monomer

If I run it the normal way lmp -in in.file, everything works. But if I add the -skiprun option: lmp -skiprun -in in.file, I get the error:

ERROR: Variable is_monomer: Variable formula compute cannot be invoked before initialization by a run (src/variable.cpp:1674)
Last command: group monomers variable is_monomer

In principle, it is clear that it is incorrect to use a variable defined as a result of a calculation that did not occur because the -skiprun option was used. But this is exactly what the -skiprun option is used for. Uncertainty.
What is interesting about it is that if we add the write_restart command before the needed variable is used, for example:

variable is_monomer atom c_neighs==0
write_restart restart.a
group monomers variable is_monomer

and run it with the -skiprun option, there will be no error.
Is adding the write_restart command the correct solution to the error?

LAMMPS: 2 Aug 2023 development, platform: SLES 12.3 and Linux Mint 21.2

There is no “correct” solution. The “-skiprun” flag does what it says, it skips the run commands. Thus it cannot be used for any kinds of (complex) input decks that require computations that are only produced during a run.

The “write_restart” hack works in this case, since writing a restart (or a data file) enforces an initialization similar to what is done with a run 0 command.

Bottom line: you are trying to use -skiprun for something it has not been designed to be used for. The closest to -skiprun is probably to change your run commands as follows:

run $(v_runflag*100000)

and then use -v runflag 1 or -v runflag 0 at the command line.

1 Like

From the docs:

This can be helpful and convenient to test input scripts of long running calculations for correctness to avoid having them crash after a long time due to a typo or syntax error in the middle or at the end.

I’m just trying to check typo.
Probably using run 0 really is the best option for this purpose.

can means that it is possible, but not guaranteed.