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
It's hard to efficiently get the parent of a mutation at the moment. But I think we calculate and store the edge associated with each mutation when initialising tree sequence. Could we provide fast array access to this, which would allow parents to be found easily. This is probably part of the "numba"-fying of tskit.
I'm hitting this because of a weird edge-case in compute_mutation_times when the parent and the child nodes of an edge are "next to" each other in time, to with FP accuracy. That function rounds up the "mean" mutation time - i.e. sets it to the parent time, which then fails TS checks. I really want to check for this and round down, but I can't find the parent node of a mutation efficiently to do this.
The edge for a mutation is stored in each tsk_mutation_t an array of which is stored in tsk_treeseq_t as site_mutations_mem (essentially a ragged array for mutations by site). I believe that this could be exposed by mapping a numpy structured array onto this memory, essentially providing the array for free. I'm sure there are some hairy details, but in principle, this should work.
I think the better thing would be to compute a numpy array for this when it's requested. The memory isn't worth saving. So,
@property
def mutations_edge(self):
if self._mutations_edge is None:
self._mutations_edge = self.ll_ts.mutations_edge
return self._mutations_edge
and in CPython we'd make a new numpy array and fill it in by iterating over the mutations. There's no point in getting into hair memory details here, we can keep the code simple and use the documented C API.
(Note, I think we'll end up doing something similar with sites_ancestral_state and mutations_derived_state as we'll need to compute a new Numpy StringDtype array.)
Activity
benjeffery commentedon Jun 6, 2025
The edge for a mutation is stored in each
tsk_mutation_tan array of which is stored intsk_treeseq_tassite_mutations_mem(essentially a ragged array for mutations by site). I believe that this could be exposed by mapping a numpy structured array onto this memory, essentially providing the array for free. I'm sure there are some hairy details, but in principle, this should work.jeromekelleher commentedon Jun 6, 2025
I think the better thing would be to compute a numpy array for this when it's requested. The memory isn't worth saving. So,
and in CPython we'd make a new numpy array and fill it in by iterating over the mutations. There's no point in getting into hair memory details here, we can keep the code simple and use the documented C API.
jeromekelleher commentedon Jun 6, 2025
(Note, I think we'll end up doing something similar with
sites_ancestral_stateandmutations_derived_stateas we'll need to compute a new Numpy StringDtype array.)