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

Uses array for hex grid property layer fix #2651

Conversation

Sahil-Chhoker
Copy link
Contributor

@Sahil-Chhoker Sahil-Chhoker commented Jan 28, 2025

Summary

lru_cache does not work with generators, therefore _get_hexmesh is changed to a function.

This was a problem in #2646 that used generators which don't go well along with caching. This PR simply removes the generator and adds a list where all the results are stored.

@Sahil-Chhoker
Copy link
Contributor Author

@quaquel I think this should do it.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.8% [+1.2%, +2.4%] 🔵 +1.9% [+1.7%, +2.0%]
BoltzmannWealth large 🔵 +0.2% [-1.1%, +0.9%] 🔵 +1.3% [+0.1%, +2.4%]
Schelling small 🔵 +1.1% [+0.8%, +1.4%] 🔵 +0.7% [+0.5%, +0.8%]
Schelling large 🔵 +0.8% [+0.4%, +1.1%] 🔵 -1.6% [-3.6%, +0.5%]
WolfSheep small 🔵 -0.6% [-1.0%, -0.2%] 🔵 +0.2% [-0.0%, +0.3%]
WolfSheep large 🔵 -2.3% [-4.8%, +0.0%] 🔵 -7.8% [-12.9%, -2.7%]
BoidFlockers small 🔵 -1.9% [-2.9%, -0.9%] 🔵 +0.6% [+0.2%, +1.0%]
BoidFlockers large 🔵 -0.0% [-0.6%, +0.6%] 🔵 +1.0% [+0.7%, +1.4%]

Copy link
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

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

Yes this should do it.

Can you make the PR text a bit more descriptive by linking it to the previous PR? I'll merge later today.

Thanks for the quick fix!

@Sahil-Chhoker
Copy link
Contributor Author

Jan, I’d also love to hear why caching doesn’t work with generators when you have time.

@quaquel
Copy link
Member

quaquel commented Jan 28, 2025

The cache returns the same generator object. This object is exhausted after the first iteration, so subsequent iterations never happen.

@quaquel quaquel added the bug Release notes label label Jan 28, 2025
@quaquel quaquel merged commit ffdd525 into projectmesa:main Jan 28, 2025
13 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants