Qualify M6.8 integrated environmental cycle and costs

This commit is contained in:
dingo
2026-09-27 18:51:09 -04:00
parent ef40f38ed0
commit 9a13e796f1
6 changed files with 325 additions and 2 deletions
+178 -1
View File
@@ -401,6 +401,180 @@ void sequences(std::uint64_t ticks) {
static_cast<unsigned long long>(bites),
static_cast<unsigned long long>(fingerprint), elapsed);
}
struct Slice {
EnvironmentalConfig parameters{config()};
Opening opening{};
std::array<EnvironmentalInput, 128> inputs{};
std::uint64_t consumer_death{}, producer_death{};
};
Slice slice(std::uint64_t seed, unsigned regime) {
evo::Random rng{seed};
Slice s;
s.parameters.rules = 2;
s.parameters.assimilation = 1000;
s.parameters.decay.fill(regime == 4 ? 0 : 1);
const auto nutrients = 4 + rng.next() % 4;
s.opening.environment = {200, regime == 2 ? 0 : nutrients, nutrients, 400, 0, 0, 200, 0, 2000,
0};
s.consumer_death = 32 + rng.next() % 5;
s.producer_death = 96 + rng.next() % 7;
for (std::size_t i = 0; i < s.inputs.size(); ++i) {
const auto tick = i + 1;
const auto draw = rng.next();
auto& in = s.inputs[i];
in.temperature_mK = regime == 3 || (tick > 40 && draw % 11 == 0) ? 260000 : 290000;
in.source_enabled = regime == 1 || (tick > 40 && draw % 5 == 0) ? 0 : 1;
if (tick == 16 && (regime == 0 || regime == 4))
in.bite = {2, 2, 2, 2, 1};
if (tick == s.consumer_death)
in.terminal[1] = 1;
if (tick == s.producer_death)
in.terminal[0] = 1;
}
return s;
}
void slice_audit(const EnvironmentalCommunity& o, const evo::accounting::Inventory& total,
const Slice& s) {
CHECK(audit(o) == total);
const auto water = o.resources().fields().read(0, Field::water);
if (!water)
throw std::runtime_error("missing water");
CHECK(*water + o.resources().organisms()[0].balances[0] +
o.resources().organisms()[1].balances[0] ==
s.opening.environment[0]);
const auto p = o.progress();
CHECK(p.source_remainder < s.parameters.irradiance_denominator);
CHECK(p.growth_remainder < s.parameters.growth_denominator);
CHECK(p.efficiency_remainder < 1000 && p.last_funded <= p.tick);
}
void integrated(std::uint64_t episodes) {
const auto start = std::chrono::steady_clock::now();
for (unsigned regime = 0; regime < 5; ++regime) {
std::uint64_t captured{}, grown{}, assimilated_n{}, returned_n{}, regrown{}, fingerprint{};
for (std::uint64_t seed = 0; seed < 16; ++seed)
for (std::uint64_t episode = 0; episode < episodes; ++episode) {
const auto stream = seed + 16 * episode;
const auto s = slice(stream, regime);
auto reference = make(s.parameters, s.opening);
auto scheduled = make(s.parameters, s.opening);
const auto total = audit(*reference);
const auto resident = reference->resources().accounted_bytes();
std::array<EnvironmentalReport, 128> reports{};
std::uint64_t episode_growth{}, episode_regrowth{}, episode_capture{};
for (std::size_t i = 0; i < s.inputs.size(); ++i) {
auto r = reference->advance(i + 1, s.inputs[i]);
CHECK(r);
reports[i] = *r;
slice_audit(*reference, total, s);
episode_growth += r->grown;
episode_capture += r->captured;
captured += r->captured;
grown += r->grown;
assimilated_n += r->assimilated[1];
returned_n += r->decomposed[4];
if (r->tick > s.consumer_death && r->tick < s.producer_death)
episode_regrowth += r->grown;
if (r->tick == s.consumer_death) {
CHECK(r->grown == 0 && r->consumer_transition == 1);
if (regime == 0)
CHECK(reference->resources().organisms()[1].balances[4] == 1);
}
if (r->tick >= s.producer_death)
CHECK(r->grown == 0 && r->captured == 0);
}
if (regime == 0) {
CHECK(episode_regrowth == 2 && reports[15].assimilated[1] == 2);
CHECK(episode_growth == s.opening.environment[1] + 2);
} else {
CHECK(episode_regrowth == 0);
if (regime == 4)
CHECK(episode_growth == s.opening.environment[1]);
else
CHECK(episode_growth == 0);
if (regime == 1 || regime == 3)
CHECK(episode_capture == 0);
}
regrown += episode_regrowth;
evo::Random batches{stream ^ 0xabcdefULL};
for (std::size_t begin = 0; begin < s.inputs.size();) {
auto end = std::min(s.inputs.size(),
begin + 1 + static_cast<std::size_t>(batches.next() % 16));
// Force checkpoint boundaries around terminal events and history eviction.
for (auto cut : {s.consumer_death - 1, s.consumer_death, s.consumer_death + 1,
std::uint64_t{64}, s.producer_death - 1, s.producer_death})
if (cut > begin && cut < end)
end = static_cast<std::size_t>(cut);
auto r = schedule_environment(
*scheduled, {identity, begin, end, 50000,
std::span{s.inputs}.subspan(begin, end - begin)});
CHECK(r && !r->failure && r->committed == end - begin);
for (std::size_t j = 0; j < r->committed; ++j)
CHECK(r->reports[j] == reports[begin + j]);
slice_audit(*scheduled, total, s);
CHECK(scheduled->resources().accounted_bytes() == resident);
auto b = bytes(*scheduled);
auto restored = EnvironmentalCommunity::restore(b, identity, 8000000);
CHECK(restored);
CHECK(bytes(**restored) == b);
CHECK((*restored)->advance(end, s.inputs[end - 1]) == reports[end - 1]);
CHECK(bytes(**restored) == b);
scheduled = std::move(*restored);
begin = end;
}
CHECK(bytes(*scheduled) == bytes(*reference));
fingerprint = (fingerprint ^ hash(bytes(*reference))) * 1099511628211ULL;
}
std::printf(
"slice regime=%u episodes=%llu ticks=%llu capture=%llu growth=%llu "
"assimilated_N=%llu returned_N=%llu regrowth=%llu hash=%016llx\n",
regime, static_cast<unsigned long long>(16 * episodes),
static_cast<unsigned long long>(16 * episodes * 128),
static_cast<unsigned long long>(captured), static_cast<unsigned long long>(grown),
static_cast<unsigned long long>(assimilated_n),
static_cast<unsigned long long>(returned_n), static_cast<unsigned long long>(regrown),
static_cast<unsigned long long>(fingerprint));
}
std::printf("slice_validation_seconds=%.6f\n",
std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count());
}
void integrated_cost() {
for (unsigned sample = 0; sample < 3; ++sample) {
double steps{}, snapshot_ms{}, restore_ms{};
std::size_t snapshot_bytes{}, resource_bytes{};
for (std::uint64_t seed = 0; seed < 100; ++seed) {
const auto s = slice(seed, 0);
auto o = make(s.parameters, s.opening);
auto start = std::chrono::steady_clock::now();
for (std::size_t begin = 0; begin < 128; begin += 64) {
auto r = schedule_environment(*o, {identity, begin, begin + 64, 50000,
std::span{s.inputs}.subspan(begin, 64)});
CHECK(r && !r->failure && r->committed == 64);
}
steps +=
std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
start = std::chrono::steady_clock::now();
auto b = bytes(*o);
snapshot_ms +=
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - start)
.count();
start = std::chrono::steady_clock::now();
auto restored = EnvironmentalCommunity::restore(b, identity, 8000000);
CHECK(restored);
restore_ms +=
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - start)
.count();
CHECK(bytes(**restored) == b);
snapshot_bytes = b.size();
resource_bytes = o->resources().accounted_bytes();
}
std::printf("slice_cost sample=%u ticks=12800 seconds=%.6f snapshot_mean_ms=%.6f "
"restore_mean_ms=%.6f snapshot_bytes=%zu resource_bytes=%zu owner_bytes=%zu "
"interval_result_bytes=%zu\n",
sample, steps, snapshot_ms / 100, restore_ms / 100, snapshot_bytes,
resource_bytes, sizeof(EnvironmentalCommunity),
sizeof(EnvironmentalIntervalResult));
}
}
void cost() {
std::array<double, 3> times{};
for (auto& seconds : times) {
@@ -434,8 +608,11 @@ int main(int argc, char** argv) {
malformed();
exhausted_tick();
sequences(argc == 2 ? 65536 : 4096);
if (argc == 2)
integrated(argc == 2 ? 64 : 1);
if (argc == 2) {
cost();
integrated_cost();
}
return 0;
} catch (const std::exception& e) {
std::fprintf(stderr, "%s\n", e.what());