Hi Laurent,
"Population size going to zero due to negative exponential growth causes problems. It is a feature, not a bug..." Sure, but my understanding is that the way 3PopExpBot20Mb.tpl is coded it was supposed to have stopped negative exponential growth in demes 1 and 2 at TDIV before demes ever reached a size of 0. This is because R1 is coded such that there must always be at least 10 and no more than 10000 individuals in these demes at TDIV. To be sure, I also bounded NPOPOOA in the est file.
Here are the relevant lines from the est file:
1 NPOPOOA unif 10 10000 bounded output
0 RATIO_OOA_EA = NPOPOOA/2000000 hide
0 RTEA = log(RATIO_OOA_EA) hide
0 R1 = RTEA/TDIV hide
The 3PopExpBot20Mb.tpl file then sets growth rate to 0 at TDIV:
TDIV 1 1 0 1 0 1 //Set growth rate to 0 in deme 1
TDIV 2 2 0 1 0 1 //Set growth rate to 0 in deme 2
With these combinations of settings I do not see how population size could be going to zero (or infinity) due to negative (or positive) exponential growth. Nevertheless, the example consistently crashes on a subset of runs with the error "free(): invalid next size (fast)".
Ivan suggested killing the demes explicitly. This should not be necessary in 3PopExpBot20Mb because there is no migration involving demes 1 and 2 earlier than TDIV. Nevertheless, to be sure, I added the following two kill lines as events to the tpl file:
TDIV 1 1 0 0 0 1 //kill deme 1
TDIV 2 2 0 0 0 1 //kill deme 2
I then ran the example 50 times from different starting parameters and a small subset of the runs crashed with the "free(): invalid next size (fast)". Is this the expected behaviour of the 3PopExpBot20Mb example? In the past I have always considered a model to be poorly coded if a subset of runs generated errors.
For reference here is the tpl file with Ivan's suggested kill lines:
#######################################################################################
//Parameters for the coalescence simulation program : fastsimcoal.exe
3 samples to simulate :
//Population effective sizes (number of genes)
NPOPAF
2000000
2000000
//Samples sizes and samples age
20
20
20
//Growth rates : negative growth implies population expansion
0
R1
R1
//Number of migration matrices : 0 implies no migration between demes
2
//Migration matrix 0
0.0000 0.0000 0.0000
0.0000 0.0000 MIG
0.0000 MIG 0.0000
//Migration matrix 1
0 0 0
0 0 0
0 0 0
//historical event: time, source, sink, migrants, new deme size, new growth rate, migration matrix index
10 historical event
TDIV 2 0 1 1 0 1
TDIV 1 1 0 1 0 1 //Set growth rate to 0 in deme 1
TDIV 2 2 0 1 0 1 //Set growth rate to 0 in deme 2
TDIV 1 1 0 0 0 1 //kill deme 1 which should not be necessary in this example given migration is 0
TDIV 2 2 0 0 0 1 //kill deme 2 which should not be necessary in this example given migration is 0
TBOT 0 0 0 RES1 0 1
TENDBOT 0 0 0 RES2 0 1
TENDBOT 1 1 0 1 0 1
TENDBOT 2 2 0 1 0 1
//Number of independent loci [chromosome]
1 0
//Per chromosome: Number of contiguous linkage Block: a block is a set of contiguous loci
1
//per Block:data type, number of loci, per generation recombination and mutation rates and optional parameters
FREQ 1 0 2.5e-8 OUTEXP
#################################################################################################
Here is the .est file with the bounded option added
// Priors and rules file
// *********************
[PARAMETERS]
//#isInt? #name #dist.#min #max
//all Ns are in number of haploid individuals
1 ANCSIZE unif 1000 100000 bounded output
1 NBOT unif 10 2000 bounded output
1 NPOPAF unif 1000 100000 bounded output
1 NPOPOOA unif 10 10000 bounded output
1 TDIV unif 10 10000 bounded output
1 TPLUSDIV unif 10 10000 bounded hide
0 MIG logunif 1e-5 1e-2 bounded output
[RULES]
[COMPLEX PARAMETERS]
1 TBOT = TDIV+TPLUSDIV output
0 RATIO_OOA_EA = NPOPOOA/2000000 hide
0 RTEA = log(RATIO_OOA_EA) hide
0 R1 = RTEA/TDIV hide
1 TENDBOT = TBOT+500 hide
0 RES1 = NBOT/NPOPAF hide
0 RES2 = ANCSIZE/NBOT hide
#################################################################################################