meiosis
meiosis_for_one_cross
meiosis_for_one_cross (key:<function PRNGKey>, mother_geno:jax.Array, father_geno:jax.Array, n_chr:int, gen_map:jax.Array, v_interference:float)
*Creates a single diploid progeny’s genotype from two parents’ genotypes by simulating meiosis for all chromosomes in parallel.
This function is a high-performance kernel designed to be compiled by JAX.
— JAX Implementation Notes — This function showcases the composition of JAX’s core transformations for maximum performance on parallel architectures (like GPUs).
vmap
for Parallelism: The core logic of creating a gamete for a single chromosome is defined in_create_gamete
.vmap
is used to automatically “vectorize” this function, applying it across all chromosomes of a parent simultaneously. Thein_axes
argument is critical for this:in_axes=(0, 0, 0, None)
tellsvmap
to map over the first axis (the chromosome axis) of thekeys
,parent_geno
, andgen_map
arrays, while broadcasting the singlev_interference
value to all parallel executions. This avoids unnecessary memory duplication.
jit
for Fused Compilation: The entire function is JIT-compiled. JAX is able to “fuse” thevmap
operations and the finaljnp.stack
into a single, highly-optimized kernel. This minimizes overhead from launching separate computations and maximizes hardware utilization.Static Arguments: The number of chromosomes,
n_chr
, is used to determine the number of random keys to split viajax.random.split(key, n_chr)
. Because the shape of a JAX array must be known at compile time,n_chr
cannot be a dynamic (traced) value. It is therefore marked as a static argument, meaning JAX will re-compile this function ifn_chr
changes.
Args: key: A JAX random key. mother_geno: The mother’s genotype. Shape: (nChr, ploidy, nLoci)
. father_geno: The father’s genotype. Shape: (nChr, ploidy, nLoci)
. n_chr: The number of chromosomes. Must be a static integer. gen_map: The genetic map defining locus positions for each chromosome. v_interference: The interference parameter for the Gamma process.
Returns: The progeny’s complete diploid genotype. Shape: (nChr, ploidy, nLoci)
.*