This repository was archived by the owner on Mar 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_sim.py
More file actions
71 lines (59 loc) · 2.11 KB
/
run_sim.py
File metadata and controls
71 lines (59 loc) · 2.11 KB
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
#!/usr/bin/env python
#=========================================================================
# run-sim [options]
#=========================================================================
#
# -c --config <path> set path to config file (.yaml)
# -r --result <path> set path where results will be written (.pkl)
#
# -d enable degen restart mode with default degen_score of 10 and degen_epoch of 50
# --degen_score <score> enable degen restart mode with degen_score of <score>
# --degen_epoch <epoch> set epoch after which degen_score must be met to avoid restart if degen restart mode is enabled
#
# Author : Darren Midkiff
# Date : May 13, 2021
#
import sys
import getopt
from ant_nn.simulation import Simulation
import dill
def main(cmdline_opts):
try:
short_opts = 'c:r:d'
long_opts = ['config=', 'result=', 'degen-epoch=', 'degen-score=']
optlist, args = getopt.getopt(cmdline_opts, short_opts, long_opts)
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
# default paths
config_path = "config.yaml"
result_path = "result.yaml"
# default degen settings
degen_epoch = None
degen_score = 10
# parse args
for opt,arg in optlist:
if opt in ("-c", "--config"):
config_path = arg
if opt in ("-r", "--result"):
result_path = arg
if opt == '-d':
degen_epoch = 50
if opt == "--degen-epoch":
degen_epoch = int(arg)
if opt == "--degen-score":
degen_score = int(arg)
print("config file:", config_path)
print("result file:", result_path)
print()
sim = Simulation(config_path=config_path)
chromosomes, scores, final_pop, food = sim.run(degen_epoch=degen_epoch, degen_score=degen_score)
file = open(result_path, "wb")
dill.dump([chromosomes, scores, final_pop, food], file)
file.close()
print("done")
if __name__ == "__main__":
cmdline_opts = sys.argv[1:]
main( cmdline_opts )