Check for non-provided states
@@ -520,6 +520,10 @@ class AgentType(Model):
if self.read_shocks and bool(self.newborn_init_history):
for var_name in self.state_now:
+
+ # Check that we are actually given a value for the variable
+ if var_name in self.newborn_init_history.keys():
+
# Copy only array-like idiosyncratic states. Aggregates should
# not be set by newborns
idio = (
@@ -529,6 +533,14 @@ class AgentType(Model):
if idio:
self.state_now[var_name] = self.newborn_init_history[var_name][0]
+ else:
+
+ warn(
+ 'The option for reading shocks was activated but ' +
+ 'the model requires state ' + var_name + ', not contained in ' +
+ 'newborn_init_history.'
+ )
+
self.clear_history()
return None
@@ -689,10 +701,13 @@ class AgentType(Model):
None
"""
if self.read_shocks:
+
who_dies = self.shock_history["who_dies"][self.t_sim, :]
# Instead of simulating births, assign the saved newborn initial conditions
if np.sum(who_dies) > 0:
for var_name in self.state_now:
+
+ if var_name in self.newborn_init_history.keys():
# Copy only array-like idiosyncratic states. Aggregates should
# not be set by newborns
idio = (
@@ -700,9 +715,19 @@ class AgentType(Model):
and len(self.state_now[var_name]) == self.AgentCount
)
if idio:
+
self.state_now[var_name][who_dies] = self.newborn_init_history[
var_name
][self.t_sim, who_dies]
+
+ else:
+
+ warn(
+ 'The option for reading shocks was activated but ' +
+ 'the model requires state ' + var_name + ', not contained in ' +
+ 'newborn_init_history.'
+ )
+
# Reset ages of newborns
self.t_age[who_dies] = 0
else:
