|
| 1 | +Wrote profile results to test_arg_recorder_with_wf.py.lprof |
| 2 | +Timer unit: 1e-06 s |
| 3 | + |
| 4 | +Total time: 0.565759 s |
| 5 | +File: /home/jaime/lib/ftprime/ftprime/argrecorder.py |
| 6 | +Function: add_individual at line 26 |
| 7 | + |
| 8 | +Line # Hits Time Per Hit % Time Line Contents |
| 9 | +============================================================== |
| 10 | + 26 @profile |
| 11 | + 27 def add_individual(self, name, time, population=msprime.NULL_POPULATION, |
| 12 | + 28 is_sample=False): |
| 13 | + 29 '''Add a new individual. |
| 14 | + 30 We need to add individuals when they are *born*, |
| 15 | + 31 rather than the first time they reproduce, to ensure |
| 16 | + 32 that records are output in order by birth time of the parent. |
| 17 | + 33 ''' |
| 18 | + 34 101240 72447 0.7 12.8 if name not in self: |
| 19 | + 35 101240 58303 0.6 10.3 self[name] = (msprime.Node(time=time, population=population, |
| 20 | + 36 101240 297613 2.9 52.6 name=name, is_sample=is_sample), []) |
| 21 | + 37 101240 137396 1.4 24.3 self.num_nodes = max(self.num_nodes, 1+int(name)) |
| 22 | + |
| 23 | +Total time: 7.5774 s |
| 24 | +File: /home/jaime/lib/ftprime/ftprime/argrecorder.py |
| 25 | +Function: add_record at line 39 |
| 26 | + |
| 27 | +Line # Hits Time Per Hit % Time Line Contents |
| 28 | +============================================================== |
| 29 | + 39 @profile |
| 30 | + 40 def add_record(self, left, right, parent, children): |
| 31 | + 41 ''' |
| 32 | + 42 Add records corresponding to a reproduction event in which children (a |
| 33 | + 43 tuple of IDs) inherit from parent (a single ID) on the interval |
| 34 | + 44 [left,right). |
| 35 | + 45 ''' |
| 36 | + 46 # unneeded but helpful for debugging |
| 37 | + 47 150314 120881 0.8 1.6 if parent not in self.keys(): |
| 38 | + 48 raise ValueError("Parent " + str(parent) + |
| 39 | + 49 "'s birth time has not been recorded with " + |
| 40 | + 50 ".add_individual().") |
| 41 | + 51 # time = self[parent][0] |
| 42 | + 52 150314 79151 0.5 1.0 new_rec = msprime.Edgeset( |
| 43 | + 53 150314 71103 0.5 0.9 parent=parent, |
| 44 | + 54 150314 66660 0.4 0.9 children=children, |
| 45 | + 55 150314 65861 0.4 0.9 left=left, |
| 46 | + 56 150314 325604 2.2 4.3 right=right) |
| 47 | + 57 150314 6848145 45.6 90.4 merge_records(new_rec, self[parent][1]) |
| 48 | + |
| 49 | +Total time: 4.08047 s |
| 50 | +File: /home/jaime/lib/ftprime/ftprime/argrecorder.py |
| 51 | +Function: merge_records at line 142 |
| 52 | + |
| 53 | +Line # Hits Time Per Hit % Time Line Contents |
| 54 | +============================================================== |
| 55 | + 142 @profile |
| 56 | + 143 def merge_records(new, existing): |
| 57 | + 144 ''' |
| 58 | + 145 Incorporate a new record (l,r,x,c,t[x]) |
| 59 | + 146 into a list of existing ones (a,b,x,C,t[x]) sorted on left endpoint. |
| 60 | + 147 Keeping them in sorted order simplifies the procedure |
| 61 | + 148 (makes it so we don't have to split the new record). |
| 62 | + 149 ''' |
| 63 | + 150 150314 101369 0.7 2.5 k = 0 |
| 64 | + 151 150314 87001 0.6 2.1 cur_left = new.left |
| 65 | + 152 # print("MR: -----") |
| 66 | + 153 # print("adding", new) |
| 67 | + 154 # print(" to", existing) |
| 68 | + 155 308472 241009 0.8 5.9 while (k < len(existing)) and (cur_left < new.right): |
| 69 | + 156 158158 124833 0.8 3.1 left = existing[k].left |
| 70 | + 157 158158 93386 0.6 2.3 right = existing[k].right |
| 71 | + 158 158158 90150 0.6 2.2 parent = existing[k].parent |
| 72 | + 159 158158 96347 0.6 2.4 children = existing[k].children |
| 73 | + 160 # print("k:",k) |
| 74 | + 161 # print("existing:",existing[k]) |
| 75 | + 162 # print("cur_left:",cur_left) |
| 76 | + 163 158158 92653 0.6 2.3 if new.parent != parent: |
| 77 | + 164 raise ValueError("Trying to merge records with different parents.") |
| 78 | + 165 158158 85414 0.5 2.1 if right <= cur_left: |
| 79 | + 166 # no overlap |
| 80 | + 167 # print("no overlap") |
| 81 | + 168 15534 8903 0.6 0.2 k += 1 |
| 82 | + 169 15534 7404 0.5 0.2 continue |
| 83 | + 170 142624 77301 0.5 1.9 if cur_left < left: |
| 84 | + 171 # print("dangling left") |
| 85 | + 172 15409 10416 0.7 0.3 existing.insert(k, msprime.Edgeset( |
| 86 | + 173 15409 7887 0.5 0.2 left=cur_left, |
| 87 | + 174 15409 16021 1.0 0.4 right=min(new.right, left), |
| 88 | + 175 15409 7897 0.5 0.2 parent=parent, |
| 89 | + 176 15409 43180 2.8 1.1 children=new.children)) |
| 90 | + 177 15409 15864 1.0 0.4 cur_left = min(new.right, left) |
| 91 | + 178 15409 9449 0.6 0.2 k += 1 |
| 92 | + 179 15409 7490 0.5 0.2 continue |
| 93 | + 180 127215 393801 3.1 9.7 combined_children = tuple(sorted(children+new.children)) |
| 94 | + 181 127215 87066 0.7 2.1 combined_rec = msprime.Edgeset( |
| 95 | + 182 127215 67410 0.5 1.7 left=cur_left, |
| 96 | + 183 127215 234108 1.8 5.7 right=min(new.right, right), |
| 97 | + 184 127215 73773 0.6 1.8 parent=new.parent, |
| 98 | + 185 127215 312244 2.5 7.7 children=combined_children) |
| 99 | + 186 127215 78337 0.6 1.9 if cur_left == left: |
| 100 | + 187 # print("equal left") |
| 101 | + 188 105571 67860 0.6 1.7 if new.right < right: |
| 102 | + 189 # print("overlap right") |
| 103 | + 190 21590 13336 0.6 0.3 mod_rec = msprime.Edgeset( |
| 104 | + 191 21590 12284 0.6 0.3 left=new.right, |
| 105 | + 192 21590 11592 0.5 0.3 right=right, |
| 106 | + 193 21590 11575 0.5 0.3 parent=parent, |
| 107 | + 194 21590 149418 6.9 3.7 children=children) |
| 108 | + 195 21590 19858 0.9 0.5 existing[k] = combined_rec |
| 109 | + 196 21590 13557 0.6 0.3 k += 1 |
| 110 | + 197 21590 20224 0.9 0.5 existing.insert(k, mod_rec) |
| 111 | + 198 21590 13962 0.6 0.3 k += 1 |
| 112 | + 199 else: |
| 113 | + 200 # print("dangling right") |
| 114 | + 201 83981 71541 0.9 1.8 existing[k] = combined_rec |
| 115 | + 202 83981 55980 0.7 1.4 k += 1 |
| 116 | + 203 else: |
| 117 | + 204 # here we know that left < cur_left < right |
| 118 | + 205 # print("overlap left") |
| 119 | + 206 21644 13649 0.6 0.3 mod_rec = msprime.Edgeset( |
| 120 | + 207 21644 11864 0.5 0.3 left=left, |
| 121 | + 208 21644 11487 0.5 0.3 right=cur_left, |
| 122 | + 209 21644 11471 0.5 0.3 parent=parent, |
| 123 | + 210 21644 93849 4.3 2.3 children=children) |
| 124 | + 211 21644 20146 0.9 0.5 existing[k] = mod_rec |
| 125 | + 212 21644 13783 0.6 0.3 k += 1 |
| 126 | + 213 21644 20156 0.9 0.5 existing.insert(k, combined_rec) |
| 127 | + 214 21644 13301 0.6 0.3 k += 1 |
| 128 | + 215 21644 14807 0.7 0.4 if new.right < right: |
| 129 | + 216 # print("overlap right") |
| 130 | + 217 existing.insert(k, msprime.Edgeset( |
| 131 | + 218 left=new.right, |
| 132 | + 219 right=right, |
| 133 | + 220 parent=parent, |
| 134 | + 221 children=children)) |
| 135 | + 222 k += 1 |
| 136 | + 223 127215 110940 0.9 2.7 cur_left = min(new.right, right) |
| 137 | + 224 # add whatever's left at the end |
| 138 | + 225 150314 101572 0.7 2.5 if cur_left < new.right: |
| 139 | + 226 82579 60579 0.7 1.5 existing.insert(k, msprime.Edgeset( |
| 140 | + 227 82579 47194 0.6 1.2 left=cur_left, |
| 141 | + 228 82579 50544 0.6 1.2 right=new.right, |
| 142 | + 229 82579 47932 0.6 1.2 parent=new.parent, |
| 143 | + 230 82579 428151 5.2 10.5 children=new.children)) |
| 144 | + 231 # print("getting") |
| 145 | + 232 # for x in existing: |
| 146 | + 233 # print(" ", x) |
| 147 | + 234 150314 77143 0.5 1.9 return None |
| 148 | + |
0 commit comments