-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (58 loc) · 2.21 KB
/
main.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
import dataclasses
import json
import configuration
import genetic_algorithm
import island
import simulations
import utils
utils.setup_logging()
_NUM_REPRODUCTIONS = 1
def _make_corpus(factory, args, corpus_seed):
utils.seed(corpus_seed)
return factory(**args)
def run():
arg_parser = utils.make_cli_arguments()
arguments = arg_parser.parse_args()
simulation = simulations.SIMULATIONS[arguments.simulation_name]
for i in range(_NUM_REPRODUCTIONS):
simulation_seed = arguments.base_seed + i
base_config = configuration.SimulationConfig(
seed=simulation_seed,
simulation_id=arguments.simulation_name,
num_islands=arguments.total_islands,
**{**simulations.DEFAULT_CONFIG, **simulation.get("config", {})},
)
corpus_args = simulation["corpus"]["args"]
if arguments.corpus_args is not None:
corpus_args.update(json.loads(arguments.corpus_args))
corpus = _make_corpus(
factory=simulation["corpus"]["factory"],
args=corpus_args,
corpus_seed=base_config.corpus_seed,
)
simulation_config = dataclasses.replace(
base_config,
comment=f"Corpus params: {json.dumps(simulation['corpus']['args'])}, input shape: {corpus.input_sequence.shape}. Output shape: {corpus.target_sequence.shape}",
simulation_id=corpus.name,
resumed_from_simulation_id=arguments.resumed_simulation_id,
)
simulation_config = utils.add_hash_to_simulation_id(simulation_config, corpus)
if arguments.override_existing:
genetic_algorithm.remove_simulation_directory(
simulation_id=simulation_config.simulation_id,
)
utils.seed(simulation_seed)
island.run(
corpus=corpus,
config=simulation_config,
first_island=arguments.first_island
if arguments.first_island is not None
else 0,
last_island=(
arguments.last_island
if arguments.last_island is not None
else simulation_config.num_islands - 1
),
)
if __name__ == "__main__":
run()