econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
333 stars 198 forks source link

Updating agent counts throws an error #1299

Open DominicWC opened 1 year ago

DominicWC commented 1 year ago

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

mnwhite commented 1 year ago

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

DominicWC commented 1 year ago

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
'''
mnwhite commented 1 year ago

Does it say which variable that's being generated for? I have a guess of what's happening.

On Fri, Jul 7, 2023 at 2:27 PM DominicWC @.***> wrote:

This is the error it throws: IndexError: boolean index did not match indexed array along dimension 0; dimension is 10000 but corresponding boolean dimension is 20000

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1299#issuecomment-1625826908, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFIVUUZICSDBBJDQDSLXPBIIJANCNFSM6AAAAAA2CECD2A . You are receiving this because you commented.Message ID: @.***>

DominicWC commented 1 year ago

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