Let a genome decide, and report where each axis actually acts
M3.6 joins the M3 pieces: strategy_for derives a StrategyConfig from the metabolic budget, founders are pre-diverged variants admitted to the lineage archive, and evo-sim --ensemble runs them over a resource and temperature grid with every cell's seeds split in half and never merged. ADR-0029's driver is untouched, so the M2.6 fingerprint still holds. Nothing mutates during an episode, so NPC mutation stays open. Three things measurement found, kept rather than smoothed over. The report aggregates were default-initialized, leaving their scalar counters indeterminate. The resource level never reaches strategy derivation at all, so the header now says where each axis acts instead of claiming both shape a strategy. And the resource axis is not monotonic: a sweep peaks near 8000 femtograms and falls away on both sides, because only one consumer may bite a target per tick, so scarcity concentrates mass into individuals that reach the threshold while abundance spreads the same income too thin. The test asserts that an axis moves the outcome and never a direction; an earlier draft asserted a direction that held at two cells and the sweep disproves. Earning a birth at all required pinning the investment fraction to the schema floor, since intake scales with surface and investment with mass. That is a finding about the ADR-0031/0032 cost model, now the second priority in STATUS. Release 33/33, analysis, ASan 33/33 and clang-format all ran and passed here; no Clang or GCC compile happens on this host, so Linux CI is still the first result for this increment. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
#include "evo/processes/ensemble.hpp"
|
||||
|
||||
#include "evo/biology/mutation.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace evo::processes {
|
||||
namespace {
|
||||
using biology::Genome;
|
||||
|
||||
constexpr std::uint32_t millikelvin_per_kelvin = 1000U;
|
||||
// Founders diverge once, under one reference environment, so every cell of the
|
||||
// gradient compares the same set of strategies rather than a set the cell shaped.
|
||||
constexpr std::uint32_t reference_temperature = 293'150U;
|
||||
constexpr std::uint64_t reference_material = 1'000'000'000U;
|
||||
|
||||
accounting::Inventory pooled(std::uint64_t value) noexcept {
|
||||
return {{value},
|
||||
{accounting::Femtograms{value}, accounting::Femtograms{value},
|
||||
accounting::Femtograms{value}, accounting::Femtograms{value}}};
|
||||
}
|
||||
std::uint64_t mix(std::uint64_t hash, std::uint64_t value) noexcept {
|
||||
return hash ^ (value + 0x9e3779b97f4a7c15ULL + (hash << 6U) + (hash >> 2U));
|
||||
}
|
||||
biology::EnvironmentState conditions(const GradientCell& cell) noexcept {
|
||||
return {cell.temperature_millikelvin, pooled(cell.nutrients)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<std::vector<Genome>, EcosystemError>
|
||||
diverge_founders(const Genome& ancestor, std::size_t wanted, std::uint64_t seed) {
|
||||
if (wanted == 0 || wanted > biology::max_candidates + 1) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
std::vector<Genome> founders{ancestor};
|
||||
if (wanted == 1) {
|
||||
return founders;
|
||||
}
|
||||
const biology::MutationContext context{
|
||||
seed, 1,
|
||||
1, static_cast<std::uint16_t>(wanted - 1),
|
||||
{1000, 0}, {reference_temperature, pooled(reference_material)}};
|
||||
const auto offer = biology::mutation_candidates(ancestor, context);
|
||||
if (!offer || offer->candidates.size() + 1 < wanted) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
for (std::size_t index = 0; index + 1 < wanted; ++index) {
|
||||
const auto successor = biology::select_mutation(
|
||||
ancestor, context, *offer, offer->candidates[index].operator_id,
|
||||
ancestor.id() + index + 1, ancestor.origin_event() + index + 1);
|
||||
if (!successor) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
founders.push_back(*successor);
|
||||
}
|
||||
return founders;
|
||||
}
|
||||
|
||||
std::expected<EnsembleReport, EcosystemError>
|
||||
run_ensemble(biology::LineageArchive& archive, std::span<const Genome> founders,
|
||||
const EcosystemConfig& base, const EnsembleConfig& plan, std::uint64_t seed) {
|
||||
if (founders.empty() || founders.size() > max_strategies || plan.gradient.empty() ||
|
||||
plan.seeds_per_cell < 2 || plan.tick_limit == 0 || plan.base_lifespan == 0) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
for (const auto& genome : founders) {
|
||||
if (!archive.admit(genome)) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
}
|
||||
EnsembleReport report{};
|
||||
std::uint64_t organism_identity = 0;
|
||||
std::uint64_t ordinal = 0;
|
||||
for (const auto& cell : plan.gradient) {
|
||||
const auto environment = conditions(cell);
|
||||
CellReport measured{};
|
||||
measured.cell = cell;
|
||||
std::vector<StrategyConfig> strategies;
|
||||
for (const auto& genome : founders) {
|
||||
const auto phenotype = biology::derive_phenotype(genome, {1000, 0}, environment);
|
||||
if (!phenotype) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
// The harness shortens scheduled life under thermal stress, which is
|
||||
// what makes the temperature axis consequential. A scheduling rule,
|
||||
// not a mortality model, and no contract knows about it.
|
||||
const auto lost = phenotype->thermal_shortfall / millikelvin_per_kelvin *
|
||||
plan.lifespan_lost_per_kelvin;
|
||||
const auto lifespan = lost >= plan.base_lifespan ? 1U : plan.base_lifespan - lost;
|
||||
// An explicit experimental budget, as ADR-0026 requires, scaled so no
|
||||
// strategy is excluded from acting by the size of the handout.
|
||||
const auto budget = biology::metabolic_budget(genome, {1000, 0}, environment);
|
||||
if (!budget) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
const auto strategy = strategy_for(genome, {1000, 0}, environment,
|
||||
budget->reproduction_investment, lifespan);
|
||||
if (!strategy) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
strategies.push_back(*strategy);
|
||||
StrategyOutcome blank{};
|
||||
blank.genome = genome.id();
|
||||
blank.scheduled_lifespan = lifespan;
|
||||
blank.thermal_shortfall = phenotype->thermal_shortfall;
|
||||
measured.first_half.push_back(blank);
|
||||
measured.second_half.push_back(blank);
|
||||
}
|
||||
for (std::uint64_t index = 0; index < plan.seeds_per_cell; ++index) {
|
||||
auto config = base;
|
||||
config.tick_limit = plan.tick_limit;
|
||||
config.nutrients = pooled(cell.nutrients).matter;
|
||||
auto episode = EcosystemEpisode::create(config, strategies, seed + ordinal);
|
||||
if (!episode) {
|
||||
return std::unexpected{episode.error()};
|
||||
}
|
||||
++ordinal;
|
||||
auto& half =
|
||||
index * 2 < plan.seeds_per_cell ? measured.first_half : measured.second_half;
|
||||
const auto slots = static_cast<std::uint32_t>(founders.size() + config.capacity + 1);
|
||||
std::vector<std::uint64_t> identity(slots + 1U);
|
||||
std::vector<std::uint64_t> born_at(slots + 1U);
|
||||
std::vector<bool> living(slots + 1U, false);
|
||||
for (std::uint32_t slot = 2; slot <= slots; ++slot) {
|
||||
const auto exists = episode->community().born(slot);
|
||||
if (!exists || !*exists) {
|
||||
continue;
|
||||
}
|
||||
identity[slot] = ++organism_identity;
|
||||
living[slot] = true;
|
||||
const auto strategy = static_cast<std::size_t>(slot - 2);
|
||||
if (!archive.record_birth(identity[slot], founders[strategy].id(), Tick{0})) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
++half[strategy].organisms;
|
||||
}
|
||||
for (auto& outcome : half) {
|
||||
++outcome.episodes;
|
||||
}
|
||||
while (true) {
|
||||
const auto stepped = episode->step();
|
||||
if (!stepped) {
|
||||
return std::unexpected{stepped.error()};
|
||||
}
|
||||
const auto tick = episode->community().progress().tick;
|
||||
for (std::uint32_t slot = 2; slot <= slots; ++slot) {
|
||||
const auto exists = episode->community().born(slot);
|
||||
const auto alive = episode->community().active(slot);
|
||||
// An unallocated slot has no lineage, so skip it before any
|
||||
// index is derived from one.
|
||||
if (!exists || !*exists || !alive) {
|
||||
continue;
|
||||
}
|
||||
const auto strategy = static_cast<std::size_t>(episode->lineage(slot) - 2);
|
||||
if (identity[slot] == 0) {
|
||||
identity[slot] = ++organism_identity;
|
||||
born_at[slot] = tick.value;
|
||||
living[slot] = true;
|
||||
if (!archive.record_birth(identity[slot], founders[strategy].id(), tick)) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
++half[strategy].births;
|
||||
++half[strategy].organisms;
|
||||
} else if (living[slot] && !*alive) {
|
||||
living[slot] = false;
|
||||
if (!archive.record_death(identity[slot], tick)) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
half[strategy].lived_ticks += tick.value - born_at[slot];
|
||||
}
|
||||
}
|
||||
if (!*stepped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const auto summary = episode->report();
|
||||
// Anything still alive lived to the end of the episode.
|
||||
for (std::uint32_t slot = 2; slot <= slots; ++slot) {
|
||||
if (living[slot]) {
|
||||
const auto strategy = static_cast<std::size_t>(episode->lineage(slot) - 2);
|
||||
half[strategy].lived_ticks += summary.ticks - born_at[slot];
|
||||
if (!archive.record_death(identity[slot], Tick{summary.ticks})) {
|
||||
return std::unexpected{EcosystemError::invalid_config};
|
||||
}
|
||||
}
|
||||
}
|
||||
measured.ticks += summary.ticks;
|
||||
measured.extinctions += summary.extinction_tick != 0 ? 1 : 0;
|
||||
report.ticks += summary.ticks;
|
||||
++report.episodes;
|
||||
}
|
||||
report.cells.push_back(measured);
|
||||
}
|
||||
report.archived_genomes = archive.archived();
|
||||
report.archived_organisms = archive.recorded();
|
||||
std::uint64_t hash = mix(0, report.episodes);
|
||||
hash = mix(hash, report.ticks);
|
||||
for (const auto& cell : report.cells) {
|
||||
hash = mix(hash, cell.ticks);
|
||||
hash = mix(hash, cell.extinctions);
|
||||
for (const auto* half : {&cell.first_half, &cell.second_half}) {
|
||||
for (const auto& outcome : *half) {
|
||||
for (const auto value :
|
||||
{outcome.genome, outcome.episodes, outcome.births, outcome.organisms,
|
||||
outcome.lived_ticks, outcome.thermal_shortfall,
|
||||
static_cast<std::uint64_t>(outcome.scheduled_lifespan)}) {
|
||||
hash = mix(hash, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
report.fingerprint = hash;
|
||||
return report;
|
||||
}
|
||||
} // namespace evo::processes
|
||||
@@ -10,4 +10,20 @@ consumer_for(const biology::Genome& genome, biology::GrowthState growth,
|
||||
}
|
||||
return ConsumerConfig{opening, budget->intake_limit, budget->assimilation_per_thousand};
|
||||
}
|
||||
|
||||
std::expected<StrategyConfig, biology::DevelopmentError>
|
||||
strategy_for(const biology::Genome& genome, biology::GrowthState growth,
|
||||
biology::EnvironmentState environment, accounting::Inventory opening,
|
||||
std::uint32_t lifespan) {
|
||||
const auto budget = biology::metabolic_budget(genome, growth, environment);
|
||||
if (!budget) {
|
||||
return std::unexpected{budget.error()};
|
||||
}
|
||||
return StrategyConfig{opening,
|
||||
budget->intake_limit,
|
||||
budget->assimilation_per_thousand,
|
||||
budget->reproduction_investment,
|
||||
budget->reproduction_investment,
|
||||
lifespan};
|
||||
}
|
||||
} // namespace evo::processes
|
||||
|
||||
Reference in New Issue
Block a user