Skip to content

Migration guide: Update automatic unique_id assignment examples #2419

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Oct 25, 2024

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.

It now reads:

Automatic assignment of unique_id to Agents

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.

  1. Remove unique_id from agent initialization:

    # Old
    agent = MyAgent(unique_id=unique_id, model=self, ...)
    agent = MyAgent(unique_id, self, ...)
    agent = MyAgent(self.next_id(), self, ...)
    
    # New
    agent = MyAgent(model=self, ...)
    agent = MyAgent(self, ...)
  2. Remove unique_id from Agent super() call:

    # Old
    class MyAgent(Agent):
        def __init__(self, unique_id, model, ...):
            super().__init__(unique_id, model)
    
    # New
    class MyAgent(Agent):
        def __init__(self, model, ...):
            super().__init__(model)
  3. Important notes:

    • unique_id is now automatically assigned relative to a Model instance and starts from 1
    • Model.next_id() is removed
    • If you previously used custom unique_id values, store that information in a separate attribute

…xamples

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.
@EwoutH EwoutH added the docs Release notes label label Oct 25, 2024
@EwoutH EwoutH added this to the v3.0 milestone Oct 25, 2024
@EwoutH EwoutH requested review from quaquel and tpike3 October 25, 2024 10:07
Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EwoutH EwoutH merged commit 4dc65a3 into main Oct 25, 2024
2 checks passed
@EwoutH EwoutH deleted the migration_guide_agent_unique_id branch October 26, 2024 13:22
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
docs Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants