Skip to content

Commit

Permalink
Add seedability
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Sep 24, 2024
1 parent 3191cf2 commit 45570de
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,14 @@ def to_input_dataframe(
return df

def subsample(
self, n=None, frac=None, key=None, time_period=None
self, n=None, frac=None, seed=None, time_period=None
) -> "Simulation":
"""Quantize the simulation to a smaller size by sampling households.
Args:
n (int, optional): The number of households to sample. Defaults to 10_000.
frac (float, optional): The fraction of households to sample. Defaults to None.
key (int, optional): The key used to seed the random number generator. Defaults to the dataset name.
seed (int, optional): The key used to seed the random number generator. Defaults to the dataset name.
time_period (str, optional): Sample households based on their weight in this time period. Defaults to the default calculation period.
Returns:
Expand Down Expand Up @@ -1521,7 +1521,7 @@ def subsample(
return self

# Seed the random number generators for reproducibility
random.seed(key)
random.seed(str(seed))
state = random.randint(0, 2**32 - 1)
np.random.seed(state)

Expand Down

0 comments on commit 45570de

Please sign in to comment.