-
Notifications
You must be signed in to change notification settings - Fork 988
Require Mesa models to be initialized with super().__init__()
#2218
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
Conversation
Remove the workaround for when the model super has not been called, and thereby require Mesa models to be initialized with `super.__init__()`. This warning was present since 2.3.0, so there has been some time to update for existing users.
The experimental_warning_given variable in PropertyLayer was named incorrectly, probably while copying from the AgentSet. This commit fixes that.
Performance benchmarks:
|
mesa/agent.py
Outdated
FutureWarning, | ||
stacklevel=2, | ||
) | ||
self.model.agents_[type(self)][self] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about try-except
then raise error, instead of a warning, for now? I'm not sure if some people do read the release note for such a subtle change in the way they have to do __init__()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a bad idea, but with Mesa 3.0 I would like to clean the codebase and remove it altogether.
In the 3.0 release notes we can put a note to first update to the latest Mesa 2.x, which also contains this warning (and it now has been in there for all 2.2.x and 2.3.x releases).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about it some more, and I think you're actually right. It's better to throw an useful error than let it crash without any guidance.
You should always run super().__init__() after initializing your model class that inherits from Mesa Model.
Added `from err` to the `raise RuntimeError` line. This links the `RuntimeError` to the original `AttributeError`, making it clear that the new exception was raised because of the `AttributeError` caught in the `try` block.
Remove the workaround for when the model super has not been called, and thereby require Mesa models to be initialized with
super().__init__()
.This is needed to correctly add Agents to the model and setup other Mesa model variables.
This warning was present since Mesa 2.2.0 (#1928), so there has been some time to update for existing users.
This PR contains a second commit that names experimental warning in PropertyLayer correctly in space.py.