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

Add simple tests of new back end using island model. #1073

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions cpptests/forward_demes_graph_fixtures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ time_units: generations
- start_size: 200
)";

const char* two_deme_perpetual_island_model = R"(
time_units: generations
demes:
- name: A
epochs:
- start_size: 100
- name: B
epochs:
- start_size: 100
migrations:
- demes: [A, B]
rate: 1e-1
)";

SingleDemeModel::SingleDemeModel() : yaml(single_deme_model)
{
}

TwoDemePerpetualIslandModel::TwoDemePerpetualIslandModel()
: yaml(two_deme_perpetual_island_model)
{
}
6 changes: 6 additions & 0 deletions cpptests/forward_demes_graph_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ struct SingleDemeModel
SingleDemeModel();
};

struct TwoDemePerpetualIslandModel
{
std::string yaml;
TwoDemePerpetualIslandModel();
};


83 changes: 82 additions & 1 deletion cpptests/test_evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOOST_AUTO_TEST_SUITE(test_evolvets)
* - [X] simlen > model time in graph
* - [X] initial population config not compatible
* with state of parental demes for single deme models.
* - [] initial population config not compatible
* - [X] initial population config not compatible
* with state of parental demes for multi deme models.
* - [] simlen < model time in graph,
* but we keep simulating until we are done.
Expand Down Expand Up @@ -151,6 +151,31 @@ BOOST_FIXTURE_TEST_CASE(test_basic_api_coherence, common_setup)
BOOST_REQUIRE_EQUAL(pop.generation, 10);
}

BOOST_FIXTURE_TEST_CASE(test_basic_api_coherence_two_deme_perpetual_island_model,
common_setup)
{
auto model = TwoDemePerpetualIslandModel();

// over-write the fixture so that the initial pop is okay
pop = fwdpy11::DiploidPopulation({100, 100}, 10.0);
fwdpy11_core::ForwardDemesGraph forward_demes_graph(model.yaml, 10);

// TODO: if we put long run times in here, we get exceptions
// from the ForwardDemesGraph back end.
evolve_with_tree_sequences_refactor(rng, pop, recorder, 10, forward_demes_graph, 10,
0., 0., mregions, recregions, gvalue_ptrs,
sample_recorder_callback, stopping_criterion,
post_simplification_recorder, options);
BOOST_REQUIRE_EQUAL(pop.generation, 10);
std::vector<unsigned> ndemes{0, 0};
for (const auto& dip : pop.diploid_metadata)
{
ndemes[dip.deme]++;
}
BOOST_REQUIRE_EQUAL(ndemes[0], 100);
BOOST_REQUIRE_EQUAL(ndemes[1], 100);
}

BOOST_FIXTURE_TEST_CASE(test_simlen_longer_than_model_length, common_setup)
{
auto model = SingleDemeModel();
Expand Down Expand Up @@ -221,6 +246,62 @@ BOOST_FIXTURE_TEST_CASE(test_initial_pop_size_invalid, common_setup)
BOOST_REQUIRE_EQUAL(pop.generation, 0);
}

BOOST_FIXTURE_TEST_CASE(test_initial_pop_size_invalid_island_model, common_setup)
{
{
// The demes model specifies N = [100, 100].
// Here, we will start with N for one deme
// This is a hard error!
// We test values ~100 because TDD found cases of memory errors
// when N >> the correct N but things can pass when N =~ the
// correct N. Gotta love UB :).
std::vector<std::uint32_t> initial_popsizes{50, 99, 101, 200};
for (auto initial_n : initial_popsizes)
{
// reset the fixture
pop = fwdpy11::DiploidPopulation(initial_n, 10.0);
auto model = TwoDemePerpetualIslandModel();
fwdpy11_core::ForwardDemesGraph forward_demes_graph(model.yaml, 10);

BOOST_CHECK_THROW(
{
evolve_with_tree_sequences_refactor(
rng, pop, recorder, 10, forward_demes_graph, 10, 0., 0.,
mregions, recregions, gvalue_ptrs, sample_recorder_callback,
stopping_criterion, post_simplification_recorder, options);
},
// TODO: is this the type that we want?
fwdpy11::discrete_demography::DemographyError);
}
// pop hasn't evolved!
BOOST_REQUIRE_EQUAL(pop.generation, 0);
}

{
std::vector<std::vector<std::uint32_t>> initial_popsizes{
{100, 0}, {0, 100}, {10, 100}, {100, 99, 1}};
for (auto initial_n : initial_popsizes)
{
// reset the fixture
pop = fwdpy11::DiploidPopulation(initial_n, 10.0);
auto model = TwoDemePerpetualIslandModel();
fwdpy11_core::ForwardDemesGraph forward_demes_graph(model.yaml, 10);

BOOST_CHECK_THROW(
{
evolve_with_tree_sequences_refactor(
rng, pop, recorder, 10, forward_demes_graph, 10, 0., 0.,
mregions, recregions, gvalue_ptrs, sample_recorder_callback,
stopping_criterion, post_simplification_recorder, options);
},
// TODO: is this the type that we want?
fwdpy11::discrete_demography::DemographyError);
}
// pop hasn't evolved!
BOOST_REQUIRE_EQUAL(pop.generation, 0);
}
}

BOOST_FIXTURE_TEST_CASE(test_generation_time_past_end_of_model, common_setup)
{
auto model = SingleDemeModel();
Expand Down
1 change: 1 addition & 0 deletions doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Back end changes
PR {pr}`1070`.
PR {pr}`1071`.
PR {pr}`1072`.
PR {pr}`1073`.

## 0.19.3

Expand Down