Neural Abyss is a Python/PyTorch grid simulation with per-agent neural policies, a vectorized tick engine, an interactive Pygame viewer, and built-in persistence for long runs. The codebase combines world simulation, policy inference, per-agent PPO training, checkpoint/resume, telemetry, and optional video recording in one repository. Runtime configuration is environment-driven through FWS_* variables, and runs are written into timestamped directories under results/.
| Item | Verified from code |
|---|---|
| Language | Python |
| Core runtime | PyTorch |
| UI | Pygame viewer in ui/viewer.py |
| Entry point | main.py |
| Default grid | 100x100 |
| Default initial population | 150 agents per team |
| Observation width | 283 |
| Action count | 41 |
| Output root | results/ |
- Combat-first tick loop.
engine/tick.pyresolves observation, action selection, combat, deaths, movement, environment effects, PPO logging, and respawn in discrete ticks. - Tensor-first simulation state.
engine/agent_registry.pystores agent state in a dense struct-of-arrays tensor and keeps one brain per registry slot. - Per-agent actor-critic brains.
agent/mlp_brain.pydefines five MLP variants behind one shared observation contract and shared actor/critic interface. - Grouped inference path.
agent/ensemble.pybatches inference by architecture bucket and can switch to atorch.func/vmappath when enabled. - Per-slot PPO runtime.
rl/ppo_runtime.pymaintains rollout buffers, optimizers, schedulers, and training payloads per slot rather than using a shared policy. - Environment-driven operation.
config.pyresolves most settings fromFWS_*environment variables and supports profiles such asdefault,debug,train_fast, andtrain_quality. - Operational durability.
utils/checkpointing.py,utils/persistence.py, andutils/telemetry.pyimplement atomic checkpoint saves, background CSV writing, telemetry sidecars, and resume-in-place workflows.
.
├── main.py # runtime entry point and orchestration
├── config.py # environment-driven configuration surface
├── agent/
│ ├── mlp_brain.py # actor-critic brain family
│ ├── ensemble.py # grouped inference and optional vmap path
│ └── obs_spec.py # observation schema and tokenization helpers
├── engine/
│ ├── tick.py # core simulation loop
│ ├── agent_registry.py # slot registry and agent tensor layout
│ ├── spawn.py / respawn.py # initial spawn and respawn logic
│ ├── mapgen.py # walls, zones, map features
│ ├── ray_engine/ # raycasting backends
│ └── catastrophe.py # heal-zone catastrophe controller
├── rl/
│ └── ppo_runtime.py # per-agent PPO runtime
├── ui/
│ ├── viewer.py # interactive viewer
│ └── camera.py # camera and viewport handling
├── simulation/
│ └── stats.py # run statistics
└── utils/
├── checkpointing.py # save/load/resume utilities
├── persistence.py # background results writer
├── telemetry.py # telemetry and event logs
├── profiler.py # optional profiling hooks
└── sanitize.py # runtime sanity checks
- Read
main.pyfirst for runtime orchestration and the end-to-end control flow. - Read
engine/tick.pynext for the simulation semantics. - Read
config.pybefore changing behavior; most operational knobs live there.
The provided source dump does not include a lockfile or dependency manifest. The imports show these direct runtime dependencies:
torchnumpypygameopencv-pythononly if you want video recording viacv2
A minimal setup is therefore:
python -m venv .venv
source .venv/bin/activate
pip install torch numpy pygame opencv-pythonFrom the repository root:
python main.pyThe default configuration enables the UI. The viewer is implemented in ui/viewer.py and drives the simulation by calling engine.run_tick().
Useful built-in viewer controls:
Spacepause or resume.single-step while paused- mouse wheel zoom
F9save a manual checkpointF11toggle fullscreen
FWS_UI=0 python main.pyThis routes execution through the headless loop in main.py, keeps the writer process active, and supports periodic status printing, telemetry, and checkpoint triggers.
FWS_CHECKPOINT_PATH="results/sim_YYYY-MM-DD_HH-MM-SS/checkpoints/ckpt_t..." python main.pyutils/checkpointing.py accepts any of the following as FWS_CHECKPOINT_PATH:
- a checkpoint directory
- a direct
checkpoint.ptpath - a
checkpoints/directory that containslatest.txt
By default, resume continues writing into the original run directory when possible.
FWS_CHECKPOINT_PATH="results/sim_YYYY-MM-DD_HH-MM-SS/checkpoints/ckpt_t..." \
FWS_RESUME_OUTPUT_CONTINUITY=1 \
FWS_RESUME_FORCE_NEW_RUN=0 \
python main.pyFWS_CHECKPOINT_PATH="results/sim_YYYY-MM-DD_HH-MM-SS/checkpoints/ckpt_t..." \
FWS_INSPECTOR_MODE=ui_no_output \
python main.pyThis enables the viewer while disabling results creation, telemetry, and checkpoint writes for the inspection session.
config.py is the authoritative configuration surface. Most settings are resolved from environment variables prefixed with FWS_.
Common workflow-critical variables:
FWS_PROFILE— profile preset such asdebug,train_fast, ortrain_qualityFWS_UI— enable or disable the Pygame viewerFWS_SEED— deterministic seed used at startupFWS_CUDAandFWS_AMP— device and mixed-precision controlsFWS_CHECKPOINT_PATH— checkpoint to resume fromFWS_RESUME_OUTPUT_CONTINUITYandFWS_RESUME_FORCE_NEW_RUN— resume output policyFWS_INSPECTOR_MODE/FWS_INSPECTOR_UI_NO_OUTPUT— no-output inspection modeFWS_CHECKPOINT_EVERY_TICKSandFWS_CHECKPOINT_ON_EXIT— checkpoint cadence and exit behaviorFWS_TELEMETRY— enable or disable telemetry output
A normal run creates results/sim_YYYY-MM-DD_HH-MM-SS/. From the provided code, the main output layout is:
results/sim_YYYY-MM-DD_HH-MM-SS/
├── config.json
├── stats.csv
├── dead_agents_log.csv
├── summary.json
├── simulation_raw.avi # only when recording is enabled and OpenCV is available
├── checkpoints/
│ ├── latest.txt
│ └── ckpt_t.../
│ ├── checkpoint.pt
│ ├── manifest.json
│ ├── DONE
│ └── PINNED # optional
└── telemetry/
├── run_meta.json
├── schema_manifest.json
├── agent_life.csv
├── lineage_edges.csv
├── tick_summary.csv
├── move_summary.csv
├── ppo_training_telemetry.csv
└── events/
Operational notes:
- Checkpoints are written atomically into
run_dir/checkpoints/. latest.txtpoints to the latest complete checkpoint directory.- Headless runs can trigger a manual checkpoint by creating the configured trigger file (default:
checkpoint.now) in the run directory. - The viewer can request a manual checkpoint with
F9. - On normal exit,
main.pywritessummary.jsonand, by default, an on-exit checkpoint.
Intended license: MIT.
From the provided source dump, a repository-root LICENSE file is not verifiable. Add the standard MIT LICENSE file at repository root if it is not already present.