gras 2.0.1

A Genetic Programming framework for Neural Architecture Search in Rust
Documentation
//! Deterministic seed derivation — the one place child-seed math lives.

/// Deterministic child-seed derivation: multiply by golden ratio for spread.
pub fn derive_seed(base: u64, i: usize) -> u64 {
    base.wrapping_add((i as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15))
}

/// xxh3 of a topology's canonical JSON — 16 hex chars, deterministic.
/// topology's identity everywhere it appears (net files, race snapshots).
pub fn topo_hash(topology_json: &str) -> String {
    format!(
        "{:016x}",
        xxhash_rust::xxh3::xxh3_64(topology_json.as_bytes())
    )
}

/// The run-wide seed every net's INITIAL WEIGHTS are drawn from — the same for founders, children
/// and immigrants.
pub fn weight_seed(run_seed: u64) -> usize {
    derive_seed(run_seed, WEIGHT_INIT_ORDINAL) as usize
}

/// Ordinal the shared weight seed lives at: far above every `clock * 1024 + child_idx`
/// roll and every founder ordinal, so a structural seed can never collide
const WEIGHT_INIT_ORDINAL: usize = usize::MAX / 2;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn is_deterministic() {
        assert_eq!(derive_seed(42, 0), derive_seed(42, 0));
        assert_eq!(derive_seed(42, 7), derive_seed(42, 7));
    }

    #[test]
    fn spreads_indices_apart() {
        assert_ne!(derive_seed(42, 0), derive_seed(42, 1));
        assert_ne!(derive_seed(42, 1), derive_seed(42, 2));
        // Different bases never collide at the same index.
        assert_ne!(derive_seed(41, 0), derive_seed(42, 0));
    }
}