示例#1
0
    def test_simple_back_and_forth_copy(self):
        d = fwdpy11.DiscreteDemography([
            fwdpy11.copy_individuals(1, 0, 1, 0.5),
            fwdpy11.copy_individuals(2, 1, 0, 1.)
        ])

        ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 3)
        md = np.array(self.pop.diploid_metadata)
        deme_counts = np.unique(md['deme'], return_counts=True)
        expected = {0: 150, 1: 50}
        self.assertEqual(len(deme_counts[0]), len(expected))
        for i in range(len(deme_counts[0])):
            self.assertEqual(deme_counts[1][i], expected[i])
示例#2
0
    def test_copies_happen_before_moves(self):
        """
        This is a more complex test.
        In the same generation:
        1. All individuals are copied from deme 0 to deme 1.
        2. 50% of deme 0 moves to deme 2.
        3. 50% of deme 0 moves to deme 3.

        This, at the end, the size of deme 1 should be
        the initial size and the size of demes 2 and 3
        should be 0.5*initial size
        """
        m = [
            fwdpy11.move_individuals(0, 0, 3, 0.5),
            fwdpy11.copy_individuals(0, 0, 1, 1),
            fwdpy11.move_individuals(0, 0, 2, 0.5)
        ]
        d = fwdpy11.DiscreteDemography(m)
        N0 = self.pop.N
        ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 1)
        md = np.array(self.pop.diploid_metadata)
        expected = {0: 0, 1: N0, 2: N0 // 2, 3: N0 // 2}
        dc = np.unique(md['deme'], return_counts=True)
        for i, j in zip(dc[0], dc[1]):
            self.assertEqual(expected[i], j)
示例#3
0
 def test_move_too_many_individuals_from_same_deme_with_copy_in_middle(
         self):
     # Attempt to move 125% of deme 0
     # This is a test that input data get sorted so
     # that copies are before moves, which will allow
     # detecting the invalid cumulative move attempt
     m = [
         fwdpy11.move_individuals(0, 0, 1, 0.5),
         fwdpy11.copy_individuals(0, 0, 1, 0.5),
         fwdpy11.move_individuals(0, 0, 2, 0.75)
     ]
     with self.assertRaises(ValueError):
         fwdpy11.DiscreteDemography(m)
示例#4
0
 def test_init_with_one_mass_move_and_one_mass_copy_same_generation(self):
     # Internally, the input data will get sorted
     # so that copies happen before moves.
     m = [
         fwdpy11.move_individuals(0, 0, 1, 0.5),
         fwdpy11.copy_individuals(0, 0, 1, 0.5)
     ]
     try:
         d = fwdpy11.DiscreteDemography(m)
         self.assertEqual(d.mass_migrations[0].move_individuals, False)
         self.assertEqual(d.mass_migrations[1].move_individuals, True)
     except:  # NOQA
         self.fail("unexpected exception")
示例#5
0
    def test_copy(self):
        m = fwdpy11.copy_individuals(0, 2, 1, 0.1)
        self.assertEqual(m.when, 0)
        self.assertEqual(m.source, 2)
        self.assertEqual(m.destination, 1)
        self.assertEqual(m.number, 0)
        self.assertEqual(m.fraction, 0.1)
        self.assertEqual(m.move_individuals, False)

        mp = pickle.dumps(m, -1)
        ump = pickle.loads(mp)
        self.assertEqual(ump.when, 0)
        self.assertEqual(ump.source, 2)
        self.assertEqual(ump.destination, 1)
        self.assertEqual(ump.number, 0)
        self.assertEqual(ump.fraction, 0.1)
        self.assertEqual(ump.move_individuals, False)
        self.assertTrue(m == ump)
示例#6
0
 def test_simple_copies_from_multiple_demes(self):
     # Set 1/2 the population to start in deme 1:
     md = np.array(self.pop.diploid_metadata, copy=False)
     md['deme'][self.pop.N // 2:] = 1
     # In generation 0, we move 1/2 of deme 1 to
     # deme 2, which creates a new deme:
     d = fwdpy11.DiscreteDemography(
         [fwdpy11.copy_individuals(0, 1, 2, 0.5)])
     # Evolve for one generation:
     ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 1)
     # We now expect 50, 50, and 25 individuals in
     # demes 0, 1, and 2
     md = np.array(self.pop.diploid_metadata)
     deme_counts = np.unique(md['deme'], return_counts=True)
     expected = {0: 50, 1: 50, 2: 25}
     self.assertEqual(len(deme_counts[0]), len(expected))
     for i in range(len(deme_counts[0])):
         self.assertEqual(deme_counts[1][i], expected[i])
示例#7
0
 def test_init_with_two_mass_copies_same_generation(self):
     m = [fwdpy11.copy_individuals(0, 0, 1, 0.5)] * 2
     with self.assertRaises(ValueError):
         fwdpy11.DiscreteDemography(m)