You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
When I running the flowing code, I found the memroy increased very quickly (until more that 100G and I killed it).
It is wired, because in each iteration there are only one tree in process. Why the memory inceased along with the iteration.
Furthermor, when I add ts.nbytes, the memory no icreased so quickly. But the speed became slower obviously.
How I can fix that?
You're right, this code chunk does have a serious memory leak - I'm not sure why yet, but I have reproduced it. Luckily, there's a much more efficient way to do what you want which doesn't have a memory leak:
Digging in a bit, this is something to do with using the timedesc order, which involves using self.tree_sequence.tables. Not sure why it's leaking memory so much, but there must be some reference counting going wrong somewhere.
This is a bug, we should try and fix this specific problem with timedesc anyway even if we're not getting at the underlying problem with reference counting in tree_sequence.tables.
@Bai-fengting, I'm not so sure that my solution above is actually resolving things - can you try it out and let me know if it fixes your memory leak problem please?
@Bai-fengting, I'm not so sure that my solution above is actually resolving things - can you try it out and let me know if it fixes your memory leak problem please?
Thanks @jeromekelleher , I tried the above code. But the problem not resolved, the memory still increased quickly.
As you mentioned, it caused by timedesc order. After I remove order="timedesc", the memory not leak.
In fact, I need the count the number of lineages above a specific node in each tree. I used the code mentioned in this issue: #2190 (comment)
As it happens, I've also got an efficient implementation of num_lineages going over in #2422. Hopefully both of these will be released in a week or so.
Here's a function for computing the number of lineages at a specific time from #386:
defnum_tree_lineages_preorder(tree, t):
# Only descend the tree as far as we need to.lineages=0stack= [tree.virtual_root]
whilelen(stack) >0:
parent=stack.pop()
forchildintree.children(parent):
child_time=tree.time(child)
ifchild_time>t:
stack.append(child)
elifchild_time<=t:
lineages+=1returnlineages
I don't think there's way to compute the num_lineages for every node without using timedesc, unfortunately.
Activity
jeromekelleher commentedon Jul 20, 2022
Hi @Bai-fengting, 👋
You're right, this code chunk does have a serious memory leak - I'm not sure why yet, but I have reproduced it. Luckily, there's a much more efficient way to do what you want which doesn't have a memory leak:
Iterating over the trees like this is much more efficient than using
ts.at()repeatedly.jeromekelleher commentedon Jul 20, 2022
Digging in a bit, this is something to do with using the
timedescorder, which involves usingself.tree_sequence.tables. Not sure why it's leaking memory so much, but there must be some reference counting going wrong somewhere.This is a bug, we should try and fix this specific problem with
timedescanyway even if we're not getting at the underlying problem with reference counting intree_sequence.tables.[-]Question about memory usage.[/-][+]Memory leak in ``timedesc`` node order.[/+]jeromekelleher commentedon Jul 20, 2022
@Bai-fengting, I'm not so sure that my solution above is actually resolving things - can you try it out and let me know if it fixes your memory leak problem please?
Bai-fengting commentedon Jul 21, 2022
Thanks @jeromekelleher , I tried the above code. But the problem not resolved, the memory still increased quickly.
As you mentioned, it caused by
timedescorder. After I removeorder="timedesc", the memory not leak.In fact, I need the count the number of lineages above a specific node in each tree. I used the code mentioned in this issue:
#2190 (comment)
Is there other way to do that?
jeromekelleher commentedon Jul 21, 2022
Thanks @Bai-fengting - I'm working on a fix for the leak over in #2417
As it happens, I've also got an efficient implementation of num_lineages going over in #2422. Hopefully both of these will be released in a week or so.
Here's a function for computing the number of lineages at a specific time from #386:
I don't think there's way to compute the num_lineages for every node without using
timedesc, unfortunately.Add direct access to all non-ragged table arrays
Add direct access to all non-ragged table arrays
Add direct access to all non-ragged table arrays
Add direct access to all non-ragged table arrays
Add direct access to all non-ragged table arrays