-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data.py
67 lines (53 loc) · 1.8 KB
/
generate_data.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
from titan.model import TITAN
from titan.parse_params import create_params
import titan.population_io as pio
import titan.output as ao
import os
import sys
param_file = "viz_basic.yml"
setting = "scott"
outdir="results"
try:
os.mkdir(outdir)
except:
print("results directory already exists, exiting")
exit()
params = create_params(setting, param_file, outdir)
model = TITAN(params)
def run(self, outdir: str):
"""
Runs the model for the number of time steps defined in params, at each time step does:
1. Increments time
2. Takes one step
3. Resets trackers
4. Saves population for visualization
args:
outdir: path to directory where results should be saved
"""
# make sure initial state of things get printed
stats = ao.get_stats(
self.pop.all_agents,
self.deaths,
self.params,
self.exposures,
self.features,
self.time,
)
self.print_stats(stats, outdir)
if self.params.model.time.burn_steps > 0:
print("\t===! Start Burn Loop !===")
# time starts at negative burn steps, model run starts at t = 1
while self.time < self.params.model.time.num_steps:
if self.time == 0:
if self.params.model.time.burn_steps > 0:
print("\t===! Burn Loop Complete !===")
print("\t===! Start Main Loop !===")
self.time += 1
self.step(outdir)
self.reset_trackers()
# save population for viz
pop_outdir = os.path.join(outdir, str(self.time))
os.mkdir(pop_outdir)
pio.write(self.pop, pop_outdir, compress=False)
print("\t===! Main Loop Complete !===")
run(model, outdir)