Skip to content

Commit

Permalink
Update migration_guide.md (#2347)
Browse files Browse the repository at this point in the history
* Update migration_guide.md

* Update migration_guide.md
  • Loading branch information
quaquel authored Oct 17, 2024
1 parent 3054bac commit 42880ac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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, *args, **kwargs):
super().__init__() # 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
```

This change ensures that all Mesa models are properly initialized, which is crucial for:
Expand Down

0 comments on commit 42880ac

Please sign in to comment.