-
Notifications
You must be signed in to change notification settings - Fork 928
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
Update migration_guide.md #2347
Conversation
docs/migration_guide.md
Outdated
def __init__(self, *args, **kwargs): | ||
super().__init__() # This is now required! | ||
def __init__(self, some_arg_I_need, *args, seed=None, my_init_kwarg=True, **kwargs): | ||
super().__init__(*args, seed=seed, **kwargs) # This is now required! |
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.
Is the *args, **kwargs
here essential for the Model class?
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.
not for the class itself but for proper use of super. See my remark above the code on this.
I found the One problem, why we have to call Maybe that doesn't have to be that way. What is if we recommend users to put their setup code into a differently named method, so the In our model, we now call a new class Model:
def __init__(self, seed: Optional[float] = None, **kwargs: Any) -> None:
self.running = True
self.steps: int = 0
self._seed = seed if seed is not None else random.random()
self.random = random.Random(self._seed)
self._setup_agent_registration()
# Remove 'seed' from kwargs before passing to setup
kwargs.pop('seed', None)
# Call user-defined setup
self.setup(**kwargs)
def setup(self, **kwargs: Any) -> None:
"""
User-defined setup method.
Subclasses should override this method instead of __init__.
"""
pass We request users to override class MyModel(Model):
def setup(self, param1: int, param2: str):
self.param1 = param1
self.param2 = param2
# Additional setup logic...
def step(self):
# Model step logic...
pass
# Usage
model = MyModel(seed=42, param1=10, param2="example") Which I find to look extremely clean. As an additional advantage, we can now more easily modify the order of Model arguments, rename ones or add new ones without breaking user models, because we can handle all that (and throw warnings if necessary, etc. We never have to be afraid an user doesn't call the This is the most breaking change of changes, but I think it allows for so much flexibility in the future that it might be worth it. |
I am not against shifting to having a model setup method, but that probably deserves its own discussion rather than discuss it here in this PR. This PR really is about making sure seed is handled correctly in the migration guide. |
@EwoutH in line with our conversation, I simplified the migration guide and not bother with the *args and *kwargs and just explicitly only pass |
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.
Thanks for cleaning it up!
This is a minor expansion to using
super
inModel
. I explicate how to handle the seed keyword argument, and briefly state something about how to handle arguments and keyword arguments via super.