Skip to content

Commit

Permalink
Appease circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrrock2 committed Apr 30, 2024
1 parent be82f60 commit d895b7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
7 changes: 5 additions & 2 deletions tests/optimization/test_gingleator.py
Expand Up @@ -53,6 +53,7 @@ def gingleator_test_partition(four_by_five_grid_for_opt):


def test_ginglator_needs_min_perc_or_min_pop_col(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -90,6 +91,7 @@ def test_ginglator_needs_min_perc_or_min_pop_col(four_by_five_grid_for_opt):


def test_ginglator_warns_if_min_perc_and_min_pop_col_set(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -132,7 +134,8 @@ def test_ginglator_warns_if_min_perc_and_min_pop_col_set(four_by_five_grid_for_o
)


def test_ginglator_finds_best_partition(four_by_five_grid_for_opt):
def test_gingleator_finds_best_partition(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -164,7 +167,7 @@ def test_ginglator_finds_best_partition(four_by_five_grid_for_opt):
score_function=Gingleator.num_opportunity_dists,
)

total_steps = 1000
total_steps = 5000
burst_length = 10

max_scores_sb = np.zeros(total_steps)
Expand Down
27 changes: 21 additions & 6 deletions tests/optimization/test_single_metric.py
Expand Up @@ -20,6 +20,7 @@ def simple_cut_edge_count(partition):


def test_single_metric_sb_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -66,6 +67,7 @@ def test_single_metric_sb_attains_min_quickly(four_by_five_grid_for_opt):


def test_single_metric_tilted_sb_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -113,6 +115,7 @@ def test_single_metric_tilted_sb_attains_min_quickly(four_by_five_grid_for_opt):


def test_single_metric_variable_len_sb_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -163,6 +166,7 @@ def test_single_metric_variable_len_sb_attains_min_quickly(four_by_five_grid_for


def test_single_metric_sa_jumpcycle_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -209,6 +213,7 @@ def test_single_metric_sa_jumpcycle_attains_min_quickly(four_by_five_grid_for_op


def test_single_metric_sa_lincycle_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -256,6 +261,7 @@ def test_single_metric_sa_lincycle_attains_min_quickly(four_by_five_grid_for_opt
def test_single_metric_sa_linear_jumpcycle_attains_min_quickly(
four_by_five_grid_for_opt,
):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -301,6 +307,7 @@ def test_single_metric_sa_linear_jumpcycle_attains_min_quickly(


def test_single_metric_sa_logitcycle_attains_min_quickly(four_by_five_grid_for_opt):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -348,6 +355,7 @@ def test_single_metric_sa_logitcycle_attains_min_quickly(four_by_five_grid_for_o
def test_single_metric_sa_logit_jumpcycle_attains_min_quickly(
four_by_five_grid_for_opt,
):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -400,6 +408,7 @@ def test_single_metric_sa_logit_jumpcycle_attains_min_quickly(
def test_single_metric_tilted_runs_attains_min_quickly_with_p_eq_0p1(
four_by_five_grid_for_opt,
):
random.seed(2024)
initial_partition = Partition.from_random_assignment(
graph=four_by_five_grid_for_opt,
n_parts=4,
Expand Down Expand Up @@ -446,6 +455,8 @@ def test_single_metric_tilted_runs_attains_min_quickly_with_p_eq_0p1(


def test_single_metric_sb_finds_hard_max(four_by_five_grid_for_opt):
random.seed(2024)

def opt_fn(partition):
mx = 10
count = sum(1 for x in partition["opt_value_sum"].values() if x == mx)
Expand Down Expand Up @@ -494,6 +505,8 @@ def opt_fn(partition):


def test_single_metric_sa_finds_hard_max(four_by_five_grid_for_opt):
random.seed(2024)

def opt_fn(partition):
mx = 10
count = sum(1 for x in partition["opt_value_sum"].values() if x == mx)
Expand Down Expand Up @@ -525,13 +538,13 @@ def opt_fn(partition):
maximize=True,
)

total_steps = 10000
total_steps = 20000

max_scores_anneal = np.zeros(total_steps)
for i, part in enumerate(
optimizer.simulated_annealing(
total_steps,
optimizer.linear_jumpcycle_beta_function(10, 10, 10),
optimizer.linear_jumpcycle_beta_function(100, 100, 100),
beta_magnitude=1,
)
):
Expand All @@ -541,6 +554,8 @@ def opt_fn(partition):


def test_single_metric_tilted_runs_finds_hard_max(four_by_five_grid_for_opt):
random.seed(2024)

def opt_fn(partition):
mx = 10
count = sum(1 for x in partition["opt_value_sum"].values() if x == mx)
Expand Down Expand Up @@ -572,12 +587,12 @@ def opt_fn(partition):
maximize=True,
)

total_steps = 5000
total_steps = 10000

min_scores_tilt = np.zeros(total_steps)
max_scores_tilt = np.zeros(total_steps)
for i, part in enumerate(
optimizer.tilted_run(num_steps=total_steps, p=0.1, with_progress_bar=True)
):
min_scores_tilt[i] = optimizer.best_score
max_scores_tilt[i] = optimizer.best_score

assert np.max(min_scores_tilt) == 2
assert np.max(max_scores_tilt) == 2
2 changes: 1 addition & 1 deletion tests/test_reproducibility.py
Expand Up @@ -62,7 +62,7 @@ def test_repeatable(three_by_three_grid):
assert flips == expected_flips


# @pytest.mark.slow
@pytest.mark.slow
def test_pa_freeze():
from gerrychain import (
GeographicPartition,
Expand Down
5 changes: 3 additions & 2 deletions tests/updaters/test_cut_edges.py
Expand Up @@ -4,7 +4,7 @@

from gerrychain import MarkovChain, Partition, proposals
from gerrychain.accept import always_accept
from gerrychain.constraints import no_vanishing_districts, contiguous
from gerrychain.constraints import no_vanishing_districts, single_flip_contiguous
from gerrychain.grid import Grid
from gerrychain.updaters import cut_edges, cut_edges_by_part
import random
Expand Down Expand Up @@ -142,11 +142,12 @@ def test_implementation_of_cut_edges_matches_naive_method(three_by_three_grid):
],
)
def test_cut_edges_matches_naive_cut_edges_at_every_step(proposal, number_of_steps):
random.seed(2024)
partition = Grid((10, 10), with_diagonals=True)

chain = MarkovChain(
proposal,
[contiguous, no_vanishing_districts],
[single_flip_contiguous, no_vanishing_districts],
always_accept,
partition,
number_of_steps,
Expand Down

0 comments on commit d895b7a

Please sign in to comment.