Skip to content

Migration guide: Add note about removing Agents from the model #2326

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 25, 2024

Conversation

EwoutH
Copy link
Member

@EwoutH EwoutH commented Sep 25, 2024

Add note about removing Agents from the model to the Migration guide.

It now reads:

  1. Instead of self.schedule.add() and self.schedule.remove(), agents are now automatically added to and removed from the model's AgentSet (model.agents) when they are created or removed.
    • You still need to remove the Agent itself. Use Agent.remove() for that. Often you would:
      • Replace self.schedule.remove(agent) with agent.remove() (in the Model)
      • Replace self.model.schedule.remove(self) with self.remove() (in the Agent)

Add note about removing Agents from the model
@EwoutH EwoutH added docs Release notes label ignore-for-release PRs that aren't included in the release notes labels Sep 25, 2024
@EwoutH EwoutH requested a review from quaquel September 25, 2024 11:05
@Corvince
Copy link
Contributor

Not related to the PR itself, but I find the semantics here a bit confusing. Why should I have to call agent.remove if I want to remove it from model.agents? And why can't I do agent.add()? I think we should actually remove agent.remove because of its unclear semantics. Thus, removing an agent can mean two things

  1. del agent, in which case it is automatically removed from model.agents (right?)
  2. model.deregister_agent(agent). In case I want to remove it from the model, but keep it around, maybe to add it back later via model.register_agent. This would mean we should keep those methods public (Performance enhancements for Model.agents #2251 (comment))

@quaquel
Copy link
Member

quaquel commented Sep 25, 2024

del agent, in which case it is automatically removed from model.agents (right?)

I don't think that will work. Del removes a reference from a namespace nothing more and there is AFAIK (and just checked) no magic method that can used to change the behavior of del. __del__ and __delete__ are not tied to del and do subtle different things.

@EwoutH EwoutH merged commit f80ec48 into main Sep 25, 2024
2 checks passed
@quaquel quaquel deleted the mig_guide_remove_note branch October 30, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Release notes label ignore-for-release PRs that aren't included in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants