Degiacomi-Lab / molearn

protein conformational spaces meet machine learning
https://degiacomi.org/software/molearn/
GNU General Public License v3.0
40 stars 11 forks source link

Disappearing kwargs #5

Closed ryankzhu closed 1 year ago

ryankzhu commented 1 year ago

Hi! I get error when I do:

trainer.set_autoencoder(Small_AutoEncoder, out_points=data.dataset.shape[-1])

It seems that the kwargs given to set_autoencoder is not passed to initialise the foldingnet decoder:

Traceback (most recent call last):
  File "train.py", line 24, in <module>
    trainer.set_autoencoder(Small_AutoEncoder, out_points=data.dataset.shape[-1])
  File "/home/rzhu/Desktop/projects/molearn/src/molearn/trainers/trainer.py", line 76, in set_autoencoder
    self.autoencoder = autoencoder(**kwargs).to(self.device)
  File "/home/rzhu/Desktop/projects/molearn/src/molearn/models/small_foldingnet.py", line 45, in __init__
    super().__init__()
  File "/home/rzhu/Desktop/projects/molearn/src/molearn/models/foldingnet.py", line 244, in __init__
    self.decoder = Decoder(*args, **kwargs)
TypeError: __init__() missing 1 required positional argument: 'out_points'
degiacom commented 1 year ago

This seems to be caused by the fact that Small_AutoEncoder inherits from AutoEncoder, and that super().__init__() is called in its __init__ method. I can see two solutions:

Perhaps the former approach is better. @SCMusson?

SCMusson commented 1 year ago

Passing *args or **kwargs to __init__ method would work but create the encoders and decoders twice. Using Multiple inheritance would do the same and avoid unnecessary work. super(AutoEncoder, self).__init__() should work I believe. Alternatively super(type(self).__bases__[0], self).__init__(). I pushed cf15651 which uses the former.