Skip to content

Commit 4dc65a3

Browse files
authored
Migration guide: Update automatic unique_id assignment with clearer examples (#2419)
Improve the automatic unique_id assignment section in the migration guide with clearer before/after examples. Show both positional and keyword argument cases for agent initialization and super() calls. Add important notes about deprecation warnings and custom ID storage.
1 parent 4215706 commit 4dc65a3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

docs/migration_guide.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,32 @@ In Mesa 3.0, `unique_id` for agents is now automatically assigned, simplifying a
7474
1. Remove `unique_id` from agent initialization:
7575
```python
7676
# Old
77+
agent = MyAgent(unique_id=unique_id, model=self, ...)
78+
agent = MyAgent(unique_id, self, ...)
7779
agent = MyAgent(self.next_id(), self, ...)
7880

7981
# New
82+
agent = MyAgent(model=self, ...)
8083
agent = MyAgent(self, ...)
8184
```
82-
2. `Model.next_id()` is deprecated and will always return 0. Remove any calls to this method.
83-
3. `unique_id` is now unique relative to a Model instance and starts from 1.
84-
4. If you previously used custom `unique_id` values, you'll need to store that information in a separate attribute.
85-
5. Deprecation warning: Initializing an agent with two arguments (`unique_id` and `model`) will raise a warning. The `unique_id` argument will be ignored.
85+
86+
2. Remove `unique_id` from Agent super() call:
87+
```python
88+
# Old
89+
class MyAgent(Agent):
90+
def __init__(self, unique_id, model, ...):
91+
super().__init__(unique_id, model)
92+
93+
# New
94+
class MyAgent(Agent):
95+
def __init__(self, model, ...):
96+
super().__init__(model)
97+
```
98+
99+
3. Important notes:
100+
- `unique_id` is now automatically assigned relative to a Model instance and starts from 1
101+
- `Model.next_id()` is removed
102+
- If you previously used custom `unique_id` values, store that information in a separate attribute
86103

87104
- Ref: [PR #2226](https://github.com/projectmesa/mesa/pull/2226), [PR #2260](https://github.com/projectmesa/mesa/pull/2260), Mesa-examples [PR #194](https://github.com/projectmesa/mesa-examples/pull/194), [Issue #2213](https://github.com/projectmesa/mesa/issues/2213)
88105

0 commit comments

Comments
 (0)