Comments (14)
Thanks for reaching out. I will test this tomorrow morning, if no one else has done it by then.
Furthermore if I not call super().init() in the model class, the first agent is not added to the scheduler.
Calling super().__init__()
was always recommended, but now it’s required. It initializes Model.agents
among other things. You’re using the Mesa Model class, so you should properly initialize it.
from mesa.
I've narrowed it down to the fact that the AgentSet's shuffle(inplace=True)
doesn't shuffle the agents. Could be because the shuffle isn't working, or the in place updating isn't.
Lines 144 to 147 in 99b35fc
from mesa.
It's the inplace updating that isn't working. Without it, it works correctly:
@quaquel you wrote this code and know more about the AgentSet implementation. Could assist in fixing the inplace updating?
from mesa.
@profConradi we just released Mesa 2.2.4 which should fix this issue. Could you confirm this is the case?
from mesa.
Yes, the RandomActivation Scheduler of 2.2.4 works correctly! Thanks!
from mesa.
Great to hear, thanks a lot for reporting this issue!
For such a serious bug to slip thought the the review, test and release process is really unfortunate. I wrote some thoughts on it here: #1909 (comment)
from mesa.
@rht do you have time to investigate this?
from mesa.
I'd need some help debugging all the problems caused by 2.1.x -> 2.2.x. Hands are full with elsewhere.
from mesa.
Unfortunately, I can reproduce this issue for both Mesa 2.2.0 and 2.2.3, while the correct behavior (shuffled agent steps) on Mesa 2.1.5. @projectmesa/maintainers this is a major issue and needs immediate care, we broke RandomActivation
.
I will investigate further.
from mesa.
Thanks for your work, Mesa is an amazing framework!
from mesa.
I can try this afternoon. I don't see an obvious mistake in the code.
AgentSet.shuffle
shuffled_agents = list(self)
self.random.shuffle(shuffled_agents)
return (
AgentSet(shuffled_agents, self.model)
if not inplace
else self._update(shuffled_agents)
)
random.shuffle is inplace. List(self) returns a list of hard refs to the agents.
AgentSet._update
def _update(self, agents: Iterable[Agent]):
"""Update the AgentSet with a new set of agents.
This is a private method primarily used internally by other methods like select, shuffle, and sort.
"""
self._agents = weakref.WeakKeyDictionary({agent: None for agent in agents})
return self
We create a new WeakKeyDictionary so it should shuffle.
Accidentally, This is the code I was playing with for #1993. So my to do;
- add a unittest that reproduces the error
- figure out why the error exists, because based on the code I don't
- test my fix from #1993
from mesa.
Thanks. I had already written an additional unittest for RandomActivation itself, we can test updates also against that (#2007).
from mesa.
Found it. The problem is in the scheduler not in AgentSet.
do_each should be
def do_each(self, method, shuffle=False):
if shuffle:
self._agents.shuffle(inplace=True)
self._agents.do(method)
from mesa.
I committed the fix to #2007.
from mesa.
Related Issues (20)
- Add Voronoi tessellation space
- Add Triangle mesh space
- Proposal: Formal neighborhood definition for grids HOT 42
- Proposal: Flexible move_agent method that allows multiple movement strategies HOT 5
- Proposal: Agent selection method HOT 7
- JupyterViz: disabled space drawer is ignored when rendering in the browser HOT 1
- jupyterviz: best practices for model layout HOT 1
- best practices / example for parameter sweep with batch runner HOT 15
- AttributeError: 'Model' object has no attribute 'agents' HOT 2
- move_agent_to_neighborhood HOT 14
- RuntimeError when removing agents from model with new schedulers HOT 3
- Clean up labels to. make release labeling easier HOT 4
- JupyterViz space view limits
- Update tutorials to include super().__init__() when subclassing mesa.model HOT 1
- model.get_agents_of_type() still contains agents that have been removed both from the grid and the scheduler HOT 8
- NumFOCUS: GSoC 2024 Update
- DiscreteEveImprovements to the DiscreteEventScheduler classntScheduler class HOT 3
- AgentSet.get is hardcoded to raise AttributeError for agents with missing attribute HOT 3
- Aggregation of tables registered in data collector during batch runs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mesa.