Lammps input impossible to subclass nicely
Opened this issue · 1 comments
#1271 has made it extremely inconvenient to sub class the Input
class of lammps jobs. In the to_dict way of serializing objects, classes are forced to specify exactly which nodes they want to read from HDF, which forces objects to know about the nodes that their sub objects write, leading to very tight coupling.
e.g. the Input class needs to know that the control and potential objects write themselves to control_inp
and potential_inp
and even that the potential object requires a further potential_inp/potential
. When I subclass Input
now, I cannot influence these values because they are hard coded, which makes it impossible to properly implement from_dict
. The only way to make saving a subclass work now is to overload to_dict
add the additional data we want to write and then overload from_hdf
to open the HDF file a second to read them.
I haven't looked around, but I suspect this is true for all objects that use the to/from_dict interface. This will probably be need to be fixed in base, so this is a reminder for myself.
I have a work around for now, but it is extremely annoying to rely on a half baked solution now for something that previously just worked.
The read_dict_from_hdf()
function has an recursive
parameter which loads the whole dictionary. This is already used on the from_hdf()
function at the job level. So in practice the corresponding dictionaries should already be available. We should just remove all the to_hdf()
and from_hdf()
calls in all those sub classes and update the tests to use to_dict()
and from_dict()