From fc5c61a55b3d6991e9cff073c04691337757e13b Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Mon, 26 Aug 2024 14:28:27 +0200 Subject: [PATCH] fix for seed --- bind/G4Calo.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bind/G4Calo.py b/bind/G4Calo.py index c2eed20..68a90ec 100644 --- a/bind/G4Calo.py +++ b/bind/G4Calo.py @@ -152,8 +152,9 @@ def _run_mini_batch( from G4Calo import __G4System G4System = __G4System() seed = int(batch_seed + counter) - #truncate to 32 bit, lower 32 bit are used in G4 - seed = seed & 0xFFFFFFFF + + print(f"Running mini batch with seed {seed}") + G4System.init(cw, seed) #counter gives random seed offset df = G4System.run_batch(nEvents, particleSpec, minEnergy_GeV, maxEnergy_GeV,"") @@ -188,8 +189,11 @@ def run_batch( nevents = [nEventsPerCore if i < nCores - 1 else nEventsLastCore for i in range(nCores)] - batch_seed = int(time.time()*1000) - + batch_seed = int(time.time()) #this is seconds + # make sure that the seed is different for next run. This is not perfect but should be good enough + # given the course takes a week this should be sufficient (10^7 seconds ~ 4 months) + time.sleep(1) + batch_seed = batch_seed % 10000000 print(f"Batch seed: {batch_seed}") #use a multiprocessing pool to run the mini batches in parallel with multiprocessing.Pool(nCores) as pool: