Comments (6)
Thanks for opening this issue and writing it up!
@rht I looked a bit into this issue and I can reproduce it. I think it has to do with either the model clock or the datacollector. Model._steps
isn't updated for example with each step. It might be related to how #1942 was implemented. Do you have the opportunity to investigate this further?
from mesa.
This is expected in the new API. Because you are not using model.schedule.step()
, the model._steps
doesn't get updated automatically. You need to manually advance the clock. See https://github.com/projectmesa/mesa-examples/blob/1e0d6b855c853c1dfa749348445a31000b4daca4/examples/schelling_experimental/model.py#L65-L77
from mesa.
Thanks. I tried adding a call self_advance_time()
just before data collection in the toy model and the problem persists. I should also note than in the model I was working with where this problem first arose, which is a version of the sugarscape_g1mt model from the mesa examples catalog, there is a call self._steps +=1
just before data collection, which I assume does essentially same thing. Thus, neither one seems to solve the problem.
from mesa.
I can reproduce this bug using the AgentSet API and other modern Mesa best practices.
import mesa
class testAgent(mesa.Agent):
def __init__(self, unique_id, model):
super().__init__(unique_id, model)
self.pos: tuple
def pollute(self):
self.model.grid.properties["pollution"].modify_cell(self.pos, lambda p: p+1)
class testModel(mesa.Model):
def __init__(self, width = 20, height = 20, initial_population=200):
super().__init__()
self.width = width
self.height = height
self.initial_population = initial_population
# initiate mesa grid class
self.grid = mesa.space.MultiGrid(self.width, self.height, torus=False)
#add pollution property layer
pollution_layer = mesa.space.PropertyLayer(name = "pollution", width = self.width, height = self.height, default_value = 0.0, dtype=float)
self.grid.add_property_layer(pollution_layer)
self.datacollector = mesa.DataCollector(model_reporters = {
"Pollution": lambda m: m.grid.properties["pollution"].data,
"Step": "_steps"
})
agent_id = 0
for i in range(self.initial_population):
# get agent position
agent = testAgent(agent_id, self)
self.grid.place_agent(agent, pos=mesa.model.random.choice(list(self.grid.empties)))
agent_id += 1
def step(self):
self.agents.shuffle().do("pollute")
print(f"Step {self._steps}: {self.grid.properties["pollution"].data[:1]}")
self.datacollector.collect(self)
self._advance_time()
# Run the model
model = testModel()
for i in range(20):
model.step()
model_results = model.datacollector.get_model_vars_dataframe()
model_results
It prints the correct values each step, so it seems the bug is really in the datacollector itself.
from mesa.
I suspect for some reason it doesn't save a copy of the values at that timestep to model_vars
, but a reference to the values that gets continuously updated with each step. @rht do you have an idea where that could happen?
from mesa.
Found the issue and implemented a fix in #2129.
from mesa.
Related Issues (20)
- Readthedocs is failing on configuration error HOT 2
- Clean-up private variables (`_agents`, `_step`) HOT 1
- Automate and enforce unique `unique_id` in Agents HOT 14
- wrong issue
- Allow creating multiple agents directly HOT 7
- Automatic time and step incrementing
- Boltzman performance issue HOT 13
- `WeakKeyDictionary` slow in large-scale Agent Initialization HOT 8
- Write Mesa 3.0 migration guide
- BUG : MESA 2.3 HOT 4
- SolaraViz: visualization should update on parameter changes HOT 6
- Customize network layout, currently only spring layout HOT 3
- Redirect Link is not working on home page HOT 7
- SolaraViz: Fast option for dynamic plots
- Docs: Update Mesa Overview page
- Improve AgentSet method chaining performance HOT 4
- A system for managing Model/Agent default values and ranges HOT 13
- Test tutorials in CI HOT 2
- Question about Agent place_agent() warning HOT 7
- Multiline plot is not yet documented
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.