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

recursive_seed_part_inner does not respect provided method #414

Closed
mkarrmann opened this issue Oct 3, 2023 · 0 comments · Fixed by #415
Closed

recursive_seed_part_inner does not respect provided method #414

mkarrmann opened this issue Oct 3, 2023 · 0 comments · Fixed by #415

Comments

@mkarrmann
Copy link
Contributor

mkarrmann commented Oct 3, 2023

recursive_seed_part and recursive_seed_part_inner accept a parameter method which is supposed to be the funciontion used to generate a single district at a give step. However, this method is not passed to recursive_seed_part_inner's recursive calls to itself, meaning it is only used to generate the first district, but not any subsequent one.

It is easy to reproduce and observe this bug by calling recursive_seed_part with a method which has a noticeable side-effect (e.g. logging), and then noticing that that side-effect only occurs once. However, it probably easy to just eye-ball the code to see the problem:

def recursive_seed_part_inner(
graph: nx.Graph,
num_dists: int,
pop_target: Union[float, int],
pop_col: str,
epsilon: float,
method: Callable = partial(bipartition_tree, max_attempts=10000),
node_repeats: int = 1,
n: Optional[int] = None,
ceil: None = None,
) -> List[Set]:

nodes = method(
graph.subgraph(remaining_nodes),
pop_col=pop_col,
pop_target=pop_target,
epsilon=epsilon,
node_repeats=node_repeats
)
remaining_nodes -= nodes
assignment = [nodes] + recursive_seed_part_inner(graph.subgraph(remaining_nodes),
num_dists - 1,
pop_target,
pop_col,
epsilon,
n=n,
ceil=ceil)

chunk_assignment = recursive_seed_part_inner(
graph.subgraph(chunk),
num_dists // num_chunks,
pop_target,
pop_col,
epsilon,
n=n,
ceil=ceil
)

Clearly, method is used exactly once, and will not be used in subsequent calls because it is not passed. Instead, the default of partial(bipartition_tree, max_attempts=10000), will be used.

InnovativeInventor pushed a commit that referenced this issue Oct 4, 2023
This is a bug fix. `method` was previously not being used where it should be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant