Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method (empty) for preSolve called checkRestrictions that can b… #324

Merged
merged 4 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion HARK/ConsumptionSaving/ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ def reset(self):
self.initializeSim()
self.aLvlNow = self.kInit*np.ones(self.AgentCount) # Start simulation near SS
self.aNrmNow = self.aLvlNow/self.pLvlNow

def preSolve(self):
AgentType.preSolve()
self.updateSolutionTerminal()

def updateSolutionTerminal(self):
Expand Down
5 changes: 3 additions & 2 deletions HARK/ConsumptionSaving/ConsGenIncProcessModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from builtins import range
from copy import deepcopy
import numpy as np
from HARK import HARKobject
from HARK import AgentType, HARKobject
from HARK.interpolation import LowerEnvelope2D, BilinearInterp, VariableLowerBoundFunc2D, \
LinearInterpOnInterp1D, LinearInterp, CubicInterp, UpperEnvelope
from HARK.utilities import CRRAutility, CRRAutilityP, CRRAutilityPP, CRRAutilityP_inv, \
Expand Down Expand Up @@ -985,8 +985,9 @@ def __init__(self, cycles=1, time_flow=True, **kwds):
# Initialize a basic ConsumerType
IndShockConsumerType.__init__(self, cycles=cycles, time_flow=time_flow, **kwds)
self.solveOnePeriod = solveConsGenIncProcess # idiosyncratic shocks solver with explicit persistent income

def preSolve(self):
AgentType.preSolve()
self.updateSolutionTerminal()

def update(self):
Expand Down
12 changes: 10 additions & 2 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,8 +1498,14 @@ def __init__(self,cycles=1, time_flow=True,verbose=False,quiet=False, **kwds):
self.solveOnePeriod = solvePerfForesight # solver for perfect foresight model


def preSolve(self):
self.updateSolutionTerminal()
def checkRestrictions(self):
"""
A method to check that various restrictions are met for the model class.
"""
if self.DiscFac < 0:
raise Exception('DiscFac is below zero with value: ' + str(self.DiscFac))

return

def updateSolutionTerminal(self):
'''
Expand Down Expand Up @@ -2011,6 +2017,7 @@ def makeEulerErrorFunc(self,mMax=100,approx_inc_dstn=True):
self.eulerErrorFunc = eulerErrorFunc

def preSolve(self):
AgentType.preSolve(self)
# Update all income process variables to match any attributes that might
# have been changed since `__init__` or `solve()` was last called.
self.updateIncomeProcess()
Expand Down Expand Up @@ -2121,6 +2128,7 @@ def __init__(self,cycles=1,time_flow=True,**kwds):
self.update() # Make assets grid, income process, terminal solution

def preSolve(self):
AgentType.preSolve(self)
self.updateSolutionTerminal()

def calcBoundingValues(self):
Expand Down
6 changes: 3 additions & 3 deletions HARK/ConsumptionSaving/ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from builtins import range
from copy import deepcopy
import numpy as np
from HARK import AgentType
from HARK.ConsumptionSaving.ConsIndShockModel import ConsIndShockSolver, ValueFunc, \
MargValueFunc, ConsumerSolution, IndShockConsumerType
from HARK.simulation import drawDiscrete, drawUniform
Expand Down Expand Up @@ -199,7 +200,7 @@ def defBoundary(self):
possible_next_states = self.MrkvArray[i,:] > 0
self.BoroCnstNat_list[i] = np.max(self.BoroCnstNatAll[possible_next_states])

# Explicitly handle the "None" case:
# Explicitly handle the "None" case:
if self.BoroCnstArt is None:
self.mNrmMin_list[i] = self.BoroCnstNat_list[i]
else:
Expand Down Expand Up @@ -734,7 +735,7 @@ def preSolve(self):
-------
None
"""
self.updateSolutionTerminal()
AgentType.preSolve(self)
self.checkMarkovInputs()

def updateSolutionTerminal(self):
Expand Down Expand Up @@ -1127,4 +1128,3 @@ def main():

if __name__ == '__main__':
main()

7 changes: 7 additions & 0 deletions HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ def checkElementsOfTimeVaryAreLists(self):
assert type(getattr(self, param)) == list, param + ' is not a list, but should be' + \
' because it is in time_vary'

def checkRestrictions(self):
"""
A method to check that various restrictions are met for the model class.
"""
return

def preSolve(self):
'''
A method that is run immediately before the model is solved, to check inputs or to prepare
Expand All @@ -422,6 +428,7 @@ def preSolve(self):
-------
none
'''
self.checkRestrictions()
self.checkElementsOfTimeVaryAreLists()
return None

Expand Down