Skip to content

Fixed Marker in mpl#2670

Merged
quaquel merged 4 commits intomesa:mainfrom
sanika-n:marker
Feb 15, 2025
Merged

Fixed Marker in mpl#2670
quaquel merged 4 commits intomesa:mainfrom
sanika-n:marker

Conversation

@sanika-n
Copy link
Copy Markdown
Collaborator

@sanika-n sanika-n commented Feb 8, 2025

Bug

In agent portrayal, the marker is supposed to be able to take on all matplotlib marker types. But the tuple way of defining markers is currently not compatible in MESA. This issue can be replicated by replacing the marker in any one of the examples (here I have taken boid_flockers) with say (3, 0, 30). This is supposed to convert the agents to a 3 sided polygon tilted by 30 degrees, if we replaced 3 with 4 we will get a square instead.
The main reason for the error was that during agent data collection, numpy was turning the tuples into arrays. I have fixed the issue in this PR.

I just ran boid_flockers using tuples in the following code after the fix:

def boid_draw(agent):
    neighbors = len(agent.neighbors)

    if neighbors <= 1:
        return {"color": "red", "size": 20, "marker": "o"}
    elif neighbors >= 2:
        return {"color": "green", "size": 20, "marker": (3, 0, 60)}

image

I am not exactly sure, but I was wondering if merging this fix will help us later implement a solution to #1150, I can try working on that for boid_draw if it is feasible...


for mark in np.unique(marker):
mark_mask = marker == mark
for mark in set(marker):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to a set here because np.unique only works on similar datatypes as far as I know. And if we have a mix of tuples and the normal strings, np.unique wont work

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 8, 2025

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.6% [+0.2%, +3.1%] 🔵 -0.1% [-0.2%, +0.1%]
BoltzmannWealth large 🔵 -0.7% [-1.5%, +0.2%] 🔵 -0.0% [-1.0%, +0.9%]
Schelling small 🔵 +0.1% [-0.2%, +0.3%] 🔵 -0.6% [-0.7%, -0.4%]
Schelling large 🔵 +0.1% [-0.4%, +0.5%] 🔵 -0.3% [-0.7%, -0.0%]
WolfSheep small 🔵 -0.0% [-0.4%, +0.4%] 🔵 -1.0% [-1.2%, -0.8%]
WolfSheep large 🔵 -1.3% [-2.7%, +0.0%] 🔵 +0.1% [-1.4%, +1.3%]
BoidFlockers small 🔵 -2.4% [-3.1%, -1.7%] 🔵 -1.0% [-1.2%, -0.7%]
BoidFlockers large 🔵 -2.4% [-3.0%, -1.8%] 🔵 -1.0% [-1.3%, -0.6%]

@EwoutH EwoutH requested review from Corvince and quaquel February 14, 2025 10:23
@EwoutH EwoutH added the bug Release notes label label Feb 14, 2025
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.

This is a good way to test hybrid markers. Nice!

@quaquel quaquel merged commit 0579dd0 into mesa:main Feb 15, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label visualisation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants