-
Notifications
You must be signed in to change notification settings - Fork 162
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
Moving examples to use the new discrete spaces #198
Conversation
If you change this line:
To:
You can see if it works in CI. |
I am testing locally against my branch for #2286, but I'll update the the yml in this branch to show CI here as well. |
This PR just need the imports switched right? |
The smart thing to do would be to change the imports to |
Awesome, sounds like a plan! |
If you need anything on this PR let me know! |
How to get the build to succeed? It now errors out on reaction? Other than that, I think this is another half our of work later today and then its done. |
Awesome progress!
I think the error is this init (https://github.com/projectmesa/mesa/blob/main/mesa/experimental/__init__.py) in combination with that we now don’t install Solara by default anymore. Let me look into 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.
I really like how clean the API is looking, and how easy old components are replaced. Good stuff!
store.market_share = 0 | ||
|
||
for consumer in self.consumer_agents: | ||
for consumer in self.agents_by_type[ConsumerAgent]: |
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.
Is there a space too much here?
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'll run ruff once I am done and fix it all
I am also pleasantly surprised by (1) how easy the switch is; and (2) how, in many places, it reduces code complexity. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Really awesome, I see some really neat changes in here. Curious, did you encounter any limitations or go any ideas to do things more elegantly in the cell space? Let's discuss Wednesday how we want to structure the examples for experimental features. Would be awesome if we can stabilize those together with features in future PRs, once the core examples are moved back. |
I have made various PRs related to grid spaces while working on this. For example, the way we resolved movement #2333 and #2296, the split of neighborhood and get_neigborhood #2309, and the width/height properties #2348 all emerged out of making these examples work with experimental grid spaces. Some of these examples can be refined even further by using property layers (e.g., sugarscape) or using some of the features introduced in the aforementioned PRs. But I am quite happy with how expressive and complete the grid spaces are. There is also room for further improvement:
# current
for cell in self.grid.all_cells:
MyAgent(self, cell)
# with some create method
MyAgent.create_agents(cell=self.grid.all_cells)
|
Could you split of the changes in the "basic" (as in projectmesa/mesa#2349 (comment)) examples into a new, separate branch and save that somewhere where you can find it back in a few weeks/months? Then we will merge those during/after cell space stabilization. All "complex" and "showcase" examples can stay in this PR, then we will merge that ASAP. Sorry it's a bit of a messy process, your effort is appreciated, and it looks like we now have a clear policy for experimental features in examples. |
It will be annoying but doable if I have time in a few days. Would it not be simpler to move the basis versions over to that PR? If I am not mistaken, only Schelling is missing at the moment. Next, we merge this, continue the move of advanced examples and once that PR is merged remove all moved over examples from mesa-examples. |
Mainly imports
Revert the basic models back to the current stable grids
For a proper port of the git history its way easier if we can move the examples at once, otherwise we're merging multiple related git histories which makes it even more complex. I reverted the basic examples, and saved the changes in a backup branch: https://github.com/projectmesa/mesa-examples/tree/pr_198_examples_backup projectmesa/mesa#2357 should unblock the CI and then we're good to go. |
Fair point. I had not considered that. |
Main CI passes, awesome. Thanks a lot for this huge effort! |
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 was a bit enthosiastic on my approval, only after realizing I didn't do a proper code review yet.
Overal, it looks amazing, with some really nice cleanups and elegant constructs! I have a few small things, then can (but should) be dealt with in a follow-up PR.
Especially check if if all your changes were ported correctly after #220, and then remove the duplicate files.
@@ -93,6 +94,7 @@ def __init__(self, model, alpha: float = 1.0, beta: float = 5.0): | |||
self._traveled_distance = 0 | |||
self.tsp_solution = [] | |||
self.tsp_distance = 0 | |||
self.graph = self.model.grid.G |
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.
Would it be useful to make this a property or function?
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.
not sure what you are proposing. This is in the agent class.
@@ -173,14 +180,15 @@ def __init__( | |||
self.num_cities = tsp_graph.num_cities | |||
self.all_cities = set(range(self.num_cities)) | |||
self.max_steps = max_steps | |||
self.grid = mesa.space.NetworkGrid(tsp_graph.g) | |||
self.grid = Network(tsp_graph.g, random=self.random) |
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.
Maybe call it space here, since it isn't really a grid?
self.grid = Network(tsp_graph.g, random=self.random) | |
self.space = Network(tsp_graph.g, random=self.random) |
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.
Do we really want this data file included?
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.
not sure, but the entire batch run example stuff seems incorrect so this needs a bit more attention
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.
Can be removed I think
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.
why?
Thanks for these comments. I just like to point out that most of these are comments on the original code from which I started, not the changes made in this PR. Some of the other comments are about using features that were added based on what was learned while doing this. I'll try to go through these in follow up PRs when I have time. A quick look suggests only 1 is pointing out a mistake in my code. |
Oh certainly, and none of them were blocking. Just things I noticed when going through the diff. Do you prefer to fix some of them before the example move, or after? |
This PR moves over all relevant examples to the experimental grid spaces. While making this move, the experimental grid spaces continue to be refined.