MDANSE icon indicating copy to clipboard operation
MDANSE copied to clipboard

[BUG] Running IJobs jobs causes their states to change and running a job with different parameters may cause odd results.

Open ChiCheng45 opened this issue 10 months ago • 1 comments

Description of the error During the creation of tutorial 4, I made the following script.

from MDANSE.Framework.Jobs.IJob import IJob

parameters_atm1_atm2 = {
    ...
    'output_files': ('../mdanse_outputs/dcsf_atm1_atm2.mda', ['MDAFormat'], 'INFO'),  # output_files
    'trajectory': '../mdanse_outputs/converted_atm1_atm2.mdt',  # trajectory
}
parameters_atm1atm2 = {
    ...
    'output_files': ('../mdanse_outputs/dcsf_atm1atm2.mda', ['MDAFormat'], 'INFO'),  # output_files
    'trajectory': '../mdanse_outputs/converted_atm1atm2.mdt',  # trajectory
}

if __name__ == "__main__":
    dynamiccoherentstructurefactor = IJob.create('DynamicCoherentStructureFactor')
    dynamiccoherentstructurefactor.run(parameters_atm1_atm2, status=True)
    dynamiccoherentstructurefactor.run(parameters_atm1atm2, status=True)

Now trajectory converted_atm1_atm2.mdt contains atom types atm1 and atm2 and converted_atm1atm2.mdt contains atom type atm1atm2. dcsf_atm1_atm2.mda contains the results f(q,t)_atm1atm1, f(q,t)_atm1atm2, and f(q,t)_atm2atm2. dcsf_atm1atm2.mda contains the results f(q,t)_atm1atm1, f(q,t)_atm1atm2, f(q,t)_atm2atm2 and f(q,t)_atm1atm2atm1atm2.

Describe the expected result I would've expected the script to work. The state of DynamicCoherentStructureFactor changes after a job is run. It should reset before running a new job or after it has finished running a job. dcsf_atm1atm2.mda should only contain f(q,t)_atm1atm2atm1atm2.

To fix this issue, I needed to recreate the DynamicCoherentStructureFactor object.

if __name__ == "__main__":
    dynamiccoherentstructurefactor = IJob.create('DynamicCoherentStructureFactor')
    dynamiccoherentstructurefactor.run(parameters_atm1_atm2, status=True)
    dynamiccoherentstructurefactor = IJob.create('DynamicCoherentStructureFactor')
    dynamiccoherentstructurefactor.run(parameters_atm1atm2, status=True)

ChiCheng45 avatar Apr 23 '25 15:04 ChiCheng45

I don't think we ever considered the case of IJob objects being reusable. I guess that we would need to have some clear/reset function which is run before parsing the parameters, or there would be leftovers in the dictionaries stored by the job instance.

MBartkowiakSTFC avatar Apr 23 '25 16:04 MBartkowiakSTFC