Parameters

Sometimes, we need to store values that are shared across components, that don’t need to be expressed as states. For example, you may want to fix a number of items, or the value of a quantity throughout. You could pass all these parameters to each component’s constructor, but that would be a bit verbose. To make things easier, you can use CoopIHC parameters. The example below shows how these work:

 1class ExampleTaskwithParams(ExampleTask):
 2    def __init__(self, *args, **kwargs):
 3        super().__init__(*args, **kwargs)
 4        self.parameters = {"param1": 1, "param2": 2}
 5
 6    def finit(self):
 7        self.update_parameters({"finit": 1})
 8
 9
10bundle = Bundle(
11    task=ExampleTaskwithParams(),
12    user=BaseAgent("user"),
13    assistant=BaseAgent("assistant"),
14)
15
16task_dic = {"param1": 1, "param2": 2, "finit": 1}
17# Parameters defined in the task available everywhere
18assert bundle.parameters == task_dic
19assert bundle.task.parameters == task_dic
20assert bundle.user.parameters == task_dic
21assert bundle.assistant.parameters == task_dic
22assert bundle.user.observation_engine.parameters == task_dic
23assert bundle.user.inference_engine.parameters == task_dic
24assert bundle.user.policy.parameters == task_dic
25# Parameters accessible as attributes everywhere
26assert bundle.user.param1 == 1
27assert bundle.user.policy.param1 == 1