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    self.lineage_counter = 0
18
19
20def next_lineage_ids(n):
21    """Reserve and return n consecutive lineage IDs starting from the current counter.
22
23    Module-level singleton state — call only after variables.init().
24    """
25    import aegis_sim.variables as v
26    start = v.lineage_counter
27    v.lineage_counter += n
28    return np.arange(start, start + n, dtype=np.int64)
29
30
31def restore_from_checkpoint(self, checkpoint):
32    """Restore variables state from a Checkpoint object."""
33    self.steps = checkpoint.step
34    self.custom_config_path = checkpoint.custom_config_path
35    self.pickle_path = None
36    self.random_seed = checkpoint.random_seed
37    # Restore both RNG states
38    np.random.set_state(checkpoint.legacy_rng_state)
39    self.rng = np.random.default_rng()
40    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)
18    self.lineage_counter = 0
def next_lineage_ids(n):
21def next_lineage_ids(n):
22    """Reserve and return n consecutive lineage IDs starting from the current counter.
23
24    Module-level singleton state — call only after variables.init().
25    """
26    import aegis_sim.variables as v
27    start = v.lineage_counter
28    v.lineage_counter += n
29    return np.arange(start, start + n, dtype=np.int64)

Reserve and return n consecutive lineage IDs starting from the current counter.

Module-level singleton state — call only after variables.init().

def restore_from_checkpoint(self, checkpoint):
32def restore_from_checkpoint(self, checkpoint):
33    """Restore variables state from a Checkpoint object."""
34    self.steps = checkpoint.step
35    self.custom_config_path = checkpoint.custom_config_path
36    self.pickle_path = None
37    self.random_seed = checkpoint.random_seed
38    # Restore both RNG states
39    np.random.set_state(checkpoint.legacy_rng_state)
40    self.rng = np.random.default_rng()
41    self.rng.bit_generator.state = checkpoint.rng_state

Restore variables state from a Checkpoint object.