-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluator.py
executable file
·182 lines (149 loc) · 7.02 KB
/
evaluator.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#! /usr/bin/env python3
# I, Robert Rozanski, the copyright holder of this work, release this work into the public domain. This applies worldwide. In some countries this may not be legally possible; if so: I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.
from mnm_repr import CellMembrane, Cytosol, EndoplasmicReticulum, ERMembrane, Medium, GolgiApparatus, GolgiMembrane, LipidParticle, MitochInnerMembrane, MitochMatrix, Nucleus, PeroxisomalMembrane, Peroxisome, VacuolarMembrane, Vacuole
from multiprocessing import Pool
from exp_cost_model import CostModel
import pickle
from archive import Archive, InitialModels
from experiment_module import BasicExpModuleNoCosts
from experiment_module import BasicExpModuleWithCosts
from oracle import Oracle
from overseer import OverseerWithModQuality
from overseer import OverseerNoQuality
from quality_module import AllCovered
from quality_module import AllCoveredMinusIgnored
from quality_module import NewCovered
from quality_module import NewCoveredMinusIgnored
from revision_module import RevCAddB
from revision_module import RevCAddR
from revision_module import RevCIAddB# template: the best
from revision_module import RevCIAddR# template: random
class Evaluator:
def __init__(self):
self.compartments = [CellMembrane(), Cytosol(), EndoplasmicReticulum(),
ERMembrane(), Medium(), GolgiApparatus(), GolgiMembrane(), LipidParticle(),
MitochInnerMembrane(), MitochMatrix(), Nucleus(), PeroxisomalMembrane(),
Peroxisome(), VacuolarMembrane(), Vacuole()]
def test_all_single_process(self):
for (case, suffix) in self.test_case_loader():
for overseer in self.system_configuration_generator(case, suffix):
overseer.run()
def test_all_multiprocess(self):
with Pool(processes = 2) as pool:
result = pool.map(self.test_generator, self.test_case_loader())
print(result)
def test_case_loader(self):
# small: 1, 2, 3, 4, 5, 6
# medium: 7, 8, 9, 10, 11
# too big: 11+
for case_number in [8, 9, 10, 11]:
case_file = 'test_cases/case_%s' % case_number
for repetition in range(3):
pkl_file = open(case_file, 'rb')
case = pickle.load(pkl_file)
pkl_file.close()
if len(str(case_number)) == 1:
suffix = 'tc0%s_r%s' % (case_number, repetition)
yield (case, suffix)
else:
suffix = 'tc%s_r%s' % (case_number, repetition)
yield (case, suffix)
def system_configuration_generator(self, case, first_suffix):
for qual in [AllCoveredMinusIgnored]: # NewCoveredMinusIgnored
for rev in [RevCIAddR]: # RevCIAddB
for threshold_addit_mods in [4]: #2, , 8
for stop_threshold in [8]: #2, 4,
suffix = 'conf%s_%s' % (self.get_suffix((qual, rev, threshold_addit_mods, stop_threshold)), first_suffix)
archive_ = Archive()
archive_.mnm_compartments = self.compartments # added access to all compartments
archive_.model_of_ref = case['model_of_ref']
# recording entities with proper IDs: base versions and derived versions
# these entities were involved in producing new versions and are handled below, not here
entities_to_skip = list(case['ents_base_and_derived'].keys())
for list_of_ents in case['ents_base_and_derived'].values():
entities_to_skip.extend(list_of_ents)
for ent in case['all_entities']:
if ent in entities_to_skip:
continue
# not-skipped activities:
ent.ID = archive_.get_new_ent_id()
archive_.mnm_entities.append(ent)
for ent in case['ents_base_and_derived'].keys():
derv_ents = case['ents_base_and_derived'][ent]# need to copy this now, dictionary stops working after ID change
ent.ID = archive_.get_new_ent_id()
archive_.mnm_entities.append(ent)
for derv_ent in derv_ents:
derv_ent.ID = ent.ID
archive_.mnm_entities.append(derv_ent)
for act in case['all_activities']:
act.ID = archive_.get_new_act_id()
archive_.mnm_activities.append(act)
for act in case['add_import_activities']:
act.ID = archive_.get_new_act_id()
archive_.import_activities.append(act)
archive_.record(InitialModels(case['initial_models']))
qual_m = qual(archive_)
rev_m = rev(archive_, sfx=suffix)
cost_model = CostModel(case['all_entities'],
self.compartments, case['all_activities'],
case['model_of_ref'].setup_conditions,
case['add_import_activities'])
cost_model.set_all_basic_costs_to_1()
cost_model.calculate_derived_costs(case['all_activities'])
cost_model.remove_None_valued_elements()
exp_m = BasicExpModuleWithCosts(archive_, cost_model, sfx=suffix) # !!!!! switched from no costs
oracle_ = Oracle(archive_, case['entities_ref'],
case['activities_ref'], case['model_of_ref'],
case['all_entities'], self.compartments,
case['all_activities'], sfx=suffix)
max_numb_cycles = 1000 #
max_time = 4 #
yield OverseerWithModQuality(archive_, rev_m, exp_m,
oracle_, threshold_addit_mods, qual_m, max_numb_cycles,
max_time, suffix, stop_threshold)
def test_generator(self, tpl):
for overseer in self.system_configuration_generator(tpl[0], tpl[1]):
overseer.run()
def get_suffix(self, tpl):
suff_dict = {
(AllCoveredMinusIgnored,RevCIAddR,2,2):'00',
(AllCoveredMinusIgnored,RevCIAddR,2,4):'01',
(AllCoveredMinusIgnored,RevCIAddR,2,8):'02',
(AllCoveredMinusIgnored,RevCIAddR,4,2):'03',
(AllCoveredMinusIgnored,RevCIAddR,4,4):'04',
(AllCoveredMinusIgnored,RevCIAddR,4,8):'05',
(AllCoveredMinusIgnored,RevCIAddR,8,2):'06',
(AllCoveredMinusIgnored,RevCIAddR,8,4):'07',
(AllCoveredMinusIgnored,RevCIAddR,8,8):'08',
(AllCoveredMinusIgnored,RevCIAddB,2,2):'09',
(AllCoveredMinusIgnored,RevCIAddB,2,4):'10',
(AllCoveredMinusIgnored,RevCIAddB,2,8):'11',
(AllCoveredMinusIgnored,RevCIAddB,4,2):'12',
(AllCoveredMinusIgnored,RevCIAddB,4,4):'13',
(AllCoveredMinusIgnored,RevCIAddB,4,8):'14',
(AllCoveredMinusIgnored,RevCIAddB,8,2):'15',
(AllCoveredMinusIgnored,RevCIAddB,8,4):'16',
(AllCoveredMinusIgnored,RevCIAddB,8,8):'17',
(NewCoveredMinusIgnored,RevCIAddR,2,2):'18',
(NewCoveredMinusIgnored,RevCIAddR,2,4):'19',
(NewCoveredMinusIgnored,RevCIAddR,2,8):'20',
(NewCoveredMinusIgnored,RevCIAddR,4,2):'21',
(NewCoveredMinusIgnored,RevCIAddR,4,4):'22',
(NewCoveredMinusIgnored,RevCIAddR,4,8):'23',
(NewCoveredMinusIgnored,RevCIAddR,8,2):'24',
(NewCoveredMinusIgnored,RevCIAddR,8,4):'25',
(NewCoveredMinusIgnored,RevCIAddR,8,8):'26',
(NewCoveredMinusIgnored,RevCIAddB,2,2):'27',
(NewCoveredMinusIgnored,RevCIAddB,2,4):'28',
(NewCoveredMinusIgnored,RevCIAddB,2,8):'29',
(NewCoveredMinusIgnored,RevCIAddB,4,2):'30',
(NewCoveredMinusIgnored,RevCIAddB,4,4):'31',
(NewCoveredMinusIgnored,RevCIAddB,4,8):'32',
(NewCoveredMinusIgnored,RevCIAddB,8,2):'33',
(NewCoveredMinusIgnored,RevCIAddB,8,4):'34',
(NewCoveredMinusIgnored,RevCIAddB,8,8):'35'
}
return suff_dict[tpl]
evaluator = Evaluator()
#evaluator.test_all_single_process()
#evaluator.test_all_multiprocess()