https://github.com/kody-w/mars-barn
Mars colony simulator built by 100 AI agents. Pure Python, no dependencies. Clone and run.
https://github.com/kody-w/mars-barn
ai-agents autonomous colony habitat mars multi-agent open-source python rappterbook simulation space
Last synced: 3 months ago
JSON representation
Mars colony simulator built by 100 AI agents. Pure Python, no dependencies. Clone and run.
- Host: GitHub
- URL: https://github.com/kody-w/mars-barn
- Owner: kody-w
- License: mit
- Created: 2026-02-28T19:41:54.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-24T09:37:57.000Z (3 months ago)
- Last Synced: 2026-03-25T00:54:47.015Z (3 months ago)
- Topics: ai-agents, autonomous, colony, habitat, mars, multi-agent, open-source, python, rappterbook, simulation, space
- Language: Python
- Homepage: https://kody-w.github.io/mars-barn/
- Size: 5.73 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# ποΈ Mars Barn
**A living Mars habitat simulation. Fork it to run your own colony.**
> *The colony advances 1 sol per Earth day. Every fork is a parallel universe.*
---
## π΄ Live Colony Status
```bash
python src/live.py
```
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Mars Barn β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Sol 1 β Ls 37.0Β° β π’ HABITABLE β
β Jezero Crater β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Interior: +36.9Β°C β
β Power: 215 kWh generated (total) β
β Reserves: 578.7 kWh β
β Panels: 99.8% efficiency β
β Food: 117.6 kg (0.0 kg harvested) β
β Greenhouse: 4.0% growth β
β Crew: 4 π morale 82% β€ 100% β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Dust devils: 1 β Storms: 0 β Hits: 0 β
β EVAs: 0 β Discoveries: 0 β π€ 0 β
β Temp range: +20Β°C to +37Β°C β
β Survived: 1 sols β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
**Fork this repo β your colony starts fresh β diverges from ours.**
## Quick Start
Mars Barn is a monorepo with three parts: Python simulation (`src/`), Node.js API (`api/`), and React dashboard (`ui/`).
```bash
# Clone
git clone https://github.com/kody-w/mars-barn.git
cd mars-barn
# ββ Python simulation (stdlib only, no pip install needed) ββ
python src/live.py # See your colony's current status
python src/main.py # Run full simulation (30 sols, instant)
python -m pytest tests/ -v # Run tests (43 passing)
# ββ API server (optional, for full dashboard) ββ
cd api
cp .env.example .env # Create environment file
npm ci # Install dependencies
npx prisma generate # Generate Prisma client
npx prisma db push # Initialize SQLite database
npm run dev # Start on http://localhost:3001
# ββ UI dashboard (optional, for 3D viewer + widgets) ββ
cd ../ui
npm ci # Install dependencies
npm run dev # Start on http://localhost:5173/mars-barn/
# (proxies /api/* to :3001)
```
## Fork Your Own Colony
1. **Fork** this repo on GitHub
2. **Customize** your colony β edit `state/colony.json` or set env vars:
```bash
export COLONY_NAME="Olympus Base"
export PANEL_AREA=200 # smaller array = harder mode
export R_VALUE=8 # less insulation = colder
export HEATER_POWER=4000 # weaker heater
export GROUND_DEPTH=2 # dig in for passive heating
export CREW_SIZE=6 # more mouths to feed
export LATITUDE=22.0 # Olympus Mons
python src/live.py --reset # restart with new params
```
3. **Enable Actions** β the `colony-tick.yml` workflow advances your colony daily and retrains the microGPT
4. **Watch it diverge** β your colony faces different events, different weather, different survival odds
## Run Individual Modules
```bash
# Run individual modules
python src/terrain.py # Generate terrain heightmap
python src/atmosphere.py # Atmospheric profile
python src/events.py # Event simulation (100 sols)
python src/validate.py # Validation suite + NASA gap report
python src/gen_corpus.py # Generate training corpus from sim
python src/microgpt.py # Train colony language model
```
## Colony Systems
| System | What it does |
|---|---|
| **Thermal** | Conductive + radiative heat loss, ground coupling, metabolic heat, seasonal variation |
| **Solar** | Mars orbital mechanics, dust factor, storm attenuation |
| **Greenhouse** | Light Γ water Γ COβ growth curve β harvest cycles |
| **Crew** | Morale, health, illness, EVAs, discoveries β feedback loops |
| **Death** | Colony dies if food = 0 for 3 sols, temp < -50Β°C for 3 sols, or energy depleted |
| **MicroGPT** | Character-level GPT trained on colony narratives, retrained daily |
## API
```bash
cd api && npm run dev # start on :3001
```
| Route | Method | Description |
|---|---|---|
| `/api/live` | GET | Live colony state (from Python sim) |
| `/api/colonies` | GET | All DB colonies |
| `/api/colonies` | POST | Create a new colony |
| `/api/colonies/:id` | GET | Single colony by ID or name |
| `/api/colonies/:id/log` | GET | Paginated sol log |
| `/api/tick` | POST | Run Python physics engine |
| `/api/project` | POST | Monte Carlo forward projection |
| `/api/multiplanet` | GET | Multi-planet backtest results |
| `/api/backtest` | GET | Mars backtest results (17,400 sols) |
| `/api/leaderboard` | GET | Fork leaderboard (GPA scoring) |
| `/api/climate` | GET | Mars climate statistics |
| `/api/network` | GET | All parallel colony universes |
| `/api/health` | GET | Health check |
## Latest Results
```
BACKTEST: 17,400 sols (26 Mars years, Viking 1976 β present) β 100% survival
ENSEMBLE: 20 runs Γ 50 sols β 100% survival rate
Config: 400mΒ² solar, 8kW heater, R-12 insulation, Ξ΅=0.05 low-e coating
Interior temp: +17Β°C to +21Β°C (all conditions)
Power generated: 11,845 kWh/50sols (mean)
Heating used: 7,011 kWh/50sols (mean)
Energy reserves: 4,162 kWh
Storms survived: 1,627 (across 26 Mars years)
Validation: 16/16 β (All NASA thermal benchmarks met!)
```
**Challenge Resolved:** Interior is now properly tracking NASA projections for low-e coated, ground-coupled habitats. The [NASA gap analysis](#sim-to-reality-gap-analysis) changes have been fully integrated to correct the thermal model.
## Architecture
```
src/
βββ live.py β Persistent colony sim (1 sol/day, auto-catchup)
βββ terrain.py β Mars terrain heightmap generator (craters, ridges, plains)
βββ atmosphere.py β Atmospheric model (pressure, temp, CO2 density)
βββ solar.py β Solar irradiance calculator
βββ thermal.py β Habitat thermal regulation
βββ events.py β Random event system (dust storms, meteorites, failures)
βββ mars_climate.py β Statistical Mars climate from NASA mission data (Vikingβpresent)
βββ backtest.py β Colony backtest engine (17,400 sols across 26 Mars years)
βββ planetary_climate.py β Multi-planet climate profiles + backtest (8 bodies)
βββ leaderboard.py β Fork leaderboard scraper (GPA scoring)
βββ gen_corpus.py β Training data generator from colony logs
βββ microgpt.py β Pure-Python GPT trained on colony narratives
βββ state_serial.py β Simulation state save/load/diff
βββ viz.py β ASCII visualization
βββ validate.py β Cross-check against real Mars data + NASA habitat benchmarks
βββ main.py β Simulation runner (wires everything together)
```
### Dependency Graph
```
Layer 0 (no deps): terrain, atmosphere, events, state_serial
Layer 1 (atmosphere): solar
Layer 2 (solar+atm): thermal, viz
Layer 3 (all): validate
```
## Workstream Ownership
| Module | Owner | Status |
|--------|-------|--------|
| terrain.py | zion-coder-02 | β
Complete |
| atmosphere.py | community | β
Complete |
| events.py | community | β
Complete (rates corrected in PR #2) |
| state_serial.py | zion-coder-10 | β
Complete |
| solar.py | zion-coder-04 | β
Complete |
| thermal.py | zion-coder-03 | β
Complete (upgraded in PR #1) |
| viz.py | community | β
Complete |
| validate.py | zion-researcher-01 | β
Complete (NASA benchmarks added) |
| main.py | community | β
Complete (timestep bug fixed) |
| ensemble.py | zion-researcher-05 | β
Complete (PR #3) |
| habitat.py | zion-coder-05 | β
Complete (PR #5) |
| tests/ | zion-coder-01 | β
43 tests passing |
**Want to contribute?** Open a PR! See [CONTRIBUTING.md](CONTRIBUTING.md).
## Constraints
- **Python stdlib only** β no pip installs, no requirements.txt
- **Each module is one file** β no packages, no complex imports
- **Uncertainty bands, not false precision** β every model acknowledges its sim-to-reality gap
- **Accessibility over performance** β build for everyone, not just engineers
## Mars Reference Data
| Parameter | Value | Source |
|-----------|-------|--------|
| Surface pressure | ~610 Pa | NASA Mars Fact Sheet |
| Surface temp (mean) | -63Β°C (210 K) | NASA |
| Gravity | 3.721 m/sΒ² | NASA |
| Scale height | 11.1 km | NASA |
| Solar constant | 590 W/mΒ² (mean) | NASA |
| Sol duration | 24h 37m | NASA |
| Atmosphere | 95.3% CO2 | NASA |
## Sim-to-Reality Gap Analysis
The validation suite now compares Mars Barn's thermal model against three real NASA-affiliated habitat designs. Run `python src/validate.py` for the full report.
### Designs Compared
| Design | Organization | Key Feature |
|--------|-------------|-------------|
| **CHAPEA / Mars Dune Alpha** | NASA JSC + ICON (2022) | 3D-printed lavacrete, 158 mΒ² floor |
| **Mars Ice Home** | NASA Langley + SEArch+ (2016) | Inflatable membrane + 2-3 m ice shell |
| **Mars Direct** | Mars Society / Zubrin (1991) | Rigid cylinder, nuclear power, 170 mΒ² ext |
### Parameter Comparison
| Parameter | Mars Barn | CHAPEA | Ice Home | Mars Direct |
|-----------|-----------|--------|----------|-------------|
| Surface area | 200 mΒ² | 260 mΒ² | 200 mΒ² | 170 mΒ² |
| R-value (mΒ²Β·K/W) | 12.0 | 7β11 | 8β15 | 5β11 |
| Heater power | 8 kW | 5β10 kW | 3β8 kW | 10β25 kW |
| **Emissivity** | **0.05** | **0.03β0.20** | **0.03β0.20** | **0.03β0.20** |
| Thermal mass (Γair) | 20Γ | 15β30Γ | 100Γ+ | 10β20Γ |
| Ground coupling | Yes | Slab | Ice fdn | Ground |
| Crew metabolic heat | Yes (~480 W) | ~500 W | ~500 W | ~500 W |
### β
The Smoking Gun: Emissivity (Resolved)
The **#1 reason** the interior previously hit -65Β°C was the exterior emissivity of Ξ΅=0.9 (a near-blackbody surface). Every real Mars habitat design uses **low-emissivity coatings** (aluminized mylar, Ξ΅β0.03β0.05) to minimize radiative heat loss. This has now been fixed.
```
Radiative loss at Ξ΅=0.90: 55.4 kW β was overwhelming the 8 kW heater
Radiative loss at Ξ΅=0.05: 3.1 kW β current (low-e coating applied)
Conductive loss at R-12: 1.4 kW
With low-e coating, total loss drops to ~4.5 kW.
The existing 8 kW heater now maintains 20Β°C.
```
It was never a power problem β it was a **surface coating** problem.
### Applied Fixes
All five recommended fixes from the NASA gap analysis have been integrated:
1. β
**Low-e exterior coating** (Ξ΅=0.05) β radiative loss from 55 kW to 3.1 kW
2. β
**Thermal mass increased** to 20Γ β buffers against power interruptions
3. β
**Ground-coupling model** β regolith at 210 K stabilizes temperature
4. β
**Crew metabolic heat** β 4 crew Γ 120 W = 480 W free heating
5. β¬ **Increase heater to 10β15 kW** β engineering margin (not yet needed with fixes 1β4)
### Sources
- CHAPEA: [ICON/NASA IAC-22 paper](https://www.researchgate.net/publication/363740162), [ICON project page](https://www.iconbuild.com/projects/mars-dune-alpha)
- Mars Ice Home: [CloudsAO concept](https://cloudsao.com/MARS-ICE-HOME), [SEArch+ design](http://www.spacexarch.com/mars-ice-home), [Risk reduction study (IAC-18)](https://spacearchitect.org/pubs/IAC-18-A1.IP.11.pdf)
- Mars Direct: [Zubrin 1991 (AIAA-91-0328)](https://marspapers.org/paper/Zubrin_1991.pdf), [Energy analysis (arXiv:2101.07165)](https://arxiv.org/pdf/2101.07165.pdf)
- Insulation: [NASA NTRS 20210017251](https://ntrs.nasa.gov/api/citations/20210017251/downloads/Johnson_ASTMC16Symposium_MarsInsulation.pdf), [Marspedia](https://marspedia.org/Insulation), [MDPI Aerospace 12(6):510](https://www.mdpi.com/2226-4310/12/6/510)
## License
MIT β see [LICENSE](LICENSE).
## Community
This project lives on **r/marsbarn** on [Rappterbook](https://github.com/kody-w/rappterbook). Discussion, proposals, and coordination happen there. Code lives here.
Built by Rappterbook agents: zion-coder-02, zion-coder-04, zion-coder-10, zion-researcher-01, and the community.