Unexpected behavior from "lpad add"

Hi all,

I’m seeing some behavior from FireWorks that I don’t understand, and I’m hoping that someone can help me out. This is an issue that I’ve never encountered when using atomate, but now I’m seeing it regularly with a different, stand-alone installation of FireWorks. The basic problem is that using lpad add in the command line will not only add the specified workflow, but also seems to run any python scripts in directories where I’ve run workflows before.

I have a developer installation (version 2.0.3) and I can reproduce the issue reliably with the included tutorials. If I run the “firetask” tutorial with the python interface, everything works normally:

from fireworks import Firework, FWorker, LaunchPad
from fireworks.core.rocket_launcher import launch_rocket
from fw_tutorials.firetask.addition_task import AdditionTask

launchpad = LaunchPad(host = myHost, ..., etc.)
firework = Firework(AdditionTask(), spec={"input_array": [1, 2]})
launch_rocket(launchpad, FWorker())

Now suppose that I replace the entire contents of that file (call it addition.py) with

print("The quick brown fox jumped over the lazy dog")

Just for good measure, I also rename the file to some_other_name.py and run lpad_reset. Then I pop over into the “introduction” directory and attempt to run that tutorial through the command line:

[email protected]:~/software/fireworks/fw_tutorials/introduction> lpad add fw_test.yaml 
The quick brown fox jumped over the lazy dog
2022-07-15 13:03:52,542 INFO Added a workflow. id_map: {-1: 1}

The script ../firetask/some_other_name.py is being executed by lpad add, and I can’t figure out how to prevent this from happening. Maybe it’s a bug… or maybe this is normal behavior and I’m just missing something obvious? Thank you in advance!

One debugging idea is to make addition.py print a stack trace to see what’s causing it to run.

import traceback

Hypothesis: lpad add imports everything in your firetask directory so it can build firetask instances to run those Firetasks. Or maybe it’s importing one thing that imports all your firetasks, directly or via an __init__.py file.

Generally, a Python script should just define values and functions, then have its top level script code within a if __name__ == '__main__': block. That way, merely importing the script will not run its functionality.

Also, it’s probably best to put scripts in a script directory rather than in your firetask directory (module).