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

Avoid repeated resetting of spatial bounds (closes #147) #148

Merged
merged 6 commits into from Jan 16, 2024
Merged

Conversation

bodkan
Copy link
Owner

@bodkan bodkan commented Jan 16, 2024

As discussed in #147, this is a fix for a backwards incompatibility change / bugfix which caused issues with slendr's built-in SLiM script because of repeated (and unnecessary) call to setSpatialBounds() upon each map update. Because the dimensions of raster maps of slendr models are always the same for all populations, this call can happen upon first creating a population and not after.

Minimum reproducible example:

devtools::load_all()
init_env()

# create an example map
map <- world(xrange = c(-25, 55), yrange = c(-32, 35), crs = 4326)

# create a single population spread all over the map
pop <- population("pop", time = 1, N = 2000, map = map)

# compile a single-population model
model <- compile_model(
  populations = pop, generation_time = 30, simulation_length = 1000,
  resolution = 1, competition = 1, dispersal = 1, mating = 1
)

# run the model through SLiM, return a tree sequence
ts <- slim(model, sequence_length = 1000, recombination_rate = 0) # <=== crashes in SLiM 4.1, but works fine with 4.0.1

Crash log:

// Initial random seed:                                                                          
7837909936800388019

// RunInitializeCallbacks():
SEED: 7837909936800388019
initializeSLiMOptions(keepPedigrees = T, dimensionality = 'xy');
initializeInteractionType(0, "xy", reciprocal=T, maxDistance=1);
initializeInteractionType(1, "xy", reciprocal=T, maxDistance=1);
initializeTreeSeq();
initializeMutationType(0, 0.5, "f", 0);
initializeGenomicElementType(1, m0, 1);
initializeGenomicElement(g1, 0, 999);
initializeMutationRate(0);
initializeRecombinationRate(0);

// Starting run at tick <start>:
1 

Generation 1: starting the simulation
Generation 1: creating pop(p0)
Generation 1: updating map for pop(p0)
ERROR (Subpopulation::ExecuteMethod_setSpatialBounds): setSpatialBounds() new spatial bounds are not compatible with an attached map named 'world'; use removeSpatialMap() to remove incompatible spatial maps before changing the spatial bounds.  (This enforces internal consistency and avoids accidentally stretching a map to new spatial bounds.)

Error on script line 222, character 12:

        pop.setSpatialBounds(c(0.0, 0.0, asFloat(WIDTH) - 1, asFloat(HEIGHT) - 1));
            ^^^^^^^^^^^^^^^^
Error: Unfortunately SLiM terminated before a tree sequence was saved.
See the above for an indication of where things could have gone wrong.

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (04c0e3c) 89.95% compared to head (80f13c2) 89.95%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #148   +/-   ##
=======================================
  Coverage   89.95%   89.95%           
=======================================
  Files           8        8           
  Lines        3037     3037           
=======================================
  Hits         2732     2732           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bodkan bodkan merged commit 0bc83ab into main Jan 16, 2024
8 checks passed
@bodkan bodkan deleted the slim41-update branch January 16, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant