From c122678aa982e4dde4dde459a07390220871ff6d Mon Sep 17 00:00:00 2001 From: sb Date: Tue, 9 Feb 2021 19:43:01 -0500 Subject: [PATCH] removing model call(); adding Model init to AgentType and Market, fixes #679 --- .../tests/test_PerfForesightConsumerType.py | 2 +- HARK/core.py | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py b/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py index a7105b1f6..9f5a7b8fe 100644 --- a/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py +++ b/HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py @@ -60,7 +60,7 @@ def test_simulation(self): "T_age": None, # Age after which simulated agents are automatically killed } - self.agent_infinite( + self.agent_infinite.assignParameters( **SimulationParams ) # This implicitly uses the assignParameters method of AgentType diff --git a/HARK/core.py b/HARK/core.py index 3fe5a04f3..ad3bb1897 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -169,16 +169,25 @@ def assignParameters(self, **kwds): ------- none """ - self.parameters = kwds + self.parameters.update(kwds) for key in kwds: setattr(self, key, kwds[key]) - def __call__(self, **kwds): + def get_parameter(self, name): """ - Assign an arbitrary number of attributes to this agent, as a convenience. - See assignParameters. + Returns a parameter of this model + + Parameters + ---------- + name : string + The name of the parameter to get + + Returns + ------- + value : + The value of the parameter """ - self.assignParameters(**kwds) + return self.parameters[name] def __eq__(self, other): if isinstance(other, type(self)): @@ -186,6 +195,10 @@ def __eq__(self, other): return notImplemented + def __init__(self): + if not hasattr(self, 'parameters'): + self.parameters = {} + def __str__(self): type_ = type(self) @@ -261,6 +274,8 @@ def __init__( seed=0, **kwds ): + super().__init__() + if solution_terminal is None: solution_terminal = NullFunc() @@ -1116,6 +1131,7 @@ def __init__( tolerance=0.000001, **kwds ): + super().__init__() self.agents = agents if agents is not None else list() # NOQA reap_vars = reap_vars if reap_vars is not None else list() # NOQA