Skip to content

Commit

Permalink
Keep track of whether demographic_model_state pointer was null
Browse files Browse the repository at this point in the history
at start of simulation.  If not, then we do NOT call the "model
updating" code path prior to entering the main loop.

CANDIDATE fix for #775
  • Loading branch information
molpopgen committed Jun 16, 2021
1 parent 1ad0d53 commit d7585f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,19 @@ namespace fwdpy11
}
};

/// model_needs_update added in 0.16.0
/// in relation to GitHub issue 775
template <typename METADATATYPE>
inline demographic_model_state_pointer
initialize_model_state(std::uint32_t generation,
const std::vector<METADATATYPE>& metadata,
DiscreteDemography& demography)
DiscreteDemography& demography, bool* model_needs_update)
{
// "steal" pointer from input
auto rv = demography.get_model_state();

*model_needs_update = (rv == nullptr);

if (rv == nullptr || generation == 0)
// If there is no state, then we need to make
// one. If there is a state, but the generation
Expand All @@ -121,6 +125,7 @@ namespace fwdpy11
{
demography.update_event_times(generation);
rv.reset(new demographic_model_state(metadata, demography));
*model_needs_update = true;
}
return rv;
}
Expand Down
15 changes: 11 additions & 4 deletions fwdpy11/src/evolve_population/evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ evolve_with_tree_sequences(
}

// Set up discrete demography types. New in 0.6.0
auto current_demographic_state = ddemog::initialize_model_state(
pop.generation, pop.diploid_metadata, demography);
/// model_needs_update added in 0.16.0
/// in relation to GitHub issue 775
bool demographic_model_needs_update = true;
auto current_demographic_state
= ddemog::initialize_model_state(pop.generation, pop.diploid_metadata,
demography, &demographic_model_needs_update);
if (gvalue_pointers.genetic_values.size()
> static_cast<std::size_t>(current_demographic_state->maxdemes))
{
Expand Down Expand Up @@ -285,8 +289,11 @@ evolve_with_tree_sequences(
record_genotype_matrix);
pop.genetic_value_matrix.swap(new_diploid_gvalues);
pop.diploid_metadata.swap(offspring_metadata);
ddemog::update_demography_manager(rng, pop.generation, pop.diploid_metadata,
demography, *current_demographic_state);
if (demographic_model_needs_update == true)
{
ddemog::update_demography_manager(rng, pop.generation, pop.diploid_metadata,
demography, *current_demographic_state);
}
if (current_demographic_state->will_go_globally_extinct() == true)
{
std::ostringstream o;
Expand Down

0 comments on commit d7585f2

Please sign in to comment.