aegis_sim.variables

 1import numpy as np
 2
 3
 4def init(self, custom_config_path, pickle_path, RANDOM_SEED):
 5    self.steps = 1
 6    self.custom_config_path = custom_config_path
 7    self.pickle_path = pickle_path
 8    self.random_seed = np.random.randint(1, 10**6) if RANDOM_SEED is None else RANDOM_SEED
 9    # TODO: Consolidate RNG usage across the codebase. Currently both the legacy
10    # global RNG (np.random.*) and the new-style Generator (variables.rng) are used
11    # in different modules. Both are seeded here so simulations are reproducible, but
12    # the split makes it easy to accidentally shift the random stream during refactors.
13    # Affected modules using legacy np.random: population.initialize, matingmanager,
14    # abiotic, envdrift, recombination, gpm_decoder, popgenstats.
15    np.random.seed(self.random_seed)
16    self.rng = np.random.default_rng(self.random_seed)
17
18
19def restore_from_checkpoint(self, checkpoint):
20    """Restore variables state from a Checkpoint object."""
21    self.steps = checkpoint.step
22    self.custom_config_path = checkpoint.custom_config_path
23    self.pickle_path = None
24    self.random_seed = checkpoint.random_seed
25    # Restore both RNG states
26    np.random.set_state(checkpoint.legacy_rng_state)
27    self.rng = np.random.default_rng()
28    self.rng.bit_generator.state = checkpoint.rng_state
def init(self, custom_config_path, pickle_path, RANDOM_SEED):
 5def init(self, custom_config_path, pickle_path, RANDOM_SEED):
 6    self.steps = 1
 7    self.custom_config_path = custom_config_path
 8    self.pickle_path = pickle_path
 9    self.random_seed = np.random.randint(1, 10**6) if RANDOM_SEED is None else RANDOM_SEED
10    # TODO: Consolidate RNG usage across the codebase. Currently both the legacy
11    # global RNG (np.random.*) and the new-style Generator (variables.rng) are used
12    # in different modules. Both are seeded here so simulations are reproducible, but
13    # the split makes it easy to accidentally shift the random stream during refactors.
14    # Affected modules using legacy np.random: population.initialize, matingmanager,
15    # abiotic, envdrift, recombination, gpm_decoder, popgenstats.
16    np.random.seed(self.random_seed)
17    self.rng = np.random.default_rng(self.random_seed)
def restore_from_checkpoint(self, checkpoint):
20def restore_from_checkpoint(self, checkpoint):
21    """Restore variables state from a Checkpoint object."""
22    self.steps = checkpoint.step
23    self.custom_config_path = checkpoint.custom_config_path
24    self.pickle_path = None
25    self.random_seed = checkpoint.random_seed
26    # Restore both RNG states
27    np.random.set_state(checkpoint.legacy_rng_state)
28    self.rng = np.random.default_rng()
29    self.rng.bit_generator.state = checkpoint.rng_state

Restore variables state from a Checkpoint object.