stfc / janus

collection of scripts to train and generate data for machine learnt interatomic potentials
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Errors from incomplete input.nn #26

Closed ElliottKasoar closed 1 year ago

ElliottKasoar commented 1 year ago

If controller.write_n2p2_nn is interrupted when writing input.nn e.g. due to invalid input parameters, this can lead to errors if attempting to rerun the script:

   1347         with open(join_paths(n2p2_directory, file_nn), "r") as readfile:
   1348             with open(join_paths(n2p2_directory, f"{file_nn}.temp"), "w") as writefile:
-> 1349                 generator.delete_duplicate_functions(
   1350                     readfile = readfile,
...
--> 855         if line_num < line_start or line_num > line_end:
    856             writefile.write(line_text)
    857     os.remove(readfile.name)

UnboundLocalError: local variable 'line_end' referenced before assignment

As was the case before generator.delete_duplicate_functions was implemented, cleaning up input.nn before rerunning the function is a solution, although input.nn.temp may also require deleting now.

However, there may be a way to handle this more gracefully e.g. checking if an existing input.nn was written correctly before continuing, and checking if input.nn.temp exists already.

ElliottKasoar commented 1 year ago

I'm not sure my initial description was correct - if write_n2p2_nn fails it typically doesn't write anything. The error appears to occur if attempting to modify (or not) the last symmetry function in the file, as there is no trailing ###... to reference.