63#include <gtest/gtest.h>
88 return static_cast<long long>(
_getpid());
90 return static_cast<long long>(
getpid());
94std::filesystem::path
tmp_path(
const std::string &name)
103 static std::atomic<unsigned long long>
counter{0};
104 const auto tick = std::chrono::steady_clock::now().time_since_epoch().count();
105 return std::filesystem::temp_directory_path()
106 / (
"aleph_ca_chk_" + name +
"_" + std::to_string(
static_cast<long long>(
tick)) +
107 "_" + std::to_string(process_id()) +
108 "_" + std::to_string(
counter++));
114 std::uniform_real_distribution<double> u(0.0, 1.0);
118 g.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
125 if (a.extents() != b.extents())
127 for (
ca_size_t i = 0; i < a.size(0); ++i)
128 for (
ca_size_t j = 0; j < a.size(1); ++j)
129 if (a.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)})
130 != b.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)}))
135std::string
read_file(
const std::filesystem::path &p)
137 std::ifstream
in(p, std::ios::binary);
138 std::ostringstream
ss;
153 const auto dir =
tmp_path(
"roundtrip");
154 std::filesystem::create_directories(dir);
155 const auto path1 = dir /
"snap1.bin";
156 const auto path2 = dir /
"snap2.bin";
170 <<
"save → load → save must be bit-identical";
172 std::filesystem::remove_all(dir);
183 const auto dir =
tmp_path(
"resume");
184 std::filesystem::create_directories(dir);
185 const auto path = dir /
"midpoint.bin";
204 <<
"restored run must match uninterrupted run frame-by-frame";
206 std::filesystem::remove_all(dir);
217 const auto dir =
tmp_path(
"inspect");
218 std::filesystem::create_directories(dir);
219 const auto path = dir /
"snap.bin";
234 std::filesystem::remove_all(dir);
247 std::filesystem::create_directories(dir);
248 const auto path = dir /
"stoch.bin";
258 initial.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
259 static_cast<int>((i + j) % 3));
274 <<
"master seed must be restored from the snapshot";
278 <<
"stochastic resume must be bit-identical to uninterrupted run";
280 std::filesystem::remove_all(dir);
295 const auto dir =
tmp_path(
"badtype");
296 std::filesystem::create_directories(dir);
297 const auto path = dir /
"snap.bin";
303 const auto offsets = std::array<Offset_Vec<1>, 2>{{{-1}, {1}}};
308 std::filesystem::remove_all(dir);
319 const auto dir =
tmp_path(
"periodic");
320 std::filesystem::create_directories(dir);
324 (dir /
"snap_{step}.bin").
string(),
327 eng.on_post_step([&](std::size_t s,
const Grid &f) {
obs.on_step_end(s, f); });
331 EXPECT_TRUE(std::filesystem::exists(dir /
"snap_0003.bin"));
332 EXPECT_TRUE(std::filesystem::exists(dir /
"snap_0006.bin"));
333 EXPECT_TRUE(std::filesystem::exists(dir /
"snap_0009.bin"));
335 EXPECT_FALSE(std::filesystem::exists(dir /
"snap_0001.bin"));
336 EXPECT_FALSE(std::filesystem::exists(dir /
"snap_0002.bin"));
337 EXPECT_FALSE(std::filesystem::exists(dir /
"snap_0010.bin"));
346 std::filesystem::remove_all(dir);
356 std::filesystem::remove_all(dir);
366 tiles.
set(i, j,
static_cast<int>((i + j) & 1));
370 <<
"16 distinct tiles touched, capacity 4 → >= 12 evictions";
380 <<
"checkerboard mismatch at (" << i <<
"," << j <<
")";
385 for (
auto &p : std::filesystem::directory_iterator(dir))
386 if (p.path().extension() ==
".bin")
390 std::filesystem::remove_all(dir);
396 const auto dir =
tmp_path(
"tile_bad");
397 std::filesystem::create_directories(dir);
400 std::filesystem::remove_all(dir);
Binary checkpoint format for Aleph::CA engines (Phase 15 + Phase 17 crash-safe / compress / async wri...
Reproducible random-number support for stochastic CA rules (Phase 8).
Phase 15 tile-based out-of-core storage for Aleph::CA.
Common typedefs and tag types for the Cellular Automata module.
User-supplied list of offsets for arbitrary connectivity.
Lattice that adds boundary-aware access on top of a storage.
Precomputed transition table for (self, neighbours...).
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Observer that auto-saves the engine state every every steps to a templated path.
Local approximation of the Schelling segregation model.
Synchronous double-buffered engine.
Out-of-core 2D tile cache with LRU eviction.
void set(ca_size_t r, ca_size_t c, const State &v)
Write the cell at (r, c) and mark its tile dirty.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
Checkpoint_Header inspect_checkpoint(const std::filesystem::path &path)
Read just the header from a checkpoint file.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Resume_Token load_checkpoint_into(Engine &engine, const std::filesystem::path &path)
Restore an engine's state in-place from a checkpoint file.
constexpr Lookup_Rule< 2, 2 > make_wolfram_elementary_rule(std::uint8_t rule_no) noexcept
Build the elementary 1D Wolfram rule rule_no (0..255) as a Lookup_Rule<2, 2> over neighbourhood {-1,...
void save_checkpoint(Engine &engine, const std::filesystem::path &path, const Checkpoint_Options &options={})
Write a complete engine snapshot to disk atomically.
Main namespace for Aleph-w library functions.
Resume handle returned by load_checkpoint_into.
The lattice wraps around on every axis.
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Reproducible stochastic CA rules (Phase 8).
Dense, contiguous storage for cellular automata cells (1D/2D/3D).