Skip to content

Commit

Permalink
Merge pull request #85 from jakobj/maint/move-pop-test
Browse files Browse the repository at this point in the history
Move test from test_hl_api to correct location in test_population
  • Loading branch information
mschmidt87 authored Apr 25, 2020
2 parents ceace46 + 9f6c12e commit 8de42a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
33 changes: 0 additions & 33 deletions test/test_hl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,6 @@ def test_parallel_population():
assert fitness_per_n_processes[0] == pytest.approx(fitness_per_n_processes[2])


def test_pop_uses_own_rng():
"""Test independence of Population on global numpy rng.
"""

population_params = {"n_parents": 5, "mutation_rate": 0.05, "seed": SEED}

genome_params = {
"n_inputs": 2,
"n_outputs": 1,
"n_columns": 3,
"n_rows": 3,
"levels_back": 2,
"primitives": [gp.Add, gp.Sub, gp.Mul, gp.ConstantFloat],
}

pop = gp.Population(**population_params, genome_params=genome_params)

np.random.seed(SEED)

pop._generate_random_parent_population()
parents_0 = list(pop._parents)

np.random.seed(SEED)

pop._generate_random_parent_population()
parents_1 = list(pop._parents)

# since Population does not depend on global rng seed, we
# expect different individuals in the two populations
for p_0, p_1 in zip(parents_0, parents_1):
assert p_0.genome.dna != p_1.genome.dna


def test_evolve_two_expressions():
"""Test evolution of multiple expressions simultaneously.
"""
Expand Down
33 changes: 33 additions & 0 deletions test/test_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,36 @@ def test_fitness_parents(population_params, genome_params):
parent.fitness = fitness

assert np.all(pop.fitness_parents() == pytest.approx(fitness_values))


def test_pop_uses_own_rng(rng_seed):
"""Test independence of Population on global numpy rng.
"""

population_params = {"n_parents": 5, "mutation_rate": 0.05, "seed": rng_seed}

genome_params = {
"n_inputs": 2,
"n_outputs": 1,
"n_columns": 3,
"n_rows": 3,
"levels_back": 2,
"primitives": [gp.Add, gp.Sub, gp.Mul, gp.ConstantFloat],
}

pop = gp.Population(**population_params, genome_params=genome_params)

np.random.seed(rng_seed)

pop._generate_random_parent_population()
parents_0 = list(pop._parents)

np.random.seed(rng_seed)

pop._generate_random_parent_population()
parents_1 = list(pop._parents)

# since Population does not depend on global rng seed, we
# expect different individuals in the two populations
for p_0, p_1 in zip(parents_0, parents_1):
assert p_0.genome.dna != p_1.genome.dna

0 comments on commit 8de42a3

Please sign in to comment.