-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_separation.py
71 lines (52 loc) · 2.78 KB
/
run_separation.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
import numpy as np
import os
import itertools
import threading
from compsim.io import separation_simulator_grid_saver
from compsim.simulate import NewSeparationSimulator, SeparationSimulator, ConnectivityRule
from compsim.plot import RasterPlotter, VectorPlotter, CroppedVectorPlotter, FixedCroppedVectorPlotter
from compsim.io import separation_simulator_grid_loader, MetricsIO, GREYSCALE_COLORS, BRIGHT_COLORS
thread = False
def run_simulation(input_file, root_dir, c, model_name):
grid = separation_simulator_grid_loader(input_file, colors=GREYSCALE_COLORS)
cs = NewSeparationSimulator(grid, c[0], c[1], allow_swap=True)
sim_name = "lambda-%.2f--alpha-%.2f" % (cs.bias, cs.bias_alpha)
print "Starting new simulation: %s. %d simulations currently running." % (sim_name, threading.activeCount() - 1)
total_iterations = 50000000
i = 0
unit_iterations = 10000000
plot_iterations = 5 * unit_iterations
path = os.path.join(root_dir, model_name, sim_name)
gif_path = os.path.join(root_dir, model_name, sim_name, "animation.gif")
plotter = VectorPlotter(cs, path)
plotter.plot("%d.pdf" % i)
if True:
while i < total_iterations:
cs.run_iterations(unit_iterations)
i += unit_iterations
print "%s: %d iterations run" % (sim_name, i)
if i % plot_iterations == 0:
plotter.plot("%d.pdf" % i)
separation_simulator_grid_saver(os.path.join(path, "%d.txt" % i), grid)
plotter.close()
print "Simulation completed: %s. %d simulations still running." % (sim_name, threading.activeCount() - 1)
if __name__ == "__main__":
input_dir = "input/separation/generated/"
root_dir = "output/NewSeparationSimulator/2-16-sanscrop/"
#input_files = ["2-compressed-largef.txt"] #, "2-compressed-smallf.txt", "2-spread-largef.txt", "2-spread-smallf.txt"]
#input_files = ["3-compressed-largef.txt", "3-spread-largef.txt", "3-spread-smallf.txt"] #"3-compressed-smallf.txt",
input_files = ["100particles-2class.txt"] #, "100particles-3class.txt"]
#input_files = ["two-particles.txt"]
for f in input_files:
input_file = os.path.join(input_dir, f)
model_name = os.path.splitext(os.path.basename(input_file))[0]
compression_constants = {0.58}
separation_constants = {0.58}
print "Now starting model %s" % model_name
if thread:
for c in itertools.product(compression_constants, separation_constants):
threading.Thread(target=run_simulation, args=(input_file, root_dir, c, model_name)).start()
else:
for c in itertools.product(compression_constants, separation_constants):
run_simulation(input_file, root_dir, c, model_name)
print "Successfully completed model %s" % model_name