-
Notifications
You must be signed in to change notification settings - Fork 926
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
More pythonic implementation of wolf sheep #2011
Conversation
|
||
from mesa import Model, Agent | ||
from mesa import Agent, Model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 lines can be condensed to be just import mesa
, then calling them would be mesa.Agent
, mesa.Model
, mesa.space.MultiGrid
, in line with np.array
or pd.DataFrame
. See https://github.com/projectmesa/mesa-examples/blob/479eaf389e1a98bda0bdba5aa8f24ede0d84e764/examples/wolf_sheep/wolf_sheep/model.py#L18.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that is slower.
To be clear, I don't care much either way, so if there is some mesa convention for this, I am fine changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's about the same:
In [1]: import mesa
In [2]: m = mesa.Model()
In [3]: %timeit mesa.Agent(0, m)
627 ns ± 125 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
In [4]: from mesa import Agent, Model
In [5]: m2 = Model()
In [6]: %timeit Agent(0, m2)
627 ns ± 148 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except for the import lines, this PR LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't have strong opinions on this so if others want to change this as well, fine.
Note, however, that the Schelling model already uses the same style of importing as I have used here. I also personally prefer e.g., SchellingAgent(Agent)
over SchellingAgent(mesa.Agent)
. This is really just a matter of taste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention in the examples repo all uses mesa.x
. The ones in the Agents.jl benchmark code are from the outdated version of the examples.
This is really just a matter of taste.
But in the case of Agents.jl benchmark, they count and compare the LOC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention in the examples repo all uses mesa.x.
I ment our benchmarks
But in the case of Agents.jl benchmark, they count and compare the LOC.
And we agree that this is only a rough proxy we should not obsess about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ment our benchmarks
The 3 versions of the code (mesa-examples, core Mesa benchmark, Agents.jl) ideally need to be kept in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Once this is merged, I'll happily make PRs on the other libraries.
Performance benchmarks:
|
Thanks! Would it be possible to split into two commits: One that makes it a single file, and then the actual changes? This diff is very difficult to review. |
There is no real point looking at the diff here. It's just a clean reimplementation. |
As the build is failing at SugarScape_g1mt, I am going to merge. |
This is a more Pythonic and single-file implementation of Wolf Sheep for benchmarking.
The single file is easier for profiling and line profiling.