-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Regarding this TODO in the documentation:
TODO: Have the schedulers use the model's randomizer, to keep random number seeds consistent and allow for replication.
How about letting the model have a random state (using numpy) which the scheduler can then call? I.e.,
- in the model init:
self.random_state = numpy.random.RandomState(seed) - in the schedule step:
self.model.random_state.shuffle(self.agents) - alternatively, in the schedule init:
self.random_state = self.model.random_state(which I assume will make a copy; not important for reproducibility but it might be nicer to use the model's random state directly)
Some things I ran into while trying this:
- It would now be required for new models to call the
super().__init__()method (see Example models should call super in init #248 ) to make sure that models have a random state. Alternatively, we could put a check in the scheduler if the model has a random state, and if not, create a local one. The problem is that then the seed can't be specified, or, if it can be passed to the scheduler, it will only have effect if the model doesn't have a random state, which seems weird. - When testing this, test_time.py will crash:
- First error is because
super().__init__()is not called (see above), and the scheduler cannot callself.model.random_state - Another error occurs when
mesa.time.random.shuffleis called in the test. It will either complain that the import isn't there (I removed it,import randomin time.py is not necessary anymore), or the following happens: test_random_activation_step_shufflesandtest_shuffle_shuffles_agentscrash. I guess it's because the way random calls are made changed (it's notmesa.time.random.shuffle, but via np.random). Not sure how to fix this.
- First error is because