You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the official factory.py, there is an example which is
@factory
class F:
a: int = Field()
def build(self):
return self.a + 4
@component
class C:
a: int = Field(3)
f: int = ComponentField(F)
print(C().f)
I test the same code using the latest zookeeper vision
from zookeeper import factory, Field, ComponentField, component
@factory
class F:
a: int = Field()
def build(self) -> int:
return self.a + 4
@component
class C:
a: int = Field(3)
f: int = ComponentField(F)
print(C().f)
But it raised an error:
Traceback (most recent call last):
File "test.py", line 14, in <module>
print(C().f)
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/component.py", line 221, in wrapped_fn
return result.build()
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/factory.py", line 20, in wrapped_fn
result = fn(factory_instance)
File "test.py", line 7, in build
return self.a + 4
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/component.py", line 217, in wrapped_fn
result = base_wrapped_fn(instance, name)
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/component.py", line 194, in base_wrapped_fn
raise e from None
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/component.py", line 181, in base_wrapped_fn
result = field.get_default(instance)
File "/usr/local/lib/python3.6/dist-packages/zookeeper/core/field.py", line 146, in get_default
f"Field '{self.name}' has no default or configured value."
AttributeError: Field 'a' has no default or configured value.
It seems that the factory didn't use it's parent component to configure its Field. I don't know what to do.
Hi, apologies for that! It seems the docstring is slightly out of date. The example does work correctly, it's just that you have to configure the component instance first:
This is basically because configuration is required to properly set up all of the fields and the connections between them. I hope that helps! Thanks for filing the issue, I will update the docs.
Describe the bug
In the official factory.py, there is an example which is
I test the same code using the latest zookeeper vision
But it raised an error:
It seems that the factory didn't use it's parent component to configure its Field. I don't know what to do.
To Reproduce
Expected behavior
Environment
TensorFlow version: 2.3.1
Zookeeper version: 1.0.4
The text was updated successfully, but these errors were encountered: