Repository navigation
refactor(discrete_space): name and document the random probe budget (#3999) - #4020
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
quaquel
reviewed
Nov 4, 2026
quaquel
left a comment
Member
There was a problem hiding this comment.
Do I understand this PR correctly in that all it does it move the implicit 50 tries into an explicit global variable?
Contributor
Author
Yes, that's right. Behaviour is unchanged: the budget stays at 50 and the probe loop is identical.
|
quaquel
approved these changes
Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Name the random-probe budget used by
Grid.select_random_empty_cellandGrid.select_random_cell_with_capacity(_MAX_RANDOM_PROBES = 50), replace the stale FIXME with the reasoning behind it, and add tests that pin down the behaviour. No behaviour change: the budget stays at 50.Motive
Phase 2 of #3626 (proposal in #3999). The budget was a magic number duplicated in two methods, with an outdated FIXME. After benchmarking alternatives, I don't think a different fixed value is justified yet, so this PR records why 50 is a safe choice and guards against regressions.
Implementation
mesa/discrete_space/grid.py: new class attributeGrid._MAX_RANDOM_PROBES = 50, used by both methods. The comment explains that all probes miss with probability (1 - p)^50, about 0.5% at 10% empty cells and about 1e-5 at 20%, so grids that aren't nearly full practically never reach the O(n) fallback. It also notes that smaller budgets make the scan fire too often at p >= 10% and should be re-evaluated with the benchmark script first.tests/discrete_space/test_discrete_space.py:Additional Notes
Findings (local, noisy; please confirm on CI):
A budget that scales with grid size remains possible, but needs multi-machine benchmark data before it is worth the extra complexity. This PR builds on the flatnonzero fallback PR for #3626 and should be rebased once that merges.
Refs #3999
Refs #3626
closes #3999