-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprofile_time.py
55 lines (35 loc) · 1.61 KB
/
profile_time.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
from tqdm import tqdm
import time
from testing_script_hadrmod import *
hmodel_list = ["PHOJET112", "SIBYLL23D", "EPOSLHC", "QGSJET01C", "URQMD34"]
def base_profile(Nsim=10, Np=100, density=1e17):
"""Runs all models a number of cycles and reports on the
average and std for time duration.
Nsim : number of cycles
Np : number of primaries per cycle
"""
tprofile = np.zeros((Nsim, len(hmodel_list)))
with tqdm(total=100) as pbar:
for nhm, hmodel in enumerate(hmodel_list):
HMRunInstance = get_hi_generator(hmodel)
for simnum in range(1, Nsim):
output_filename = f"output_{hmodel}_Np{Np:}_{simnum:02d}.txt"
tstart = time.time()
TestRun1D_tracks(Np, output_filename, seed=None, density=density)
dt = time.time() - tstart
tprofile[simnum, nhm] = dt
pbar.update(100 * Nsim/len(hmodel_list))
np.savetxt('time_profile_' + ('_'.join(hmodel_list) + '.txt'), tprofile)
if __name__ == "__main__":
import os
density_grid = np.logspace(15, 30, 30, endpoint=False)
for d in density_grid[:]:
dirname = f'density={d:3.2e}'
os.makedirs(dirname, exist_ok=True)
base_profile(Nsim=10, Np=1000)
for filename in os.listdir('./'):
if filename.startswith('output') and filename.endswith('txt'):
os.rename(filename, os.path.join(dirname, filename))
tprof_filename = 'time_profile_' + ('_'.join(hmodel_list) + '.txt')
os.rename(tprof_filename, os.path.join(dirname, tprof_filename))