What is update? How many terminal solutions?
Closed this issue · 8 comments
Looking at the PortfolioConsumerType
I find the following update
method:
which calls RiskyConsumerType's update
HARK/HARK/ConsumptionSaving/ConsPortfolioModel.py
Lines 180 to 181 in 3ee3979
which calls ConsIndShk's update
HARK/HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Lines 87 to 88 in 3ee3979
which finally updates the terminal solution.
HARK/HARK/ConsumptionSaving/ConsIndShockModel.py
Lines 1780 to 1794 in 3ee3979
However, when initializing a PortfolioConsumerType, we instantiate the parent RiskyAssetConsumerType
which instantiates the parent IndShockConsumerType
which itself updates, and calls update_terminal_solution. So, this is the second call to update_terminal_solution
But we are not done....
PortfolioConsumerType has a pre_solve method
HARK/HARK/ConsumptionSaving/ConsPortfolioModel.py
Lines 176 to 179 in 3ee3979
so this is the third time we're calling update_terminal_solution by my count!
If we are lucky, it's calling the same update_terminal_solution
3 times. I don't understand this enough but I think I have been in situations where, due to poor inheritance practices, the update_teriminal_solution
that I expected is not the one being run, or at least not the last one being run.
This is a big issue that sometimes makes debugging solutions harder than it needs to be.
I think the solution is to remove the following lines
HARK/HARK/ConsumptionSaving/ConsPortfolioModel.py
Lines 174 to 178 in 3ee3979
but this might not be the only model that does something like this
Why don't we use super?
No I mean in general, super at instantiation
Yeah, this is a problem. I think some agent types run the "create income process" from ConsIndShock as much as 3 times each for a single solve. Which can take longer than the solve itself...
Maybe a policy for this would be that every agent type should define (not simply inherit) its full update
, pre_solve
, and post_solve
methods? You'd be free to call super.update_whatever(...)
in them, but at least you would be doing it consciously?