-
Notifications
You must be signed in to change notification settings - Fork 925
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
track unique_id automatically #2260
Conversation
Performance benchmarks:
|
What I don't understand, but unfortunately can't test right now: doesn't this keep increasing the counter indefinitely, even across models? So if I run the same model twice without restarting my kernel, won't the ids be different? |
I would like all maintainers to check our Matrix chat before moving further. |
I continued some work on this, mainly to understand how breaking automatic counting actually is. And it indeed creates a massive mess throughout the various tests, including very old test code that probably has not been touched in a long while (e.g., the test code of the schedulers). I did 3 things here
Like in #2226, The code here still accepts a unique_id and raises a warning. If you remove that, the number of tests that fails explodes again. There are many tests that use custom unique ids (so not even model.next_id. Not sure where this leaves #2226 or this one. It seems there is broad agreement on having unique_id assigned automatically in MESA 3, but it is equally clear that this involves quite some more work depending on how breaking this new feature is implemented. |
Performance benchmarks:
|
for more information, see https://pre-commit.ci
makes this consistent with projectmesa#2226
for more information, see https://pre-commit.ci
Performance benchmarks:
|
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.
Overall looks good, few minor things.
for more information, see https://pre-commit.ci
Great work, thanks! |
I like the idea of Any obvious clean way around this? Making my networkx graph "one node larger" and ignoring its node #0 to accommodate Mesa is a hack I'm not prepared to consider at this point. I'm wondering if there's any easy option to putting in a bunch of logic in my code to subtract 1 and add 1 to IDs at various points where I switch back and forth between working with "agent k" vs. "graph node k-1". |
The easiest thing would be to add a @property
def node_id(self):
return self.unique_id - 1
|
This PR ensures that the
unique_id
in Agent is assigned automatically. It draws on work done in #2226. In short, this PR makes 3 changes:Agent.unique_id
is assigned automatically and no longer used as an argument to Agent. A deprecation warning is issued if the Agent is instantiated with 2 arguments (unique_id
andmodel
). The value passed forunique_id
is ignored in favor of the new system. This last point is in line with Automatically assignunique_id
to Agents #2226.Model.next_id()
raises a deprecation warning and always return 0.unique_id
is unique relative to a Model instance. Internally, Agent has a class-level attribute_ids
. This attribute is a dictionary with the Model instance as key and the "generator" forunique_id
as value.All unit tests and benchmarks work with the new structure. They raise no deprecation warnings.
examples, tutorials, etc., still need to be updated to be consistent with this change.
Resolves #2213.