Skip to content

consider number of nodes in simplification interval? #94

Closed

Description

@petrelharp

In running a large-ish model, @mufernando has run out of space in the table, triggering the

Error:tsk_node_table_add_row: Table column too large; cannot be more than 2**31 bytes.

error. This is done with a population of size 125,000, and hits the limit at around 100,000 generations. For a concrete example, see #62. Setting the simplification interval manually (in our case to 500) fixes the problem. So, this should be part of the automatic simplification interval calculation: if the table is getting close to the maximum (which from #62 is something like 214748263 nodes in the node table),
then simplify. I guess two options would be:

  1. if we're close to the limit, then simplify
  2. look ahead and extrapolate whether we will be close to the limit by the next simplification, and if so, make the simplification interval smaller

(1) is much simpler, and I don't see downsides. I vote for that, although maybe the user should be notified if it's happening really very often? Like, if it happens at two generations in a row, throw a warning saying that we're running out of room in the tables, and ther model is too big or too many individuals have been remembered for tree sequences at the moment.

Activity

  1. bhaller commented on May 14, 2020

    @bhaller
    Contributor

    Hmm. If the model is just going with the default simplification behavior, then this seems fine – improve the default behavior, good. If the model has requested a specific simplification interval, though, then I don't think SLiM should simplify behind the user's back; better to fail, actually, in my opinion, so that the user can decide whether to change the simplification interval, or to do something else. You say "this should be part of the automatic simplification interval calculation", so perhaps we're agreed on this?

    No urgency on this, right? Since one can always just set an explicit interval?

  2. petrelharp commented on May 14, 2020

    @petrelharp
    CollaboratorAuthor

    Yes, that's what I meant. And I agree, it's not urgent, although I'm sure others will run into this at first inscrutible problem soon.

  3. bhaller commented on May 14, 2020

    @bhaller
    Contributor

    OK. I'm not planning to roll another SLiM release for a while, now that 3.4 is out the door, unless something urgent forces me to.

  4. bhaller commented on Aug 30, 2020

    @bhaller
    Contributor

    This should roll in SLiM 3.5. The relevant code is in SLiMSim::CheckAutoSimplification(). I suppose we want to:

    1. Remember with a new bool flag whether initializeTreeSeq() was called with the default simplification options (ratio and interval both NULL), and
    2. In SLiMSim::CheckAutoSimplification(), if we're in the default mode according to that flag, then check the new heuristic and force a simplify if the tables are above some threshold size.

    Maybe with this change we can also lengthen the default interval somewhat, as it tends to over-simplify for many models, making performance poor. Right now the default is a ratio of 10, and an initial interval of 20; I'd propose extending the initial interval to 50. A lot of people use the default settings, and their performance is poor, and they don't even realize there are options here to customize that could radically improve performance. If forcing a simplify when the tables are too big makes us less likely to overflow, then the default could simplify less often, presumably.

    The code in SLiMSim::CheckAutoSimplification() expresses how the "table size" is currently calculated; it's just the sum of the lengths of the node, edge, site, and mutation tables. I'm not sure that is a very good heuristic. @petrelharp, thoughts?

  5. bhaller commented on Aug 30, 2020

    @bhaller
    Contributor

    I've actually been wondering whether it might be a good idea to emit a warning of some kind when initializeTreeSeq() is called without any ratio/interval (i.e., taking the default simplification behavior), to warn the user that this is likely to be radically sub-optimal...?

  6. petrelharp commented on Aug 31, 2020

    @petrelharp
    CollaboratorAuthor

    Well, gee, how about we just check if the current number of rows in the node table is within, say, (6x the total current population size) of the maximum, and if so, simplify? We should probably do the same for the mutations as well. That way there'd be no troubles unless the population tripled in one generation.

    it might be a good idea to emit a warning of some kind when initializeTreeSeq() is called without any ratio/interval

    I don't think we should do this without providing concrete guidance on how to set it... and if we have better guidance on this, we should implment it, I guess? I support changing the default ratio. Maybe we should run some experiments to figure this out.

  7. added
    trees
    on Jun 23, 2021
  8. bhaller commented on Jul 26, 2023

    @bhaller
    Contributor

    @petrelharp The script in #62 no longer overflows the tables. I guess this is a consequence of the shift in tskit from 32-bit to 64-bit in some places; that script was overflowing the metadata (not the number of nodes), and now the metadata size is kept in 64-bit. I suspect the model @mufernando was running that caused an overflow was also a metadata overflow.

    So. Is this issue still a problem at all? Overflowing the metadata was the easy way to produce a table overflow, and now it doesn't. IIRC we all discussed it and decided that actually overflowing the node/mutation tables themselves would be a lot harder – would require a model size that presently seems unreasonably large – and so the tskit folks did not increase those limits from 32-bit to 64-bit (i.e., continued using tsk_id_t for them).

    Here is a model that does overflow the tsk_id_t limit, by pushing nodes into the node table endlessly:

    initialize() {
    	initializeTreeSeq(simplificationRatio=INF);
    	initializeMutationRate(0);
    	initializeMutationType("m1", 0.5, "f", 0.0);
    	initializeGenomicElementType("g1", m1, 1.0);
    	initializeGenomicElement(g1, 0, 0);
    	initializeRecombinationRate(0.0);
    }
    1 early() {
    	sim.addSubpop("p1", 1000000);
    }
    1e9 late() {
    }
    

    I'm running it now. But this is obviously a pretty unreasonable model; it's making a million new individuals per tick, with no genetics or anything (to keep the runtime minimal), and it's turning off simplification completely. Even at that extreme, it overflows after tick 1000:

    tick 1073 : tables_.nodes.num_rows == 2146000000 (49%)
    Error:tsk_node_table_add_row: Table too large; cannot allocate more than 2**31 rows. (TSK_ERR_TABLE_OVERFLOW)

    Turns out the limit is 2^31, not 2^32, not sure why. The table size for the node table is kept in 64-bit, BTW, but the node ids are 32-bit; that's the reason for the overflow, I guess. Anyhow, any model using auto-simplification would have simplified long before reaching this point, it seems to me, and above we were only discussing forcing a simplify when the tables got large in the auto-simplification case, not when people have defined a custom simplification schedule.

    So I think if there is any bug here worth fixing at all, it is that perhaps the tskit error could be more informative for end users; it could add "You may wish to simplify the tree sequence more frequently" or something like that, to clue in the clueless. :-> But I'm not sure even that is needed; since the overflow is really only attainable if the user has set a custom simplification schedule, they will presumably know what the error message means.

    Closing for now, but if you disagree, then of course re-open and comment. :->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementtrees

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions