From 7829fde6f2e4e78bfb8c05f9889a621b06fa83ba Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Thu, 7 Nov 2024 14:14:45 +0100 Subject: [PATCH] manual seed option --- bind/G4Calo.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bind/G4Calo.py b/bind/G4Calo.py index bb808e8..fb99a49 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -188,7 +188,8 @@ def run_batch( minEnergy_GeV: float, maxEnergy_GeV: float = -1.0, filename: str = "", - no_mp: bool = False): + no_mp: bool = False, + manual_seed : int = -1): ''' splits the batch in jobs depending on how many cores are available and runs mini batches in parallel ''' @@ -215,15 +216,18 @@ def run_batch( nevents = [nEventsPerCore if i < nCores - 1 else nEventsLastCore for i in range(nCores)] - with _g4calo_threading_lock if _g4calo_threading_lock is not None else contextlib.nullcontext(): - # check if file exists, if so, read last seed. If not create it - if os.path.exists(os.path.expanduser("~/.g4calo_seeds.txt")): - with open(os.path.expanduser("~/.g4calo_seeds.txt"), "r") as f: - seed = int(f.read()) - else: - seed = 0 - with open(os.path.expanduser("~/.g4calo_seeds.txt"), "w") as f: - f.write(str(seed + nCores)) + if manual_seed >= 0: + seed = manual_seed + else: + with _g4calo_threading_lock if _g4calo_threading_lock is not None else contextlib.nullcontext(): + # check if file exists, if so, read last seed. If not create it + if os.path.exists(os.path.expanduser("~/.g4calo_seeds.txt")): + with open(os.path.expanduser("~/.g4calo_seeds.txt"), "r") as f: + seed = int(f.read()) + else: + seed = 0 + with open(os.path.expanduser("~/.g4calo_seeds.txt"), "w") as f: + f.write(str(seed + nCores)) seed += 1 print(f"Batch seed: {seed}")