# ailed — library rules The organism itself: an affective CPPN, a Relational Perceptron, a Gated Relational Perceptron, and a two-axis affect state. Nothing domain-specific lives here. Experiments live in the sibling `experiments` repo; the design is `AILED_General_Specification.md` in the parent directory. ## What is in here | file | responsibility | |---|---| | `src/ailed/affect.py` | spec §5. `AffectConfig`, `Affect`, `update`, `decay`. Pure functions over floats. | | `src/ailed/core.py` | spec §3–§4. `AffectiveCPPN`, `RelationalPerceptron`, `GatedRelationalPerceptron`, `Organism`, `detach_memory`. | ## Rules Each of these exists because breaking it produced a wrong result, not as a style preference. - **`affect.py` imports no torch and holds no tensor.** ψ is built from `loss.item()`. If gradient flowed through it, ψ would quietly become a learned latent and there would be no oracle for what it means. - **Autograd only.** No hand-written backward passes. - **Affect axes are read by name** (`valence`, `arousal`). `Organism.forward` is the single sanctioned place a `(valence, arousal)` tuple is unpacked positionally, via `Affect.axes`. - **`kappa = 0` is one flag** that removes the affect term from the gate and changes nothing else. It is the control every affect claim is measured against, so it must not acquire a second code path. - **Memory is keyed by stable entity id.** Entities that appear get fresh zero state; entities that leave drop out of the returned dict. No unbounded growth. - **`detach_memory` detaches, it does not clear.** State survives the truncated-BPTT boundary; only the graph is cut. - **CPU, small, no configuration nobody asked for.** No device handling, no batching. ## Tests `uv run pytest -q` from this directory. **A test that cannot fail is worse than no test.** This has bitten this repo twice: a full suite passed against an `Organism` that ignored its memory argument entirely, and against a CPPN whose comment described an initialisation that did not exist. When a test defends a central property, break the property on purpose and confirm the test fails. Say so in your report. The properties currently defended, which you should not weaken: - translation invariance and permutation equivariance of the RP (both structural — `core.py` never receives raw coordinates, only differences) - masked aggregation counts unmasked neighbours and cannot produce NaN - the gate's direction: rising arousal lowers `g` toward the present - memory is load-bearing: zeroing a survivor's incoming state must change the output - gradient flows through memory across steps, not merely through the current step ## Calibration knobs `omega` scales the CPPN's sine pre-activation and sets the kernel bandwidth. It wants tuning against the domain's length scale and is deliberately a named parameter, not a constant. The first layer keeps PyTorch's default init on purpose — the comment says so, and it says so because an earlier comment claimed an initialisation that was not there. ## Conventions Python ≥3.11, `uv`, PyTorch, pytest. Commit inside this repo only.