larq/zookeeper

Unexpected behaviour when configuring nested components.

AdamHillier opened this issue · 0 comments

Describe the bug

The parameter value injection means that in the component hierarchy the same component instance can be in multiple places (only one instance exists, but there are pointers to it from multiple sub-components at different levels of nesting). This means there can be unintended side-effects when passing configuration values applied to the same object but scoped to different levels. It's best to understand this with an example:

Minimal reproducable example:

from zookeeper import Component

class A(Component):
    x: int = 5

class B(Component):
    a: A

class Parent(Component):
    a: A
    b: B

p = Parent()

p.configure({
    "a.x": 3,
    "a.b.x": 4,
})

print(p)

Expected (or perhaps intended) behaviour:

Parent(
    a = A(
        x = 3
    ),
    b = B(
        a = A(
            x = 4
        )
    )
)

Actual behaviour:

Parent(
    a = A(
        x = 4
    ),
    b = B(
        a = A(
            x = 4
        )
    )
)

Environment

Zookeeper version: 1.0.dev2