econ-ark/HARK

Updating agent counts throws an error

Opened this issue · 4 comments

Describe the bug
If we run a simulation with a certain number of agents, and then change the number of agents and rerun a simulation, we get an error.

We're able to change other parameters, like the distributions of income, but not the agent count.

To Reproduce
Run the following:

from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType
agent=PerfForesightConsumerType()
agent.solve()
Params={"AgentCount":10000,"aNrmInitStd": 1.0,"T_sim":10}
agent.assign_parameters(**Params)
agent.initialize_sim()
agent.simulate()
print("First simulation works")

Params={"AgentCount":10000,"aNrmInitStd": 2.0,"T_sim":10}
agent.assign_parameters(**Params)
agent.initialize_sim()
agent.simulate()
print("Second simulation works")

Params={"AgentCount":20000,"aNrmInitStd": 1.0,"T_sim":10}
agent.assign_parameters(**Params)
agent.initialize_sim()
agent.simulate()
print("Third simulation works")

Expected behavior
All three simulations should run without issue

Desktop:
OS: Windows
Browser: Firefox
Econ-ARK and Python version: 0.13.0 and Python 3.9.13

Can you put the failure mode or error here? What happens on the third simulation?

This is the error it throws:
c:...anaconda3\lib\site-packages\HARK\ConsumptionSaving\ConsIndShockModel.py in sim_birth(self, which_agents)

   1736         # Get and store states for newly born agents
   1737         N = np.sum(which_agents)  # Number of new consumers to make
-> 1738         self.state_now["aNrm"][which_agents] = Lognormal(
   1739             mu=self.aNrmInitMean,
   1740             sigma=self.aNrmInitStd,
IndexError: boolean index did not match indexed array along dimension 0; dimension is 10000 but corresponding boolean dimension is 20000
'''

That's all that the error message gives me. It should be pretty easy to reproduce by running the code in an empty file.