pykan
pykan copied to clipboard
Error when calling plot or fix symbolic because acts is not an attribute
Similar to here
I get an attribute error when calling some methods (namely plot
) after I've trained a model if I haven't first run a forward inference pass on the model, this is because acts
is set in the forward
method.
I propose adding these two functions to KAN
:
@property
def acts(self) -> list:
"""
Acts attribute getter, raises an error if it does not exist.
Returns:
--------
acts : list
activations of each layer
"""
if not hasattr(self, "_acts"):
raise RuntimeError(
"No acts attribute. Please run a forward pass of the model first."
)
return self._acts
@acts.setter
def acts(self, value: list):
"""
Set the acts list attribute.
Args:
-----
value:
Returns:
--------
None
"""
setattr(self, "_acts", value)
So that if it happens, it's clear that the model needs to be called first. Otherwise it's a bit opaque what the issue is.
There might be a larger issue though, I think that the model should be plotable after training, but this would be a quick intermediate fix.
Thanks