Skip to content

Commit

Permalink
ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Oct 1, 2024
1 parent ce779bc commit b8d5623
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
7 changes: 6 additions & 1 deletion HARK/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from HARK.parser import math_text_to_lambda
from typing import Any, Callable, Mapping, List, Union


class Aggregate:
"""
Used to designate a shock as an aggregate shock.
Expand Down Expand Up @@ -267,7 +268,11 @@ def get_dynamics(self):
return self.dynamics

def get_vars(self):
return list(self.shocks.keys()) + list(self.dynamics.keys()) + list(self.reward.keys())
return (
list(self.shocks.keys())
+ list(self.dynamics.keys())
+ list(self.reward.keys())
)

def transition(self, pre, dr):
"""
Expand Down
22 changes: 11 additions & 11 deletions HARK/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def __init__(
self.initial = initial

self.seed = seed # NOQA
self.agent_count = agent_count # TODO: pass this in at block level
self.agent_count = agent_count # TODO: pass this in at block level
self.T_sim = T_sim

# changes here from HARK.core.AgentType
Expand Down Expand Up @@ -534,20 +534,20 @@ def sim_one_period(self):

shocks_now = draw_shocks(
self.shocks,
np.zeros(self.agent_count) # TODO: stupid hack to remove age calculations.
# this needs a little more thought
)
np.zeros(self.agent_count), # TODO: stupid hack to remove age calculations.
# this needs a little more thought
)

pre = self.calibration # for AgentTypeMC, this is conditional on age
# TODO: generalize indexing into calibration.
pre = self.calibration # for AgentTypeMC, this is conditional on age
# TODO: generalize indexing into calibration.

pre.update(self.vars_prev)
pre.update(shocks_now)

# Won't work for 3.8: self.parameters | self.vars_prev | shocks_now
dr = self.dr # AgentTypeMC chooses rule by age;
# that generalizes to age as a DR argument?

dr = self.dr # AgentTypeMC chooses rule by age;
# that generalizes to age as a DR argument?

post = simulate_dynamics(self.dynamics, pre, dr)

Expand All @@ -570,7 +570,7 @@ def sim_birth(self, which_agents):
-------
None
"""

initial_vals = draw_shocks(self.initial, np.zeros(which_agents.sum()))

if np.sum(which_agents) > 0:
Expand Down Expand Up @@ -636,4 +636,4 @@ def clear_history(self):
"""
for var_name in self.vars:
self.history[var_name] = np.empty((self.T_sim, self.agent_count))
self.history[var_name].fill(np.nan)
self.history[var_name].fill(np.nan)
2 changes: 1 addition & 1 deletion HARK/simulation/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ def test_simulate(self):
- history["c"][5]
)

self.assertTrue((a1 == b1).all())
self.assertTrue((a1 == b1).all())
1 change: 1 addition & 0 deletions HARK/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def apply_fun_to_vals(fun, vals):
"""
return fun(*[vals[var] for var in signature(fun).parameters])


# =======================================================
# ================ Other useful functions ===============
# =======================================================
Expand Down

0 comments on commit b8d5623

Please sign in to comment.