From 273f2c114a275241161eb1702cfda5fedc9c19dd Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Sat, 12 Oct 2024 12:25:36 +0200 Subject: [PATCH 1/2] Update migration_guide.md --- docs/migration_guide.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/migration_guide.md b/docs/migration_guide.md index 4741b8fb28b..7d9dc10a239 100644 --- a/docs/migration_guide.md +++ b/docs/migration_guide.md @@ -42,15 +42,16 @@ The `mesa.flat` namespace is removed. Use the full namespace for your imports. ### Mandatory Model initialization with `super().__init__()` -In Mesa 3.0, it is now mandatory to call `super().__init__()` when initializing your model class. This ensures that all necessary Mesa model variables are correctly set up and agents are properly added to the model. +In Mesa 3.0, it is now mandatory to call `super().__init__()` when initializing your model class. This ensures that all necessary Mesa model variables are correctly set up and agents are properly added to the model. The convention in Python is to extract the arguments and keyword arguments you need in your `__init__` and pass on the rest via `super`. To control the random number generation, `mesa.Model` relies on the `seed` keyword argument. Make sure all your model classes explicitly call `super().__init__()` in their `__init__` method: ```python class MyModel(mesa.Model): - 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! # Your model initialization code here + # this code uses some_arg_I_need and my_init_kwarg ``` This change ensures that all Mesa models are properly initialized, which is crucial for: From c02b7b9c7f5f00d629cef904d008d59cae00aa5a Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 17 Oct 2024 07:48:10 +0200 Subject: [PATCH 2/2] Update migration_guide.md --- docs/migration_guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/migration_guide.md b/docs/migration_guide.md index 7d9dc10a239..c3ff5e7217b 100644 --- a/docs/migration_guide.md +++ b/docs/migration_guide.md @@ -42,14 +42,14 @@ The `mesa.flat` namespace is removed. Use the full namespace for your imports. ### Mandatory Model initialization with `super().__init__()` -In Mesa 3.0, it is now mandatory to call `super().__init__()` when initializing your model class. This ensures that all necessary Mesa model variables are correctly set up and agents are properly added to the model. The convention in Python is to extract the arguments and keyword arguments you need in your `__init__` and pass on the rest via `super`. To control the random number generation, `mesa.Model` relies on the `seed` keyword argument. +In Mesa 3.0, it is now mandatory to call `super().__init__()` when initializing your model class. This ensures that all necessary Mesa model variables are correctly set up and agents are properly added to the model. If you want to control the seed of the random number generator, you have to pass this as a keyword argument to super as shown below. Make sure all your model classes explicitly call `super().__init__()` in their `__init__` method: ```python class MyModel(mesa.Model): - 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! + def __init__(self, some_arg_I_need, seed=None, some_kwarg_I_need=True): + super().__init__(seed=seed) # Calling super is now required, passing seed is highly recommended # Your model initialization code here # this code uses some_arg_I_need and my_init_kwarg ```