forked from martinventer/virtual_creatures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
montepython_hpc_noice progress bar here.py
131 lines (105 loc) · 2.8 KB
/
montepython_hpc_noice progress bar here.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from CreatureTools_n import Creature
import numpy as np
import multiprocessing as mp
import os
import pandas as pd
from datetime import datetime
import sys
import time
# from scipy.interpolate import interp1d
#
# from scipy import interpolate
# from tqdm import tqdm
def genGen():
choices = [
'F',
'+',
'-',
]
proba1 = np.random.uniform(0, 1)
proba2 = 1 - proba1
rule1 = ''.join([np.random.choice(choices)
for _ in range(5)]) + 'X'
rule2 = ''.join([np.random.choice(choices)
for _ in range(5)]) + 'X'
params = {
'num_char': 100,
'variables': 'X',
'constants': 'F+-',
'axiom': 'FX',
'rules': {
'X': {
'options': [
rule1,
rule2,
],
'probabilities': [proba1, proba2]
}
},
'point': np.array([0, 0]),
'vector': np.array([0, 1]),
'length': 1.0,
'angle': np.random.randint(0, 90) # random
}
population = [[
'L-string',
'Coordinates',
'Area',
'Bounding Coordinates',
'% of F',
'% of +',
'% of -',
'Longest F sequence',
'Longest + sequence',
'Longest - sequence',
'Average chars between Fs',
'Average chars between +s',
'Average chars between -s',
'Angle',
'Rules'
]]
c = Creature(params)
a = (
c.l_string,
c.coords.tolist(),
c.area,
c.bounds,
c.perF,
c.perP,
c.perM,
c.maxF,
c.maxP,
c.maxM,
c.avgF,
c.avgP,
c.avgM,
c.angle,
c.rules,
)
return list(a)
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
if __name__ == "__main__":
iter = 10000
population = []
with mp.Pool() as pool:
for i in range(iter):
progress(i, iter, status='Doing job')
np.random.seed()
results = pool.apply_async(genGen)
population.append(results.get())
pool.join()
sys.stdout.write('Done! Writing to CSV')
sys.stdout.flush()
population = pd.DataFrame(population[1:], columns=population[0])
curr_dir = os.path.dirname(__file__)
now = datetime.utcnow().strftime('%b %d, %Y @ %H.%M')
file_name = os.path.join(
curr_dir, 'monte_carlo ' + now + '_.csv')
population.to_csv(file_name, index=None, header=True,
chunksize=10000)