An open API service indexing awesome lists of open source software.

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.

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.