From d3d0b9ba83bd9f3df73cb3aa63e14aabf144f24f Mon Sep 17 00:00:00 2001 From: Diane Blackwood Date: Wed, 24 Sep 2025 01:07:28 -0400 Subject: [PATCH] Initial files added --- .devcontainer/devcontainer.json | 26 ++++ .dockerignore | 14 ++ .forgejo/workflows/ci.yml | 24 ++++ ACKNOWLEDGEMENTS.md | 17 +++ Cargo.toml | 10 ++ DETERMINISM.md | 24 ++++ Dockerfile.dev | 35 +++++ Dockerfile.release | 44 ++++++ LICENSE-Apache | 20 +++ LICENSE-MIT | 22 +++ Makefile | 29 ++++ README.md | 180 ++++++++++++++++++++++++- STYLE.md | 28 ++++ TRANSLATION_GLOSSARY.md | 35 +++++ UNSAFE_POLICY.md | 16 +++ crates/mabelabrs-core/Cargo.toml | 12 ++ crates/mabelabrs-core/src/evaluator.rs | 10 ++ crates/mabelabrs-core/src/genome.rs | 16 +++ crates/mabelabrs-core/src/lib.rs | 9 ++ crates/mabelabrs-core/src/organism.rs | 16 +++ docker-compose-homalab-addendum.yml | 6 + docker-compose.yml | 37 +++++ 22 files changed, 629 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .dockerignore create mode 100644 .forgejo/workflows/ci.yml create mode 100644 ACKNOWLEDGEMENTS.md create mode 100644 Cargo.toml create mode 100644 DETERMINISM.md create mode 100644 Dockerfile.dev create mode 100644 Dockerfile.release create mode 100644 LICENSE-Apache create mode 100644 LICENSE-MIT create mode 100644 Makefile create mode 100644 STYLE.md create mode 100644 TRANSLATION_GLOSSARY.md create mode 100644 UNSAFE_POLICY.md create mode 100644 crates/mabelabrs-core/Cargo.toml create mode 100644 crates/mabelabrs-core/src/evaluator.rs create mode 100644 crates/mabelabrs-core/src/genome.rs create mode 100644 crates/mabelabrs-core/src/lib.rs create mode 100644 crates/mabelabrs-core/src/organism.rs create mode 100644 docker-compose-homalab-addendum.yml create mode 100644 docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..05681e5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +{ + "name": "MabeLabRS Dev", + "dockerComposeFile": "../docker-compose.yml", + "service": "dev", + "workspaceFolder": "/work", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {} + }, + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "rust-analyzer.cargo.useRustcWrapperForBuildScripts": true + }, + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "serayuzgur.crates", + "matklad.rust-analyzer", + "ms-azuretools.vscode-docker" + ] + } + }, + "remoteUser": "dev" +} + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..71678e5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +target +**/target +**/*.rs.bk +**/*.swp +**/*.swo +**/.DS_Store +.git +.gitignore +.forgejo +node_modules +.idea +.vscode +**/.cache +.sccache diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..ab00a55 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + branches: [ main, porting ] + pull_request: + branches: [ main, porting ] + +jobs: + rust: + runs-on: docker + container: + image: mabelabrs-dev:latest + # If your Forgejo runner can't pull local images, add a previous step + # to `docker build -f Dockerfile.dev -t mabelabrs-dev:latest .` + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build --workspace --all-targets + - name: Clippy + run: cargo clippy --workspace --all-targets -- -D warnings + - name: Test + run: cargo test --workspace --all-features --no-fail-fast + diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md new file mode 100644 index 0000000..c175c72 --- /dev/null +++ b/ACKNOWLEDGEMENTS.md @@ -0,0 +1,17 @@ +# Acknowledgements + +MabeLabRS is a Rust port inspired by: + +- **MABE2** (https://github.com/mercere99/MABE2) + Copyright (c) 2016–present Charles Ofria and MABE contributors + Licensed under the MIT License. + +- **Empirical** (https://github.com/devosoft/Empirical) + Copyright (c) 2014–present Charles Ofria and Empirical contributors + Licensed under the MIT License. + +This project is independent and not officially affiliated with the upstream +projects, but it draws architectural concepts and design inspiration from them. + +We gratefully acknowledge the work of the original authors and contributors. + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b9afafa --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] +members = [ + "crates/mabelabrs-core", + "crates/mabelabrs-world", + "crates/mabelabrs-eval", + "crates/mabelabrs-io", + "crates/mabelabrs-utils", + "crates/mabelabrs-ffi", +] +resolver = "2" diff --git a/DETERMINISM.md b/DETERMINISM.md new file mode 100644 index 0000000..1872949 --- /dev/null +++ b/DETERMINISM.md @@ -0,0 +1,24 @@ +# Determinism Policy + +MabeLabRS emphasizes reproducibility of artificial life experiments. + +## Randomness +- Use `rand_chacha::ChaCha8Rng` (fast, reproducible). +- Seeds must be explicit and logged in experiment manifests. + +## Floating-point +- Default: `f64`. +- Avoid nondeterministic parallel reductions; when needed, gate behind + the `fast-math` feature. +- Golden tests should tolerate ≤ 1e-12 relative error in float comparisons. + +## Collections +- Use `BTreeMap`/`BTreeSet` when deterministic ordering is required. +- Use `indexmap::IndexMap`/`IndexSet` for hash-backed structures + that preserve insertion order. + +## Parallelism +- Sequential by default. +- `rayon` parallelism only behind `parallel` feature flag. +- Golden tests must run with `--no-default-features` to guarantee determinism. + diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..55e9b4e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,35 @@ +# Developer image: Rust + build tools + sccache + minimal deps +FROM rust:1-bookworm + +# Install useful build deps and tooling +RUN apt-get update && apt-get install -y --no-install-recommends \ + clang cmake pkg-config libssl-dev git ca-certificates curl \ + && rm -rf /var/lib/apt/lists/* + +# sccache speeds up incremental builds across container runs +ENV SCCACHE_DIR=/root/.cache/sccache +RUN cargo install sccache + +# Configure rustc to use sccache by default +ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache +ENV CARGO_INCREMENTAL=0 + +# Optional: set a default toolchain (can be overridden by rust-toolchain.toml) +RUN rustup component add clippy rustfmt + +# Create a non-root user (optional; comment out if you prefer root) +RUN useradd -m -u 1000 dev +USER dev +WORKDIR /work + +# Cache hints: create empty project files so first build primes caches +COPY --chown=dev:dev Cargo.toml ./ +COPY --chown=dev:dev crates/mabelabrs-core/Cargo.toml crates/mabelabrs-core/Cargo.toml +COPY --chown=dev:dev crates/mabelabrs-world/Cargo.toml crates/mabelabrs-world/Cargo.toml +COPY --chown=dev:dev crates/mabelabrs-eval/Cargo.toml crates/mabelabrs-eval/Cargo.toml +COPY --chown=dev:dev crates/mabelabrs-io/Cargo.toml crates/mabelabrs-io/Cargo.toml +COPY --chown=dev:dev crates/mabelabrs-utils/Cargo.toml crates/mabelabrs-utils/Cargo.toml +COPY --chown=dev:dev crates/mabelabrs-ffi/Cargo.toml crates/mabelabrs-ffi/Cargo.toml + +# Final copy happens at runtime via bind mount; this stage just primes caches. + diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..e7ba47f --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,44 @@ +# Build stage +FROM rust:1-bookworm as builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + clang cmake pkg-config libssl-dev git ca-certificates curl \ + && rm -rf /var/lib/apt/lists/* + +# sccache optional in release, but still useful for CI +RUN cargo install sccache +ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache + +WORKDIR /work +# Copy manifests first to leverage Docker layer caching +COPY Cargo.toml Cargo.lock ./ +COPY crates/mabelabrs-core/Cargo.toml crates/mabelabrs-core/Cargo.toml +COPY crates/mabelabrs-world/Cargo.toml crates/mabelabrs-world/Cargo.toml +COPY crates/mabelabrs-eval/Cargo.toml crates/mabelabrs-eval/Cargo.toml +COPY crates/mabelabrs-io/Cargo.toml crates/mabelabrs-io/Cargo.toml +COPY crates/mabelabrs-utils/Cargo.toml crates/mabelabrs-utils/Cargo.toml +COPY crates/mabelabrs-ffi/Cargo.toml crates/mabelabrs-ffi/Cargo.toml + +# Create empty src to allow dependency build caching +RUN mkdir -p crates/mabelabrs-utils/src && echo "fn main(){}" > crates/mabelabrs-utils/src/main.rs + +# Build deps +RUN cargo build -p mabelabrs-utils --release || true + +# Now copy the whole source and do the real build +COPY . . +RUN cargo build -p mabelabrs-utils --release + +# Runtime stage (distroless-ish; use slim for better debugability) +FROM debian:bookworm-slim + +# If your CLI needs SSL/DNS, keep these minimal libs +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates libssl3 && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY --from=builder /work/target/release/mabelabrs-utils /usr/local/bin/mabelabrs-utils + +ENTRYPOINT ["/usr/local/bin/mabelabrs-utils"] +CMD ["--help"] + diff --git a/LICENSE-Apache b/LICENSE-Apache new file mode 100644 index 0000000..7862ce0 --- /dev/null +++ b/LICENSE-Apache @@ -0,0 +1,20 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +Copyright 2025 Wesley R. Elsberry and MabeLabRS Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..83e88f8 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2025 Wesley R. Elsberry and MabeLabRS Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..edde3a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +SHELL := /bin/bash + +.PHONY: build test clippy fmt ci shell clean release + +# Open an interactive shell in the dev container +shell: +\tdocker compose run --rm dev bash + +build: +\tdocker compose run --rm dev bash -lc "cargo build --workspace --all-targets" + +test: +\tdocker compose run --rm dev bash -lc "cargo test --workspace --all-features --no-fail-fast" + +clippy: +\tdocker compose run --rm dev bash -lc "cargo clippy --workspace --all-targets -- -D warnings" + +fmt: +\tdocker compose run --rm dev bash -lc "cargo fmt --all" + +ci: fmt clippy build test + +release: +\tdocker compose build release + +clean: +\trm -rf target || true +\tdocker compose down --volumes --remove-orphans || true + diff --git a/README.md b/README.md index 8c57919..b4f2cb1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,180 @@ -# MABELab-RS +# MabeLabRS — a Rust port of MABE2 +**MabeLabRS** is a Rust re-implementation of the MSU **MABE2** artificial life framework, aiming for: +- **API parity** where sensible, with a modern Rust design (traits, enums, safe concurrency). +- **Determinism** for research reproducibility (seeded RNG, stable iteration order). +- **Portability** to the web (WASM) for teaching demos (evo-edu.org) and outreach (TalkOrigins). + +> Upstream: MABE2 (C++, MIT) — https://github.com/mercere99/MABE2 +> This project is an independent port; see **License & Attribution** below. + +--- + +## Project status + +- 🚧 **Pre-alpha (porting in progress)** — core traits and module skeletons are landing first. +- 🎯 Goals: organism + genome abstractions, worlds/topologies, evaluators, experiment runner, config I/O, parity tests. + +--- + +## Workspace layout + +- mabelabrs/ +- ├─ Cargo.toml # [workspace] +- ├─ rust-toolchain.toml # pin stable or MSRV +- ├─ LICENSE-APACHE +- ├─ LICENSE-MIT +- ├─ ACKNOWLEDGEMENTS.md +- ├─ README.md +- ├─ crates/ +- │ ├─ mabelabrs-core/ # genomes, organisms, traits, RNG & schedulers +- │ ├─ mabelabrs-world/ # populations, environments, spatial/graph topologies +- │ ├─ mabelabrs-eval/ # tasks, fitness functions, analyzers +- │ ├─ mabelabrs-io/ # serde configs, logging, (bincode/json) state +- │ ├─ mabelabrs-utils/ # CLI runner, experiment manifests +- │ └─ mabelabrs-ffi/ # optional C++ bridge to MABE2 for parity (feature-gated) +- ├─ tests/ +- │ ├─ golden/ # small deterministic fixtures +- │ └─ parity/ # cross-lang checks (behind ffi feature) +- ├─ benches/ # criterion benches for hotspots +- └─ porting/ # LLM-driven port tooling (only on porting branch) +- ├─ TRANSLATION_GLOSSARY.md +- ├─ STYLE.md +- ├─ DETERMINISM.md +- ├─ UNSAFE_POLICY.md +- ├─ prompts/ +- └─ tools/ # scripts to run local LLM, compile, test, open PRs + + +--- + +## Why Rust? + +- **Memory safety** and clear ownership models for complex evolutionary simulations. +- **Deterministic** iteration and seeded RNG for reproducibility. +- **Great tooling** (cargo, clippy, criterion, proptest) and easy WASM targets for classroom demos. + +--- + +## Quick start + +```bash +# clone +git clone /MabeLabRS.git +cd MabeLabRS + +# build all crates +cargo build + +# run tests +cargo test + +# optional parity tests (requires C++ MABE2 + ffi feature) +cargo test -p mabelabrs-ffi --features ffi + + +Feature flags: + +ffi — enable C++ bridge for cross-language parity tests. + +fast-math — allow non-deterministic float reductions (off by default). + +Determinism + +RNG: rand_chacha (documented seed in experiment manifest). + +Order-sensitive collections: indexmap where iteration order matters. + +Parallelism: gated by feature flags (rayon), default serial to preserve bit-for-bit comparable runs. + +Using with evo-edu.org / TalkOrigins + +WASM builds will be provided as examples under examples/wasm/ for web-hosted demos and teaching modules. + +Naming and metadata optimized for search discoverability: MabeLabRS / mabelabrs-* crates. + +Contributing + +Discuss issues in the tracker; claim a module before starting. + +Follow STYLE.md and UNSAFE_POLICY.md. + +Every PR must: + +compile (cargo check), + +be formatted (cargo fmt), + +lint cleanly (cargo clippy -- -D warnings), + +include tests for added behavior. + +Deterministic tests belong in tests/golden/. Heavier regression and parity tests go in tests/parity/. + +We welcome LLM-assisted contributions only if the result compiles and includes tests. Please include the prompt and model info in the PR description for provenance. + +Branch strategy + +main: always buildable; docs + examples meant for users. + +porting: long-lived branch for translation scripts, FFI harnesses, and staged module ports. + +Feature branches: feat/ or fix/; merge into porting, and periodically milestone-merge porting → main when a vertical slice is stable (e.g., genome+mutation+simple world). + +Protect main and porting with required checks. + +License & Attribution + +Port license: Dual MIT OR Apache-2.0 (choose at your option). +See LICENSE-MIT and LICENSE-APACHE. + +Upstream attribution: +This project is a Rust port inspired by MABE2 (MIT) and conceptually by the Empirical library (MIT). +Copyright and license notices from upstream are preserved in ACKNOWLEDGEMENTS.md. + +You may use MabeLabRS under the terms of MIT or Apache-2.0. + +Citation + +If you use MabeLabRS in academic work, please cite MABE2 as appropriate and this repository (commit or release tag). A CITATION.cff will be added at first release. + +Roadmap (short) + + Core traits: Genome, Organism, Evaluator, World, Scheduler + + Config & manifests (serde + JSON/TOML) + + Minimal world & evaluator example with golden tests + + Optional ffi parity tests against MABE2 + + WASM demo example for evo-edu.org + + First alpha release on crates.io + + +--- + +## Container-first workflow + +This repo ships with a containerized toolchain for **development**, **testing**, and **releases**. + +### Quick start (Dev container) +```bash +# one-time build of the dev image (with Rust toolchain, sccache, tools) +docker compose build dev + +# launch an interactive dev shell with your repo mounted at /work +docker compose run --rm dev bash + +# inside the container +cargo build +cargo test +cargo clippy -- -D warnings + +# Generative AI Notice + +This project is planned to be largely conducted through the use of generative AI tools, +including OpenAI ChatGPT. While the plan is to conduct testing, be aware that +generative AI may not be entirely accurate in its outputs, and determine suitability +to purpose incorporating this information. diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 0000000..252270a --- /dev/null +++ b/STYLE.md @@ -0,0 +1,28 @@ +# MabeLabRS Style Guide + +## Code formatting +- Use `cargo fmt` with `rustfmt.toml` in repo root. +- Line width: 100. +- Always use `#[derive(Debug, Clone, PartialEq, Eq)]` on simple data types. + +## Naming +- Crates: `mabelabrs-*` prefix. +- Traits: `CamelCase`, no `I` prefix. +- Structs: `CamelCase`. +- Enums: `CamelCase` with variant `CamelCase`. +- Functions: `snake_case`. + +## Error handling +- Return `Result` from fallible functions. +- Use `thiserror` for error enums. +- Avoid panics, except in tests or truly unrecoverable states. + +## Documentation +- All public items must have `///` doc comments. +- Modules should have a top-level `//!` doc comment. + +## Testing +- Unit tests inline in modules (`#[cfg(test)]`). +- Integration tests in `/tests`. +- Deterministic golden tests in `/tests/golden`. + diff --git a/TRANSLATION_GLOSSARY.md b/TRANSLATION_GLOSSARY.md new file mode 100644 index 0000000..cca113a --- /dev/null +++ b/TRANSLATION_GLOSSARY.md @@ -0,0 +1,35 @@ +# Translation Glossary: C++ → Rust + +This glossary defines consistent mappings from MABE2 / Empirical idioms +to MabeLabRS Rust code. It should be updated as the port progresses. + +## Memory / Pointers +- `std::unique_ptr` → `Box` +- `std::shared_ptr` → `Arc` (multi-thread safe), or `Rc` (single-thread) +- `std::weak_ptr` → `Weak` (Arc/Rc) +- raw pointer (owning) → `Box` +- raw pointer (borrowed) → `&T` or `&mut T` + +## Optional / Variants +- `std::optional` → `Option` +- `std::variant` → `enum { A(A), B(B) }` + +## Containers +- `std::vector` → `Vec` +- `std::map` → `BTreeMap` (ordered, deterministic) +- `std::unordered_map` → `HashMap` or `IndexMap` (deterministic) +- `std::set` → `BTreeSet` + +## Interfaces / Inheritance +- C++ abstract base class → Rust `trait` +- C++ pure virtual function → `fn ...;` in trait +- C++ virtual function → default method in trait + +## Errors +- Error codes / exceptions → `Result` with `thiserror` derive + +## Utilities +- C++ RNG (emp::Random) → `rand_chacha::ChaCha8Rng` seeded via manifest +- Empirical Config → `serde` + `toml/json` +- Empirical Signals/Actions → strongly typed Rust event bus (observer pattern) + diff --git a/UNSAFE_POLICY.md b/UNSAFE_POLICY.md new file mode 100644 index 0000000..ae69ad0 --- /dev/null +++ b/UNSAFE_POLICY.md @@ -0,0 +1,16 @@ +# Unsafe Code Policy + +MabeLabRS is committed to safe Rust. Unsafe is allowed only when: + +- It is proven necessary for performance in critical loops, and +- There is no safe alternative without excessive overhead, and +- The code is isolated in a single module with: + - Comments explaining invariants, + - Unit tests covering invariants, + - Reviewed by at least one maintainer. + +All unsafe blocks must be justified with a doc comment. + +Tools: +- Run `cargo geiger` in CI to track unsafe usage. + diff --git a/crates/mabelabrs-core/Cargo.toml b/crates/mabelabrs-core/Cargo.toml new file mode 100644 index 0000000..3271b6f --- /dev/null +++ b/crates/mabelabrs-core/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "mabelabrs-core" +version = "0.1.0" +edition = "2021" +license = "MIT OR Apache-2.0" +description = "Core traits and data structures for MabeLabRS" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +thiserror = "1.0" +rand_chacha = "0.3" + diff --git a/crates/mabelabrs-core/src/evaluator.rs b/crates/mabelabrs-core/src/evaluator.rs new file mode 100644 index 0000000..063b246 --- /dev/null +++ b/crates/mabelabrs-core/src/evaluator.rs @@ -0,0 +1,10 @@ +//! Evaluator abstraction. + +use crate::organism::Organism; +use crate::genome::Genome; + +/// Trait for evaluating organisms in a population. +pub trait Evaluator> { + /// Evaluate fitness of an organism. + fn evaluate(&self, organism: &O) -> f64; +} diff --git a/crates/mabelabrs-core/src/genome.rs b/crates/mabelabrs-core/src/genome.rs new file mode 100644 index 0000000..433d6bd --- /dev/null +++ b/crates/mabelabrs-core/src/genome.rs @@ -0,0 +1,16 @@ +//! Genome abstraction. + +use serde::{Serialize, Deserialize}; + +/// Trait representing a genome in MabeLabRS. +pub trait Genome: Serialize + for<'de> Deserialize<'de> + Clone { + /// Mutate this genome in-place. + fn mutate(&mut self); + + /// Return a deep copy of this genome. + fn copy(&self) -> Self; + + /// Return a human-readable description. + fn describe(&self) -> String; +} + diff --git a/crates/mabelabrs-core/src/lib.rs b/crates/mabelabrs-core/src/lib.rs new file mode 100644 index 0000000..1fb547c --- /dev/null +++ b/crates/mabelabrs-core/src/lib.rs @@ -0,0 +1,9 @@ +//! Core traits and data structures for MabeLabRS. + +pub mod genome; +pub mod organism; +pub mod evaluator; + +/// A unique identifier for genomes. +pub type GenomeId = u64; + diff --git a/crates/mabelabrs-core/src/organism.rs b/crates/mabelabrs-core/src/organism.rs new file mode 100644 index 0000000..9c72590 --- /dev/null +++ b/crates/mabelabrs-core/src/organism.rs @@ -0,0 +1,16 @@ +//! Organism abstraction. + +use crate::genome::Genome; +use serde::{Serialize, Deserialize}; + +/// Trait representing an organism composed of a genome. +pub trait Organism: Serialize + for<'de> Deserialize<'de> { + /// Return a reference to the genome. + fn genome(&self) -> &G; + + /// Return a mutable reference to the genome. + fn genome_mut(&mut self) -> &mut G; + + /// Express the phenotype (to be defined by evaluator). + fn express(&self) -> String; +} diff --git a/docker-compose-homalab-addendum.yml b/docker-compose-homalab-addendum.yml new file mode 100644 index 0000000..7b0887e --- /dev/null +++ b/docker-compose-homalab-addendum.yml @@ -0,0 +1,6 @@ +deploy: + resources: + reservations: + devices: + - capabilities: ["gpu"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a75f722 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3.9" +services: + dev: + build: + context: . + dockerfile: Dockerfile.dev + image: mabelabrs-dev:latest + container_name: mabelabrs-dev + working_dir: /work + volumes: + - ./:/work + - sccache:/root/.cache/sccache + - cargo-registry:/usr/local/cargo/registry + - cargo-git:/usr/local/cargo/git + - target:/work/target + tty: true + environment: + - RUSTC_WRAPPER=/usr/local/cargo/bin/sccache + - CARGO_HOME=/usr/local/cargo + - RUST_LOG=info + + release: + build: + context: . + dockerfile: Dockerfile.release + image: mabelabrs:latest + container_name: mabelabrs + # no source mount; uses built artifact + entrypoint: ["/usr/local/bin/mabelabrs-utils"] + command: ["--help"] + +volumes: + sccache: + cargo-registry: + cargo-git: + target: +