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

examples: Fix schelling viz #2490

Merged
merged 1 commit into from
Nov 11, 2024
Merged

examples: Fix schelling viz #2490

merged 1 commit into from
Nov 11, 2024

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Nov 11, 2024

Fix the Schelling visualisation. Default arguments are already defined in the model.py, and the visualisation crashed probably because of the order having changed.

Before:

  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\mesa\examples\basic\schelling\agents.py", line 20, in step
    similar = sum(1 for neighbor in neighbors if neighbor.type == self.type)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\mesa\examples\basic\schelling\agents.py", line 20, in <genexpr>
    similar = sum(1 for neighbor in neighbors if neighbor.type == self.type)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\mesa\space.py", line 371, in iter_neighbors
    for x, y in self.get_neighborhood(pos, moore, include_center, radius):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\mesa\space.py", line 309, in get_neighborhood
    x_range = range(x - radius, x + radius + 1)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer

After:
image

Fix the Schelling visualisation
@EwoutH EwoutH added the example Changes the examples or adds to them. label Nov 11, 2024
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +3.5% [+1.9%, +5.3%] 🔵 +0.1% [-0.0%, +0.3%]
BoltzmannWealth large 🔵 -0.5% [-1.0%, +0.0%] 🔵 -0.2% [-0.7%, +0.4%]
Schelling small 🔵 -0.4% [-0.6%, -0.2%] 🔵 +0.7% [+0.5%, +0.9%]
Schelling large 🔵 -0.7% [-1.0%, -0.4%] 🔵 +0.3% [-0.3%, +0.9%]
WolfSheep small 🔵 -0.2% [-0.4%, +0.1%] 🔵 -0.4% [-0.5%, -0.2%]
WolfSheep large 🔵 +0.0% [-0.4%, +0.3%] 🔵 +0.2% [-0.3%, +0.6%]
BoidFlockers small 🔵 +1.3% [+0.9%, +1.7%] 🔵 +0.8% [-0.0%, +1.7%]
BoidFlockers large 🔵 +1.1% [+0.7%, +1.6%] 🔵 +1.8% [+1.3%, +2.4%]

@EwoutH EwoutH merged commit ab8f7ab into projectmesa:main Nov 11, 2024
11 of 13 checks passed
EwoutH added a commit that referenced this pull request Nov 11, 2024
Fix the Schelling visualisation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Changes the examples or adds to them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants