-
Notifications
You must be signed in to change notification settings - Fork 967
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
Attempt to Optimize Wolf-Sheep Performance #2723
base: main
Are you sure you want to change the base?
Conversation
Performance benchmarks:
|
Performance benchmarks:
|
@gadhvirushiraj Thanks a lot for your PR! Our benchmarks currently show a performance decrease, both the small and large size. What would you like us to do for this PR? |
Hello @EwoutH, I've been digging into the recent performance drop and noticed that it doesn't seem from updating positions in I'm open to exploring alternative approaches if you have any suggestions. This PR has been a good learning opportunity for me in getting to grips with Mesa's modeling :) Thanks |
I would start with profiling both the old and new implementation, to see where compute time is spend in both. |
Summary
Attempt at optimizing
Sheep Agent
movement using Mesa'sPropertyLayer
and vectorized operations to determine the best moves.Motive
The current movement logic in the wolf-sheep model performs redundant checks when agents search their neighborhood for valid moves. This optimization builds on changes from #2503.
Implementation
Two
PropertyLayer
:sheep_pos
andgrass_pos
are added and updated. The agent determines the best move by extracting a subsection (neighbor radius - 1) of thePropertyLayer
and applying vectorized boolean operations. Refer Issue #2565.However, performance drops for
Wolf-Sheep (large)
, likely because the overhead of updating a larger grid offsets the benefits. A larger grid with higher agent density maybe yield better results, I think (not sure).Usage Examples
--
Additional Notes
I tested multiple variations of this approach. Full-layer vector operations proved expensive compared to the original
get_neighborhood
method.An, imporvment can be a better way to update
grass_pos
(grass tracking layer) and updatingwolf_pos
directly from Agent'smove()
. Edit : Implemented