Skip to content

Commit 6cbafd5

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 2d82303 + 61da796 commit 6cbafd5

27 files changed

+506
-169
lines changed

benchmarks/global_benchmark.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from configurations import configurations
1414

15-
from mesa.experimental.devs.simulator import ABMSimulator
16-
1715

1816
# Generic function to initialize and run a model
1917
def run_model(model_class, seed, parameters):
@@ -27,26 +25,17 @@ def run_model(model_class, seed, parameters):
2725
Returns:
2826
startup time and run time
2927
"""
30-
uses_simulator = ["WolfSheep"]
3128
# Explicitly collect garbage before the run to ensure a clean memory state
3229
gc.collect()
3330

3431
# Disable GC during timed runs to avoid random slowdowns
3532
gc.disable()
3633
start_init = time.perf_counter()
37-
if model_class.__name__ in uses_simulator:
38-
simulator = ABMSimulator()
39-
model = model_class(simulator=simulator, rng=seed, **parameters)
40-
else:
41-
model = model_class(rng=seed, **parameters)
34+
model = model_class(rng=seed, **parameters)
4235

4336
end_init_start_run = time.perf_counter()
4437

45-
if model_class.__name__ in uses_simulator:
46-
simulator.run_for(config["steps"])
47-
else:
48-
for _ in range(config["steps"]):
49-
model.step()
38+
model.run_for(config["steps"])
5039

5140
end_run = time.perf_counter()
5241
gc.enable() # Re-enable GC after benchmarking

docs/apis/experimental.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ This namespace contains experimental features. These are under development, and
44

55
## Devs
66

7-
```{eval-rst}
8-
.. automodule:: experimental.devs.eventlist
9-
:members:
10-
```
11-
127
```{eval-rst}
138
.. automodule:: experimental.devs.simulator
149
:members:

docs/apis/time.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Time
2+
3+
```{eval-rst}
4+
.. automodule:: mesa.time
5+
:members:
6+
:inherited-members:
7+
```

docs/migration_guide.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,78 @@ This guide contains breaking changes between major Mesa versions and how to reso
44
Non-breaking changes aren't included, for those see our [Release history](https://github.com/mesa/mesa/releases).
55

66
## Mesa 3.5.0
7+
### Event scheduling and time advancement
8+
Mesa 3.5 introduces public methods for event scheduling and time advancement directly on `Model`, replacing the need for `Simulator` classes.
9+
10+
#### Time-based advancement replaces step loops
11+
```python
12+
# Old
13+
for _ in range(10):
14+
model.step()
15+
16+
# New
17+
model.run_for(10) # Functionally equivalent for standard ABMs
18+
model.run_until(10) # You can now also run until a specific time
19+
```
20+
`run_for(1)` produces identical results to `step()` for traditional models.
21+
22+
#### One-off event scheduling
23+
24+
```python
25+
# Schedule a single event at or after a specific time
26+
model.schedule_event(callback, at=50.0) # Absolute time
27+
model.schedule_event(callback, after=5.0) # Relative time
28+
29+
# Cancel if needed
30+
event = model.schedule_event(callback, at=100.0)
31+
event.cancel()
32+
```
33+
34+
#### Recurring event scheduling
35+
```python
36+
from mesa.time import Schedule
37+
38+
# Schedule an event every 10 time units
39+
model.schedule_recurring(func, Schedule(interval=10)) # By default, starting after 1 interval (t=10 in this case)
40+
model.schedule_recurring(func, Schedule(interval=10, start=0)) # Start immediately or at any other time
41+
42+
# Save the event and stop it when needed
43+
gen = model.schedule_recurring(func, Schedule(interval=5.0))
44+
gen.stop()
45+
46+
# Limit executions
47+
model.schedule_recurring(func, Schedule(interval=1.0, count=10))
48+
```
49+
50+
#### Replacing Simulator classes
51+
The experimental Simulator classes are now also deprecated.
52+
```python
53+
# Old - ABMSimulator
54+
from mesa.experimental.devs.simulator import ABMSimulator
55+
simulator = ABMSimulator()
56+
simulator.setup(model)
57+
simulator.run_for(100)
58+
59+
# New
60+
model.run_for(100)
61+
```
62+
63+
```python
64+
# Old - DEVSimulator
65+
from mesa.experimental.devs.simulator import DEVSimulator
66+
simulator = DEVSimulator()
67+
simulator.setup(model)
68+
simulator.schedule_event_absolute(callback, time=10.5)
69+
simulator.run_for(50)
70+
71+
# New
72+
model.schedule_event(callback, at=10.5)
73+
model.run_for(50)
74+
```
75+
76+
Mesa 3.5 doesn't introduce any breaking changes. Mesa 4 will clean up many deprecated components and thus will break unmodified models.
77+
78+
* Ref: [Discussion #2921](https://github.com/mesa/mesa/discussions/2921), [PR #3266](https://github.com/projectmesa/mesa/pull/3266)
779

880
### AgentSet sequence behavior
981
The Sequence behavior (indexing and slicing) on `AgentSet` is deprecated and will be removed in Mesa 4.0. Use the new `to_list()` method instead.

docs/tutorials/0_first_model.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@
501501
"for _ in range(100):\n",
502502
" # Run the model\n",
503503
" model = MoneyModel(10)\n",
504-
" for _ in range(30):\n",
505-
" model.step()\n",
504+
" model.run_for(30)\n",
506505
"\n",
507506
" # Store the results\n",
508507
" for agent in model.agents:\n",

docs/tutorials/2_collecting_data.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@
157157
"outputs": [],
158158
"source": [
159159
"model = MoneyModel(100, 10, 10)\n",
160-
"for _ in range(20):\n",
161-
" model.step()\n",
160+
"model.run_for(20)\n",
162161
"# Let's make sure it worked\n",
163162
"print(len(model.agents))"
164163
]
@@ -285,8 +284,7 @@
285284
"outputs": [],
286285
"source": [
287286
"model = MoneyModel(100, 10, 10)\n",
288-
"for _ in range(100):\n",
289-
" model.step()"
287+
"model.run_for(100)"
290288
]
291289
},
292290
{

docs/tutorials/3_agentset.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@
179179
"outputs": [],
180180
"source": [
181181
"model = MoneyModel(100)\n",
182-
"for _ in range(20):\n",
183-
" model.step()\n",
182+
"model.run_for(20)\n",
184183
"\n",
185184
"\n",
186185
"data = model.datacollector.get_agent_vars_dataframe()\n",

docs/tutorials/4_visualization_basic.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@
208208
"source": [
209209
"# Lets make sure the model works\n",
210210
"model = MoneyModel(n=100, width=100, height=10, seed=10)\n",
211-
"for _ in range(20):\n",
212-
" model.step()\n",
211+
"model.run_for(20)\n",
213212
"\n",
214213
"\n",
215214
"data = model.datacollector.get_agent_vars_dataframe()\n",

docs/tutorials/5_visualization_dynamic_agents.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@
170170
"source": [
171171
"# Lets make sure the model works\n",
172172
"model = MoneyModel(100, 10, 10)\n",
173-
"for _ in range(20):\n",
174-
" model.step()\n",
173+
"model.run_for(20)\n",
175174
"\n",
176175
"\n",
177176
"data = model.datacollector.get_agent_vars_dataframe()\n",

docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@
169169
"source": [
170170
"# Lets make sure the model works\n",
171171
"model = MoneyModel(100, 10, 10)\n",
172-
"for _ in range(20):\n",
173-
" model.step()\n",
172+
"model.run_for(20)\n",
174173
"\n",
175174
"\n",
176175
"data = model.datacollector.get_agent_vars_dataframe()\n",

0 commit comments

Comments
 (0)