Skip to content

Commit

Permalink
Correct unique_id in migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Sep 20, 2024
1 parent 5d0c116 commit 078fe54
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions docs/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,22 @@ RuntimeError: The Mesa Model class was not initialized. You must explicitly init


### Automatic assignment of `unique_id` to Agents
In Mesa 3.0, the `unique_id` is now automatically assigned to agents upon creation. This change simplifies agent initialization and ensures uniqueness of agent identifiers.
In Mesa 3.0, `unique_id` for agents is now automatically assigned, simplifying agent creation and ensuring unique IDs across all agents in a model.

_Key changes_
1. Agent initialization:
- Old: `Agent(unique_id, model, ...)`
- New: `Agent(model, ...)`
2. The `Model.next_id()` method is deprecated and will be removed in a future version.
3. The `Model.current_id` counter now starts at 0 instead of 1.

_Migration steps_
1. Update agent creation calls:
1. Remove `unique_id` from agent initialization:
```python
# Old
agent = MyAgent(self.next_id(), self, ...)

# New
agent = MyAgent(self, ...)
```
2. Remove any custom logic for managing `unique_id` assignments.
3. If you were using `Model.next_id()` for purposes other than agent creation, replace it with alternative logic.
4. Be aware that agent IDs now start at 0 instead of 1, which may affect some model logic or data analysis.
2. `Model.next_id()` is deprecated and will always return 0. Remove any calls to this method.
3. `unique_id` is now unique relative to a Model instance and starts from 1.
4. If you previously used custom `unique_id` values, you'll need to store that information in a separate attribute.
5. Deprecation warning: Initializing an agent with two arguments (`unique_id` and `model`) will raise a warning. The `unique_id` argument will be ignored.

- Ref: [PR #2226](https://github.com/projectmesa/mesa/pull/2226), [PR #2260](https://github.com/projectmesa/mesa/pull/2226), Mesa-examples [PR #194](https://github.com/projectmesa/mesa-examples/pull/194)
- 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)


### AgentSet and `Model.agents`
Expand Down

0 comments on commit 078fe54

Please sign in to comment.