-
Notifications
You must be signed in to change notification settings - Fork 929
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
Allow user models to assign Model.agents
for now, but add warning
#1976
Conversation
fix in case user is using model.agents
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1976 +/- ##
==========================================
- Coverage 79.27% 79.03% -0.24%
==========================================
Files 16 16
Lines 1298 1307 +9
Branches 291 293 +2
==========================================
+ Hits 1029 1033 +4
- Misses 230 233 +3
- Partials 39 41 +2 ☔ View full report in Codecov by Sentry. |
Thanks, this looks good, just 2 comments and a failing pre-commit ci |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
me being stupid
Thanks a lot for this effort. I will leave the code review to others, but conceptually, this looks really good.
If an user is advanced enough to do that, they will check the source code on problems, and know how to find us. So not a problem.
Also not a problem. Actually, maybe we can add that as a policy. So LGTM conceptually. |
Model.agents
for now, but add warning
Thats an excellent idea! If we just document this well enough this should prevent some headaches |
Thanks! Will open a discussion or PR for it somewhere. If this can be validated on multiple custom models that currently define @rht I would also like a party not currently involved in this PR to validate it, could you do that? |
Hi @NickGotts! This PR should have solved your issue migrating your model from Mesa 2.1 to 2.2. Could you maybe test if the model you had for 2.1.5 now works on the latest Mesa version? You can install the latest development version of Mesa that includes this PR with:
|
I would be careful with the wording on this. It means that any custom properties, which often involve the use of underscore variable names can freely be broken by MESA. To be clear, I am fine with the basic idea. What matters is how to communicate it in a clear way. |
Yes communication will be key here. We shouldn't introduce this before 3.0, but I think the restriction should be fine. Users can still use custom properties, just not private ones. Alternatively, and I am just thinking about this now, we could just have a single |
Oh I think my suggested name could trigger some name mangling? I am not up to date on this topic, maybe this would be good or it would be bad, but it wasn't intentional (albeit maybe subconsciously intended) |
A bit too late for me to comment, but |
Even if you were to make an exception and declare |
The use of a trailing underscore can have several meanings. In PEP8 it is suggested as a way of avoiding naming conflicts with Python keywords. In scikit_learn, it is used to denote attributes that are only available after a model has been fitted. So there is precedence in Python to using underscorers (leading and trailing) to signal to the user that there is something going on that you want to be careful with. Moreover, this PR is really meant as a temporary fix to help users migrate their code away from using |
With this merged we can do the 2.2.2 release now right? Anything else we want to have cherry picked? |
As an example the "how to merge" discussion, this PR would have been easier to cherry pick to a maintenance branch if it was squashed to a single commit. Almost no information would have been lost, since that's all here in the PR discussion anyway. |
Fix in case the user is using
model.agents
.The fix consists of 3 things
model.agents
. If used, this triggers a warning. Whatever the user wants to assign is assigned tomodel._agents
model._agents
tomodel.agents_
. I deem it unlikely that this label is being used by anyone.model.agents
. It checks ifmodel._agents
exists in which case the user is usingmodel.agents
.I have not included full name mangling, but we can do so if we want to be extra sure that there are no classes with user code. But this code works as intended. All current tests pass and I tested with the example models to see what happens if I define
model.agents
myself.There are 2 corner cases left. First, if the user is using descriptors for
model.agents
this won't work. Second, if the user is usingmodel._agents
and/ormodel._agents
. The latter could be fixed by full name mangling. The first is not fixable.