-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To re-run ```sh pip install line_profiler kernprof -v -l tests/test_arg_recorder_with_wf.py > devel/prof.txt kernprof -v -l tests/test_recomb_collector.py > devel/prof_rc.txt ```
- Loading branch information
Showing
5 changed files
with
314 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
Wrote profile results to test_arg_recorder_with_wf.py.lprof | ||
Timer unit: 1e-06 s | ||
|
||
Total time: 0.565759 s | ||
File: /home/jaime/lib/ftprime/ftprime/argrecorder.py | ||
Function: add_individual at line 26 | ||
|
||
Line # Hits Time Per Hit % Time Line Contents | ||
============================================================== | ||
26 @profile | ||
27 def add_individual(self, name, time, population=msprime.NULL_POPULATION, | ||
28 is_sample=False): | ||
29 '''Add a new individual. | ||
30 We need to add individuals when they are *born*, | ||
31 rather than the first time they reproduce, to ensure | ||
32 that records are output in order by birth time of the parent. | ||
33 ''' | ||
34 101240 72447 0.7 12.8 if name not in self: | ||
35 101240 58303 0.6 10.3 self[name] = (msprime.Node(time=time, population=population, | ||
36 101240 297613 2.9 52.6 name=name, is_sample=is_sample), []) | ||
37 101240 137396 1.4 24.3 self.num_nodes = max(self.num_nodes, 1+int(name)) | ||
|
||
Total time: 7.5774 s | ||
File: /home/jaime/lib/ftprime/ftprime/argrecorder.py | ||
Function: add_record at line 39 | ||
|
||
Line # Hits Time Per Hit % Time Line Contents | ||
============================================================== | ||
39 @profile | ||
40 def add_record(self, left, right, parent, children): | ||
41 ''' | ||
42 Add records corresponding to a reproduction event in which children (a | ||
43 tuple of IDs) inherit from parent (a single ID) on the interval | ||
44 [left,right). | ||
45 ''' | ||
46 # unneeded but helpful for debugging | ||
47 150314 120881 0.8 1.6 if parent not in self.keys(): | ||
48 raise ValueError("Parent " + str(parent) + | ||
49 "'s birth time has not been recorded with " + | ||
50 ".add_individual().") | ||
51 # time = self[parent][0] | ||
52 150314 79151 0.5 1.0 new_rec = msprime.Edgeset( | ||
53 150314 71103 0.5 0.9 parent=parent, | ||
54 150314 66660 0.4 0.9 children=children, | ||
55 150314 65861 0.4 0.9 left=left, | ||
56 150314 325604 2.2 4.3 right=right) | ||
57 150314 6848145 45.6 90.4 merge_records(new_rec, self[parent][1]) | ||
|
||
Total time: 4.08047 s | ||
File: /home/jaime/lib/ftprime/ftprime/argrecorder.py | ||
Function: merge_records at line 142 | ||
|
||
Line # Hits Time Per Hit % Time Line Contents | ||
============================================================== | ||
142 @profile | ||
143 def merge_records(new, existing): | ||
144 ''' | ||
145 Incorporate a new record (l,r,x,c,t[x]) | ||
146 into a list of existing ones (a,b,x,C,t[x]) sorted on left endpoint. | ||
147 Keeping them in sorted order simplifies the procedure | ||
148 (makes it so we don't have to split the new record). | ||
149 ''' | ||
150 150314 101369 0.7 2.5 k = 0 | ||
151 150314 87001 0.6 2.1 cur_left = new.left | ||
152 # print("MR: -----") | ||
153 # print("adding", new) | ||
154 # print(" to", existing) | ||
155 308472 241009 0.8 5.9 while (k < len(existing)) and (cur_left < new.right): | ||
156 158158 124833 0.8 3.1 left = existing[k].left | ||
157 158158 93386 0.6 2.3 right = existing[k].right | ||
158 158158 90150 0.6 2.2 parent = existing[k].parent | ||
159 158158 96347 0.6 2.4 children = existing[k].children | ||
160 # print("k:",k) | ||
161 # print("existing:",existing[k]) | ||
162 # print("cur_left:",cur_left) | ||
163 158158 92653 0.6 2.3 if new.parent != parent: | ||
164 raise ValueError("Trying to merge records with different parents.") | ||
165 158158 85414 0.5 2.1 if right <= cur_left: | ||
166 # no overlap | ||
167 # print("no overlap") | ||
168 15534 8903 0.6 0.2 k += 1 | ||
169 15534 7404 0.5 0.2 continue | ||
170 142624 77301 0.5 1.9 if cur_left < left: | ||
171 # print("dangling left") | ||
172 15409 10416 0.7 0.3 existing.insert(k, msprime.Edgeset( | ||
173 15409 7887 0.5 0.2 left=cur_left, | ||
174 15409 16021 1.0 0.4 right=min(new.right, left), | ||
175 15409 7897 0.5 0.2 parent=parent, | ||
176 15409 43180 2.8 1.1 children=new.children)) | ||
177 15409 15864 1.0 0.4 cur_left = min(new.right, left) | ||
178 15409 9449 0.6 0.2 k += 1 | ||
179 15409 7490 0.5 0.2 continue | ||
180 127215 393801 3.1 9.7 combined_children = tuple(sorted(children+new.children)) | ||
181 127215 87066 0.7 2.1 combined_rec = msprime.Edgeset( | ||
182 127215 67410 0.5 1.7 left=cur_left, | ||
183 127215 234108 1.8 5.7 right=min(new.right, right), | ||
184 127215 73773 0.6 1.8 parent=new.parent, | ||
185 127215 312244 2.5 7.7 children=combined_children) | ||
186 127215 78337 0.6 1.9 if cur_left == left: | ||
187 # print("equal left") | ||
188 105571 67860 0.6 1.7 if new.right < right: | ||
189 # print("overlap right") | ||
190 21590 13336 0.6 0.3 mod_rec = msprime.Edgeset( | ||
191 21590 12284 0.6 0.3 left=new.right, | ||
192 21590 11592 0.5 0.3 right=right, | ||
193 21590 11575 0.5 0.3 parent=parent, | ||
194 21590 149418 6.9 3.7 children=children) | ||
195 21590 19858 0.9 0.5 existing[k] = combined_rec | ||
196 21590 13557 0.6 0.3 k += 1 | ||
197 21590 20224 0.9 0.5 existing.insert(k, mod_rec) | ||
198 21590 13962 0.6 0.3 k += 1 | ||
199 else: | ||
200 # print("dangling right") | ||
201 83981 71541 0.9 1.8 existing[k] = combined_rec | ||
202 83981 55980 0.7 1.4 k += 1 | ||
203 else: | ||
204 # here we know that left < cur_left < right | ||
205 # print("overlap left") | ||
206 21644 13649 0.6 0.3 mod_rec = msprime.Edgeset( | ||
207 21644 11864 0.5 0.3 left=left, | ||
208 21644 11487 0.5 0.3 right=cur_left, | ||
209 21644 11471 0.5 0.3 parent=parent, | ||
210 21644 93849 4.3 2.3 children=children) | ||
211 21644 20146 0.9 0.5 existing[k] = mod_rec | ||
212 21644 13783 0.6 0.3 k += 1 | ||
213 21644 20156 0.9 0.5 existing.insert(k, combined_rec) | ||
214 21644 13301 0.6 0.3 k += 1 | ||
215 21644 14807 0.7 0.4 if new.right < right: | ||
216 # print("overlap right") | ||
217 existing.insert(k, msprime.Edgeset( | ||
218 left=new.right, | ||
219 right=right, | ||
220 parent=parent, | ||
221 children=children)) | ||
222 k += 1 | ||
223 127215 110940 0.9 2.7 cur_left = min(new.right, right) | ||
224 # add whatever's left at the end | ||
225 150314 101572 0.7 2.5 if cur_left < new.right: | ||
226 82579 60579 0.7 1.5 existing.insert(k, msprime.Edgeset( | ||
227 82579 47194 0.6 1.2 left=cur_left, | ||
228 82579 50544 0.6 1.2 right=new.right, | ||
229 82579 47932 0.6 1.2 parent=new.parent, | ||
230 82579 428151 5.2 10.5 children=new.children)) | ||
231 # print("getting") | ||
232 # for x in existing: | ||
233 # print(" ", x) | ||
234 150314 77143 0.5 1.9 return None | ||
|
Oops, something went wrong.