SimParam

The SimParam class is the cornerstone of a simulation, acting as a global container for parameters that are not specific to any single Population but govern the rules of the entire simulation. Just as the Population class holds the state of individuals, SimParam holds the “genetic laws” of the simulated world, such as trait architecture, genetic maps, and SNP chip definitions.

source

SimParam

 SimParam (gen_map:jax.Array, centromere:jax.Array, ploidy:int,
           traits:Optional[ForwardRef('TraitCollection')]=None,
           snp_chips:List[ForwardRef('LociMap')]=<factory>,
           founderPop:Optional[ForwardRef('Population')]=None,
           sexes:str='no', recomb_params:tuple=(2.6, 0.0, 0.0),
           n_threads:int=1, track_pedigree:bool=False,
           track_recomb:bool=False, last_id:int=0,
           pedigree:Optional[jax.Array]=None,
           var_e:Optional[jax.Array]=None)

*A container for all global simulation parameters.

— JAX JIT Compilation Notes —

This class is a JAX Pytree, but it contains a mix of dynamic JAX arrays and static Python-native objects. When an instance of SimParam is passed to a JIT-compiled function, the function is compiled specifically for the values of the static attributes.

  • Dynamic Attributes (Tracable): These are jnp.ndarrays. Their values can change between function calls without causing re-compilation. Includes: gen_map, centromere, founderPop, pedigree, var_e.

  • Static Attributes (Non-Tracable): These are all other attributes (int, str, bool, list, tuple, and custom classes). If any of these attributes change value between calls to a JIT-compiled function, it will trigger a re-compilation of that function.

    This is generally desired behavior for simulation parameters, but care must be taken not to modify them inside performance-critical loops. The static attributes are: ploidy, traits, snp_chips, sexes, recomb_params, n_threads, track_pedigree, track_recomb, last_id.*