Skip to content

Commit 5c55a5e

Browse files
Fixed determinism issue
1 parent 0d703f3 commit 5c55a5e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/tlo/methods/demography.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ def assign_closest_facility_level(self):
485485
nearest-neighbor matching, restricted to facilities within each individual's district.
486486
"""
487487
import hashlib
488-
import secrets
489-
import time
490488

491489
worldpop_gdf = self.parameters["worldpop_gdf"].copy()
492490
worldpop_gdf["Z_prop"] = pd.to_numeric(worldpop_gdf["Z_prop"], errors="coerce")
@@ -518,9 +516,12 @@ def assign_closest_facility_level(self):
518516
"Nkhatabay": "Nkhata Bay",
519517
}
520518

521-
# Worldpop-weighted coordinate assignment
522-
run_seed = secrets.token_bytes(16) + int(time.time() * 1e9).to_bytes(8, "big")
523-
unique_districts = df["district_of_residence"].unique()
519+
# Worldpop-weighted coordinate assignment.
520+
# FIX: derive run_seed from the module RNG (not secrets/time) so results are
521+
# reproducible across runs that share the same random seed.
522+
run_seed = self.rng.randint(0, 2 ** 31 - 1).to_bytes(4, "big")
523+
# FIX: sort districts so iteration order is deterministic regardless of PYTHONHASHSEED.
524+
unique_districts = sorted(df["district_of_residence"].unique())
524525

525526
district_to_coords = {}
526527
for district in unique_districts:

0 commit comments

Comments
 (0)