feat(lifecycle): preserve inherited plans in exact populations
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (deploy) (push) Successful in 4m57s
Foundation / checks (network) (push) Successful in 20m53s
Foundation / checks (client) (push) Successful in 22m12s
Foundation / checks (tsan) (push) Successful in 39m45s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 45m41s
Foundation / checks (checks) (push) Canceled after 45m43s
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (deploy) (push) Successful in 4m57s
Foundation / checks (network) (push) Successful in 20m53s
Foundation / checks (client) (push) Successful in 22m12s
Foundation / checks (tsan) (push) Successful in 39m45s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 45m41s
Foundation / checks (checks) (push) Canceled after 45m43s
This commit is contained in:
@@ -56,9 +56,10 @@ CellularCensus::observe(const CellularLives& state, std::span<const CellularCoho
|
||||
const bool maturing = state.rules_version() == cellular_lives_maturation_rules &&
|
||||
state.format_version() == cellular_lives_migration_format &&
|
||||
(population == 0 || population == 2);
|
||||
const bool inherited = state.rules_version() == cellular_lives_inheritance_rules &&
|
||||
state.format_version() == cellular_lives_inheritance_format &&
|
||||
population == 0;
|
||||
const bool inherited =
|
||||
state.rules_version() == cellular_lives_inheritance_rules &&
|
||||
state.format_version() == cellular_lives_inheritance_format &&
|
||||
(population == 0 || population == cellular_population_inheritance_format);
|
||||
if (!inherited && ((!maturing && state.rules_version() != cellular_lives_foraging_rules) ||
|
||||
(state.format_version() != cellular_lives_presence_format &&
|
||||
state.format_version() != cellular_lives_migration_format) ||
|
||||
|
||||
@@ -14,13 +14,15 @@ CellularPopulation::CellularPopulation(std::unique_ptr<CellularLives> state,
|
||||
|
||||
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
|
||||
CellularPopulation::create(std::unique_ptr<CellularLives> state, CellularTierPolicy policy) {
|
||||
if (!state ||
|
||||
(state->rules_version() != cellular_lives_foraging_rules &&
|
||||
!(state->rules_version() == cellular_lives_maturation_rules &&
|
||||
state->format_version() == cellular_lives_migration_format)) ||
|
||||
(state->format_version() != cellular_lives_presence_format &&
|
||||
state->format_version() != cellular_lives_migration_format) ||
|
||||
policy.materialize_radius_um == 0 ||
|
||||
const bool supported =
|
||||
state && ((state->rules_version() == cellular_lives_foraging_rules &&
|
||||
(state->format_version() == cellular_lives_presence_format ||
|
||||
state->format_version() == cellular_lives_migration_format)) ||
|
||||
(state->rules_version() == cellular_lives_maturation_rules &&
|
||||
state->format_version() == cellular_lives_migration_format) ||
|
||||
(state->rules_version() == cellular_lives_inheritance_rules &&
|
||||
state->format_version() == cellular_lives_inheritance_format));
|
||||
if (!supported || policy.materialize_radius_um == 0 ||
|
||||
policy.collapse_radius_um <= policy.materialize_radius_um ||
|
||||
policy.collapse_radius_um > biology::cellular_motion_axis_limit_um)
|
||||
return std::unexpected(CellularPopulationError::unsupported);
|
||||
@@ -42,6 +44,8 @@ std::uint64_t CellularPopulation::conversion_sequence() const noexcept {
|
||||
return conversion_sequence_;
|
||||
}
|
||||
std::uint32_t CellularPopulation::format_version() const noexcept {
|
||||
if (state_->format_version() == cellular_lives_inheritance_format)
|
||||
return cellular_population_inheritance_format;
|
||||
return state_->format_version() == cellular_lives_migration_format ? 2U : 1U;
|
||||
}
|
||||
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
|
||||
@@ -68,6 +72,18 @@ CellularPopulation::maturation_upgrade_candidate() const {
|
||||
(*candidate)->conversion_sequence_ = conversion_sequence_;
|
||||
return candidate;
|
||||
}
|
||||
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
|
||||
CellularPopulation::inheritance_upgrade_candidate() const {
|
||||
auto biological = state_->inheritance_upgrade_candidate();
|
||||
if (!biological)
|
||||
return std::unexpected(CellularPopulationError::unsupported);
|
||||
auto candidate = create(std::move(*biological), policy_);
|
||||
if (!candidate)
|
||||
return std::unexpected(candidate.error());
|
||||
(*candidate)->members_ = members_;
|
||||
(*candidate)->conversion_sequence_ = conversion_sequence_;
|
||||
return candidate;
|
||||
}
|
||||
std::expected<std::size_t, CellularPopulationError>
|
||||
CellularPopulation::collapse(std::uint64_t genome) {
|
||||
auto candidate = members_;
|
||||
|
||||
@@ -6,16 +6,18 @@
|
||||
|
||||
namespace evo::server {
|
||||
namespace {
|
||||
constexpr std::uint64_t magic = 0x315442504F564541ULL; // "AEVOPBT1"
|
||||
constexpr std::uint64_t migration_magic = 0x325442504F564541ULL; // "AEVOPBT2"
|
||||
constexpr std::uint64_t magic = 0x315442504F564541ULL; // "AEVOPBT1"
|
||||
constexpr std::uint64_t migration_magic = 0x325442504F564541ULL; // "AEVOPBT2"
|
||||
constexpr std::uint64_t inheritance_magic = 0x335442504F564541ULL; // "AEVOPBT3"
|
||||
bool shape(const CellularPopulationBatch& batch, bool recording) {
|
||||
const auto& h = batch.header;
|
||||
const auto zero = [](const auto& bytes) {
|
||||
return std::ranges::all_of(bytes, [](auto byte) { return byte == 0; });
|
||||
};
|
||||
if ((batch.format_version != 1 && batch.format_version != 2) || h.world == 0 || h.region == 0 ||
|
||||
h.frame == 0 || zero(h.predecessor) || zero(h.predecessor_digest) ||
|
||||
h.end_tick < h.begin_tick)
|
||||
if ((batch.format_version != 1 && batch.format_version != 2 &&
|
||||
batch.format_version != cellular_population_inheritance_format) ||
|
||||
h.world == 0 || h.region == 0 || h.frame == 0 || zero(h.predecessor) ||
|
||||
zero(h.predecessor_digest) || h.end_tick < h.begin_tick)
|
||||
return false;
|
||||
const auto count = batch.conversion ? std::size_t{1} : batch.biology.ticks.size();
|
||||
if (count == 0 || count > max_cellular_batch_ticks ||
|
||||
@@ -26,7 +28,10 @@ bool shape(const CellularPopulationBatch& batch, bool recording) {
|
||||
!batch.biology.ticks.empty() || batch.biology.header != CellularBatchHeader{})
|
||||
return false;
|
||||
} else {
|
||||
if (batch.biology.header != h || batch.biology.format_version != cellular_batch_format ||
|
||||
const auto raw_format = batch.format_version == cellular_population_inheritance_format
|
||||
? cellular_batch_inheritance_format
|
||||
: cellular_batch_format;
|
||||
if (batch.biology.header != h || batch.biology.format_version != raw_format ||
|
||||
h.end_tick - h.begin_tick != count || !encode_cellular_batch(batch.biology))
|
||||
return false;
|
||||
for (const auto& tick : batch.biology.ticks)
|
||||
@@ -78,7 +83,9 @@ class Reader {
|
||||
|
||||
bool population_interval_safe(const CellularLives& state) noexcept {
|
||||
return (state.rules_version() == cellular_lives_foraging_rules ||
|
||||
state.rules_version() == cellular_lives_maturation_rules) &&
|
||||
state.rules_version() == cellular_lives_maturation_rules ||
|
||||
(state.rules_version() == cellular_lives_inheritance_rules &&
|
||||
state.format_version() == cellular_lives_inheritance_format)) &&
|
||||
std::ranges::all_of(state.lives(), [](const auto& life) {
|
||||
return life.account == LifeAccount{} || life.presence == CellularPresence::suspended;
|
||||
});
|
||||
@@ -96,6 +103,8 @@ unattended_population_inputs(const CellularLives& base, const CellularBatchHeade
|
||||
if (!working)
|
||||
return std::unexpected(CellularPopulationError::format);
|
||||
CellularBatch batch{header, {}};
|
||||
if (base.rules_version() == cellular_lives_inheritance_rules)
|
||||
batch.format_version = cellular_batch_inheritance_format;
|
||||
while ((*working)->tick() < header.end_tick) {
|
||||
auto intents = wildlife_intents(**working, (*working)->tick() + 1);
|
||||
if (!intents)
|
||||
@@ -164,7 +173,7 @@ execute_population_batch(const CellularPopulation& base, CellularPopulationBatch
|
||||
if (intent == input.lives.end() || intent->intent != frozen)
|
||||
return std::unexpected(CellularPopulationError::ineligible);
|
||||
}
|
||||
CellularBatch one{batch.biology.header, {input}, cellular_batch_format};
|
||||
CellularBatch one{batch.biology.header, {input}, batch.biology.format_version};
|
||||
one.header.begin_tick = (*candidate)->state().tick();
|
||||
one.header.end_tick = one.header.begin_tick + 1;
|
||||
auto biology = replay_cellular_batch((*candidate)->state(), one);
|
||||
@@ -229,7 +238,9 @@ encode_population_batch(const CellularPopulationBatch& batch) {
|
||||
biological = std::move(*encoded);
|
||||
}
|
||||
std::vector<std::uint8_t> out;
|
||||
put(out, batch.format_version == 2 ? migration_magic : magic);
|
||||
put(out, batch.format_version == cellular_population_inheritance_format ? inheritance_magic
|
||||
: batch.format_version == 2 ? migration_magic
|
||||
: magic);
|
||||
put(out, batch.format_version, 4);
|
||||
put(out, batch.conversion ? 1 : 0, 4);
|
||||
const auto& h = batch.header;
|
||||
@@ -264,7 +275,8 @@ decode_population_batch(std::span<const std::uint8_t> bytes) {
|
||||
const auto saved_magic = in.get();
|
||||
const auto version = in.get(4);
|
||||
if (!((saved_magic == magic && version == 1) ||
|
||||
(saved_magic == migration_magic && version == 2)))
|
||||
(saved_magic == migration_magic && version == 2) ||
|
||||
(saved_magic == inheritance_magic && version == cellular_population_inheritance_format)))
|
||||
return std::unexpected(CellularPopulationError::unsupported);
|
||||
const auto kind = in.get(4);
|
||||
CellularPopulationBatch batch;
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
namespace evo::server {
|
||||
namespace {
|
||||
constexpr std::uint64_t magic = 0x31504F504F564541ULL; // "AEVOPOP1"
|
||||
constexpr std::uint64_t migration_magic = 0x32504F504F564541ULL; // "AEVOPOP2"
|
||||
constexpr std::uint64_t magic = 0x31504F504F564541ULL; // "AEVOPOP1"
|
||||
constexpr std::uint64_t migration_magic = 0x32504F504F564541ULL; // "AEVOPOP2"
|
||||
constexpr std::uint64_t inheritance_magic = 0x33504F504F564541ULL; // "AEVOPOP3"
|
||||
std::uint64_t checksum(std::span<const std::uint8_t> bytes) {
|
||||
std::uint64_t hash = 14695981039346656037ULL;
|
||||
for (const auto byte : bytes)
|
||||
@@ -39,7 +40,11 @@ std::vector<std::uint8_t> CellularPopulation::snapshot() const {
|
||||
const auto biology = state_->snapshot();
|
||||
std::vector<std::uint8_t> bytes;
|
||||
bytes.reserve(cellular_population_header_bytes + members_.size() * 16 + biology.size() + 8);
|
||||
put(bytes, format_version() == 2 ? migration_magic : magic, 8);
|
||||
put(bytes,
|
||||
format_version() == cellular_population_inheritance_format ? inheritance_magic
|
||||
: format_version() == 2 ? migration_magic
|
||||
: magic,
|
||||
8);
|
||||
put(bytes, format_version(), 4);
|
||||
put(bytes, policy_.automatic ? 1 : 0, 4);
|
||||
put(bytes, policy_.materialize_radius_um, 4);
|
||||
@@ -68,10 +73,12 @@ CellularPopulation::restore(std::span<const std::uint8_t> bytes, std::uint64_t w
|
||||
return std::unexpected(CellularPopulationError::checksum);
|
||||
Reader reader(bytes);
|
||||
const auto saved_magic = reader.get(8);
|
||||
if (saved_magic != magic && saved_magic != migration_magic)
|
||||
if (saved_magic != magic && saved_magic != migration_magic && saved_magic != inheritance_magic)
|
||||
return std::unexpected(CellularPopulationError::format);
|
||||
const auto version = reader.get(4);
|
||||
if ((saved_magic == magic && version != 1) || (saved_magic == migration_magic && version != 2))
|
||||
if ((saved_magic == magic && version != 1) ||
|
||||
(saved_magic == migration_magic && version != 2) ||
|
||||
(saved_magic == inheritance_magic && version != cellular_population_inheritance_format))
|
||||
return std::unexpected(CellularPopulationError::unsupported);
|
||||
const auto flags = reader.get(4);
|
||||
if (flags > 1)
|
||||
|
||||
Reference in New Issue
Block a user