Skip to content

document the duplicate coordinate - #3473

Merged
quaquel merged 26 commits into
mesa:mainfrom
Krishsharma179:fix-duplicate-coordinate-validation
Mar 11, 2026
Merged

quaquel merged 26 commits into
mesa:mainfrom
Krishsharma179:fix-duplicate-coordinate-validation

Conversation

@Krishsharma179

@Krishsharma179 Krishsharma179 commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In the current system in discrete_space.py in add_cell there is a probability that the user might initialize the new cell at the coordinate where there is already a cell then the previous cell will be overwritten by the new cell silently

Bug / Issue

#3469 This is the link to the related issue

Implementation

Just document this explicitly

Warning:
            Coordinate Collision: If a cell already exists at the specified
            coordinates (e.g., cell1), it will be overwritten silently by the
            new cell (cell2).

            Ensure the target coordinates are vacant before calling this method.
        

@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +0.5% [+0.1%, +0.9%] 🔵 +0.3% [+0.2%, +0.5%]
BoltzmannWealth large 🔵 -0.1% [-1.1%, +1.1%] 🔵 +2.2% [-0.3%, +5.4%]
Schelling small 🔵 +1.4% [+0.8%, +2.0%] 🔵 +2.0% [+1.8%, +2.3%]
Schelling large 🔵 +0.4% [-0.2%, +1.1%] 🔵 -1.7% [-2.8%, -0.4%]
WolfSheep small 🔵 -0.7% [-1.1%, -0.3%] 🔵 -1.0% [-1.1%, -0.8%]
WolfSheep large 🔵 -0.8% [-1.9%, +0.3%] 🔵 +0.8% [-0.8%, +2.6%]
SugarscapeG1mt small 🔵 +0.4% [-0.2%, +1.0%] 🔵 -1.0% [-1.2%, -0.7%]
SugarscapeG1mt large 🔵 +0.4% [-0.6%, +1.4%] 🔵 -0.5% [-1.0%, +0.3%]
BoidFlockers small 🔵 -0.4% [-0.7%, -0.0%] 🔵 -0.2% [-0.4%, -0.1%]
BoidFlockers large 🔵 -0.5% [-1.0%, +0.0%] 🔵 -0.8% [-1.0%, -0.6%]

@Krishsharma179

Copy link
Copy Markdown
Contributor Author

Hi @quaquel , please check this out when you get a chance!

@quaquel quaquel added the enhancement Release notes label label Mar 7, 2026
@souro26

souro26 commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

I’m not sure this should be treated as a bug. Right now add_cell just assigns directly into _cells, which means adding a cell at an existing coordinate replaces the old one. That is an intentional dictionary style semantic rather than something accidental.

Changing this to raise a ValueError would shift the behavior from replacement to a hard failure. That’s a significant behavioral change, especially since the current implementation doesn’t enforce any uniqueness checks and simply lets the new cell overwrite the old one. Also, modifying existing tests to enforce a new behavior is not the best way to handle this in my opinion.

Given the comment that dynamically modifying DiscreteSpace isn’t really a primary supported workflow, I think enforcing validation here is the wrong direction. It is better to either document the overwrite behavior explicitly or discuss whether replacement vs. validation should actually be the intended API before locking it in with an exception and tests.

@Krishsharma179

Copy link
Copy Markdown
Contributor Author

@quaquel please check

@Krishsharma179

Copy link
Copy Markdown
Contributor Author

I’m not sure this should be treated as a bug. Right now add_cell just assigns directly into _cells, which means adding a cell at an existing coordinate replaces the old one. That is an intentional dictionary style semantic rather than something accidental.

Changing this to raise a ValueError would shift the behavior from replacement to a hard failure. That’s a significant behavioral change, especially since the current implementation doesn’t enforce any uniqueness checks and simply lets the new cell overwrite the old one. Also, modifying existing tests to enforce a new behavior is not the best way to handle this in my opinion.

Given the comment that dynamically modifying DiscreteSpace isn’t really a primary supported workflow, I think enforcing validation here is the wrong direction. It is better to either document the overwrite behavior explicitly or discuss whether replacement vs. validation should actually be the intended API before locking it in with an exception and tests.

Hey @souro26 thanks for the feedback I understood that raising an error will be too extreme for this so I document this behavior explicitly

@quaquel

quaquel commented Mar 10, 2026

Copy link
Copy Markdown
Member

Can you update the original description so it correctly reflects the actual implementation?

Comment thread mesa/discrete_space/discrete_space.py Outdated
new cell (cell2).

- The original cell will vanish without any notification or error.
- All agents contained within the original cell will be permanently lost.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not true, please remove

Comment thread mesa/discrete_space/discrete_space.py Outdated
coordinates (e.g., cell1), it will be overwritten silently by the
new cell (cell2).

- The original cell will vanish without any notification or error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not true perse. It has just been removed from the grid, but might stick around as a ghost cell depending on what holds references to it.

@Krishsharma179

Copy link
Copy Markdown
Contributor Author

ok I will do it

@Krishsharma179
Krishsharma179 force-pushed the fix-duplicate-coordinate-validation branch from 39a67cd to 84585ce Compare March 10, 2026 15:17
@Krishsharma179

Copy link
Copy Markdown
Contributor Author

@quaquel Done! Updated the documentation to reflect the actual
behavior. Thanks for the clarification!

@souro26

souro26 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Please update the PR title and description

@Krishsharma179 Krishsharma179 changed the title Fix duplicate coordinate validation document the duplicate coordinate validation Mar 10, 2026
@Krishsharma179 Krishsharma179 changed the title document the duplicate coordinate validation document the duplicate coordinate Mar 10, 2026
@quaquel quaquel added docs Release notes label and removed enhancement Release notes label labels Mar 11, 2026
@quaquel
quaquel merged commit 62afb50 into mesa:main Mar 11, 2026
12 checks passed
EwoutH pushed a commit that referenced this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants