Closed bodkan closed 11 months ago
So I think I fixed it?
In the end it doesn't seem like dramatic changes to the internals were needed. Turns out that if an range expansion/shrinking is scheduled with locked size change, the size change progression can be used to determine the model time direction, skipping the apparent inconsistency caused by the range change and population size events. What I did was to simply skip the range expansion event from the loop used to determine time direction if the range change is associated with population size change. If it isn't, then the code works just as before. The change in the code can be found here.
The tests and examples run as before, so hopefully I didn't break anything else in the process.
Consider this chunk of code which determines the spatio-temporal dynamics of population expansion:
This creates the following object -- no issues there:
However, when
lock = TRUE
is set inexpand_range()
(an option which allows automatic adjustment of population sizes to maintain +/- same densities), this causes an issue with the direction of times of individual events:Setting
lock = TRUE
simply auto-schedules normalresize()
events, which seems fine, except that the orders of times of events is then no longer monotonic: 13000, 10000, 7000, 9850, 9700...This shouldn't be a problem by itself, except that slendr's internal checks of time direction require that times of subsequent events are monotonic. That's how we can let the users specify time units in whatever direction they want -- slendr can always translate to forward-ticks SLiM time or backwards-generations msprime time in a "smart way".
This should be fixable, but it will probably make the time-direction checking code even more complex. 🙄
This honestly isn't a backbreaking bug, just a small annoyance.
For completeness, here are the spatial map components needed for the code above to work: