Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using tree sequence recording in conditional simulations #347

Closed
olivia-johnson opened this issue Aug 26, 2022 · 1 comment
Closed
Labels
bug priority trees related to tree-seq, tskit, etc.

Comments

@olivia-johnson
Copy link

Hi everyone,

Following the new update, I have found that my conditional simulation that includes tree sequence recording returns an error when it restarts if the condition could not be met. The error is "(Species::InstantiateSLiMObjectsFromTables): (internal error) remembered_genomes is not empty" and it invalidates the simulation. I think I need to clear the individuals from the memory when the simulation restarts, but I'm not sure how to do that.

I have adapted recipe 9.2 such that it returns the same error (see minimal example below).

Thanks so much for your help!
Olivia

// Minimal example: Conditional simulation with tree sequence recording



initialize() {

   initializeMutationRate(0);

   initializeMutationType("m1", 0.0, "f", 0.0);// introduced mutation

   initializeGenomicElementType("g1", m1, 1.0);

   initializeGenomicElement(g1, 0, 99999);

   initializeRecombinationRate(1e-8);

   initializeTreeSeq();

}

1 early() {

   // save this run's identifier, used to save and restore

   defineConstant("simID", getSeed());

   sim.addSubpop("p1", 500);

}

1000 late() {

   // save the state of the simulation

   sim.treeSeqOutput(tempdir() + "slim_" + simID + ".trees");

   // introduce the sweep mutation

   target = sample(p1.genomes, 1);

   target.addNewDrawnMutation(m1, 10000);

}

1000:100000 late() {

   rInd= sample(p1.individuals, 10);

   sim.treeSeqRememberIndividuals(rInd);

   if (sim.countOfMutationsOfType(m1) == 0)

   {
       fixed = (sum(sim.substitutions.mutationType == m1) == 1);

       if (fixed){

           cat(simID + ": FIXED\n");

           sim.simulationFinished();
       }

       else

       {
           cat(simID + ": LOST at " +sim.cycle+" - RESTARTING\n");

           // go back to tick 1000

           sim.readFromPopulationFile(tempdir() + "slim_" + simID + ".trees");

           // start a newly seeded run

           setSeed(rdunif(1, 0, asInteger(2^62) - 1));

           // re-introduce the sweep mutation

           target = sample(p1.genomes, 1);

           target.addNewDrawnMutation(m1, 10000);
       }

   }

}
@bhaller
Copy link
Contributor

bhaller commented Aug 26, 2022

Hi @olivia-johnson. Thanks very much for the bug report. I'll look into it as soon as I can, perhaps later today. I think it will be an easy fix; it's just a case that we haven't tested, and so it slipped through the cracks. (@petrelharp perhaps it would be good for you and I to both add a test that hits this case, in our respective testing suites!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug priority trees related to tree-seq, tskit, etc.
Projects
None yet
Development

No branches or pull requests

2 participants