Skip to content

fix: bound random edge sampling to available candidates - #37

Closed
liuzhengyang699 wants to merge 1 commit into
metauto-ai:mainfrom
liuzhengyang699:fix/bounded-edge-sampling
Closed

liuzhengyang699 wants to merge 1 commit into
metauto-ai:mainfrom
liuzhengyang699:fix/bounded-edge-sampling

Conversation

@liuzhengyang699

Copy link
Copy Markdown

random_sample_num_edges samples with replacement until the graph reaches the requested edge count. If the candidates are exhausted or the remaining edges would create cycles, it keeps retrying forever. For example, the two candidates a -> b and b -> a cannot produce a two-edge DAG. This can hang the random-graph baseline in experiments/crosswords/evaluate.py.

Visit candidates once in random order and stop when the target is reached. If this pass cannot reach the target, raise a ValueError describing the sampled and requested edge counts. Existing edges still count toward the target, and the input graph is left unchanged.

Validation: python -m pytest test/swarm/graph/test_edge_sampling.py -q — 5 passed, no LLM calls. Three regressions fail before the fix; the tests bound sampler calls so the old implementation cannot hang the test run. git diff --check passed.

@liuzhengyang699 liuzhengyang699 closed this by deleting the head repository Oct 27, 2026
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 this pull request may close these issues.

1 participant