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

https://github.com/rudra496/worldsim-ai

๐ŸŒ WorldSim AI โ€” AI-powered world simulation engine. Generate, explore & interact with dynamic virtual worlds. For research, gaming & creative storytelling.
https://github.com/rudra496/worldsim-ai

3d ai ai-simulation creative-ai digital-twin game-ai generative-ai hacktoberfest llm llm-agent machine-learning open-source predictive-modeling procedural-generation python reinforcement-learning simulation virtual-worlds world-generation

Last synced: 15 days ago
JSON representation

๐ŸŒ WorldSim AI โ€” AI-powered world simulation engine. Generate, explore & interact with dynamic virtual worlds. For research, gaming & creative storytelling.

Awesome Lists containing this project

README

          


Star History Chart



WorldSim AI

# ๐ŸŒ WorldSim AI

**AI-Powered Digital Twin Simulation Platform**


Model, predict, and optimize real-world systems โ€” smart cities, factories, energy grids, logistics networks, and more. Feature-rich agent-based simulation with real-time 3D visualization, reinforcement learning, IoT data ingestion, distributed scaling, and digital twin capabilities. Free and open-source (MIT).

> If you find this project useful, please consider giving it a โญ star โ€” it helps more developers discover it!

[![GitHub stars](https://img.shields.io/github/stars/rudra496/worldsim-ai?style=social)](https://github.com/rudra496/worldsim-ai/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/rudra496/worldsim-ai?style=social)](https://github.com/rudra496/worldsim-ai/network/members)
[![GitHub watchers](https://img.shields.io/github/watchers/rudra496/worldsim-ai?style=social)](https://github.com/rudra496/worldsim-ai/watchers)
[![GitHub discussions](https://img.shields.io/github/discussions/rudra496/worldsim-ai)](https://github.com/rudra496/worldsim-ai/discussions)

[![Python 3.10+](https://img.shields.io/badge/Python-3.10+-3776AB.svg?style=flat&logo=python&logoColor=white)](https://python.org)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.104+-009688.svg?style=flat&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com)
[![React](https://img.shields.io/badge/React-18-61DAFB.svg?style=flat&logo=react&logoColor=black)](https://reactjs.org)
[![Three.js](https://img.shields.io/badge/Three.js-0.160-000000.svg?style=flat&logo=three.js&logoColor=white)](https://threejs.org)
[![NumPy](https://img.shields.io/badge/NumPy-1.24+-013243.svg?style=flat&logo=numpy&logoColor=white)](https://numpy.org)
[![PyTorch](https://img.shields.io/badge/PyTorch-Optional-EE4C2C.svg?style=flat&logo=pytorch&logoColor=white)](https://pytorch.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat)](LICENSE)
[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg?style=flat&logo=docker&logoColor=white)](https://docker.com)
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat)](CONTRIBUTING.md)
[![v0.1.0](https://img.shields.io/badge/Release-v0.1.0-2ea44f.svg?style=flat)](https://github.com/rudra496/worldsim-ai/releases/tag/v0.1.0)

---

## โšก One Command Start

```bash
git clone https://github.com/rudra496/worldsim-ai.git
cd worldsim-ai
docker-compose up --build
# ๐Ÿ‘‰ Open http://localhost:3000
```

๐Ÿ“ฆ Alternative: Python-only (no frontend)

```bash
pip install -r requirements.txt
python run_demo.py
```

๐Ÿ”ง Alternative: Full local development

```bash
# Backend
pip install -r requirements.txt
uvicorn worldsim.api.main:app --reload --port 8000

# Frontend (separate terminal)
cd frontend && npm install && npm start
```

---

## โœจ Complete Feature Set

### ๐Ÿงฌ Agent-Based Modeling
- **4 agent types**: Vehicle, Human, Machine, EnergyUnit โ€” each with customizable properties
- **Rule-based & probabilistic behaviors** โ€” deterministic or stochastic movement, production, consumption
- **Multi-agent AI system** โ€” autonomous Planner, Predictor, and Optimizer agents coordinate via AgentCoordinator

### ๐ŸŒ Environment Modeling
- **2D grid & graph world** representations with configurable dimensions
- **8 zone types**: residential, industrial, commercial, road, park, power_plant, water_treatment, warehouse
- **Resource management** โ€” energy, water, materials, bandwidth with production/consumption tracking

### ๐Ÿง  AI & Machine Learning
- **PyTorch LSTM predictor** โ€” deep time-series forecasting (NumPy fallback when PyTorch unavailable)
- **Autoencoder anomaly detection** โ€” unsupervised drift and outlier detection
- **LP-based resource optimization** โ€” scipy linear programming for allocation
- **Priority scheduling** โ€” greedy heuristic for task ordering
- **Reinforcement learning** โ€” Gymnasium-compatible environment with PPO/Q-learning agents
- **Adaptive feedback loops** โ€” simulation โ†’ AI prediction โ†’ optimization โ†’ correction cycle

### ๐ŸŽฎ 3D Visualization (Three.js)
- **Interactive 3D world** via React Three Fiber โ€” orbit, pan, zoom controls
- **3D zone rendering** โ€” translucent colored boxes with zone type labels
- **Agent 3D objects** โ€” vehicles (boxes), humans (spheres), machines (cylinders), energy (glowing spheres)
- **Day/night cycle** โ€” toggle between ambient lighting modes
- **2D โ†” 3D switcher** โ€” seamless view switching

### ๐Ÿ“ก Real-Time Data Ingestion
- **MQTT source** โ€” subscribe to IoT sensor topics with JSON parsing (requires `paho-mqtt`)
- **File source** โ€” CSV/JSON/JSONL ingestion with live tail support
- **REST API source** โ€” periodic polling of external endpoints
- **Simulator source** โ€” synthetic data with noise, drift, and failure injection
- **Alert manager** โ€” CRITICAL/WARNING/INFO with configurable callbacks

### ๐Ÿ–ฅ Distributed Simulation
- **Multi-node engine** โ€” extends core engine for horizontal scaling
- **Spatial partitioning** โ€” grid-based agent distribution across nodes
- **Load balancing** โ€” threshold-based rebalancing with migration plans
- **gRPC protocol** โ€” dataclass-based message serialization (no protoc required)

### ๐Ÿ™ Digital Twin
- **Live/replay/hybrid sync** modes โ€” mirror real-world data or replay historical patterns
- **GIS integration** โ€” GeoJSON loading, coordinate transforms, geofencing with ray-casting
- **Plugin system** โ€” hot-reloadable plugins with ABC interface
- **Built-in plugins** โ€” LoggingPlugin, MetricsExportPlugin (Prometheus), SlackNotifyPlugin
- **Plugin marketplace** โ€” local catalog with built-in plugins (extensible to remote registries)
- **REST + WebSocket connector** โ€” push/pull state, bidirectional sync
- **API key auth** with role-based access control
- **Rate limiting** โ€” token bucket algorithm

### ๐Ÿ“Š Dashboard & API
- **React SPA** โ€” dark theme, responsive, works standalone in demo mode
- **Real-time WebSocket** โ€” live simulation streaming to frontend
- **9 API endpoints** โ€” scenarios, simulations, results, metrics, health + WebSocket
- **Metrics charts** โ€” recharts for throughput, efficiency, stability, utilization
- **CLI tool** โ€” `worldsim run`, `list`, `demo`, `serve`

### ๐Ÿ”ฌ Research Framework
- โœ… **Deterministic mode** โ€” Same seed โ†’ identical results (reproducible experiments)
- โœ… **State snapshots** โ€” Checkpoint and restore at any tick
- โœ… **Event bus** โ€” Full pub/sub for simulation events
- โœ… **Multiple export formats** โ€” JSON, CSV, structured text reports
- โœ… **Config-driven** โ€” YAML configs, no hardcoded values

---

## ๐Ÿ—บ Roadmap

| Version | Status | Description |
|---------|--------|-------------|
| **v0.1** | โœ… Done | Core engine, 4 agent types, grid/graph worlds, AI prediction + optimization, 8 scenarios, REST + WebSocket API, React dashboard, Docker |
| **v0.2** | โœ… Done | PyTorch LSTM predictor (NumPy fallback), autoencoder anomaly detection, Gymnasium RL env, PPO/Q-learning agents, multi-agent AI system, adaptive feedback loops |
| **v0.3** | โœ… Done | Three.js 3D world (React Three Fiber), orbit controls, 3D zones/agents with glow, day/night cycle, 2Dโ†”3D view switcher |
| **v0.4** | โœ… Done | MQTT/File/API/Simulator data sources, ingestion pipeline, ring buffer, data transformer, alert manager |
| **v0.5** | โœ… Done | Multi-node distributed engine, spatial partitioning, load balancing, gRPC protocol, message serialization |
| **v1.0** | โœ… Done | Digital twin core (live/replay/hybrid), GIS integration, plugin system + marketplace, REST/WebSocket connector, API auth, rate limiting |

> ๐Ÿ“– See [ROADMAP.md](ROADMAP.md) for detailed feature checklists.

---

## ๐Ÿ— Architecture

```mermaid
graph TB
subgraph Presentation ["๐Ÿ–ฅ๏ธ Presentation Layer"]
UI["React Dashboard"]
Canvas["2D Canvas"]
Three["3D View (Three.js)"]
Charts["Metrics Charts"]
end

subgraph API ["๐Ÿ“ก API Layer"]
REST["REST Endpoints"]
WS["WebSocket"]
CLI["CLI Tool"]
end

subgraph Core ["โš™๏ธ Simulation Core"]
Engine["Simulation Engine
S(t+1) = F(S(t), A(t), E(t))"]
Events["Event Bus"]
State["State Manager"]
end

subgraph Models ["๐Ÿงฌ Modeling Layer"]
Agents["Agent System (4 types)"]
Env["Environment (Grid + Graph)"]
Scenarios["Scenario Engine"]
end

subgraph AI ["๐Ÿง  Intelligence Layer"]
Predict["LSTM Predictor"]
Detect["Anomaly Detector"]
Optimize["LP Optimizer"]
RL["RL Agents (PPO)"]
MAS["Multi-Agent System"]
Feedback["Feedback Loops"]
end

subgraph DataIO ["๐Ÿ“ก Data Layer"]
MQTT_S["MQTT Source"]
File_S["File Source"]
API_S["API Source"]
Sim_S["Simulator Source"]
end

subgraph Twin ["๐Ÿ™ Digital Twin"]
GIS["GIS / GeoJSON"]
Plugins["Plugin System"]
Market["Marketplace"]
Connector["Twin Connector"]
end

subgraph Dist ["๐Ÿ“Š Distributed"]
Nodes["Simulation Nodes"]
Partition["Spatial Partitioning"]
GRPC["gRPC Protocol"]
end

UI --> REST
UI --> WS
CLI --> Engine
REST --> Engine
WS --> Engine
Engine --> Agents
Engine --> Env
Engine --> Events
Engine --> State
Scenarios --> Engine
Predict --> Engine
Detect --> Engine
Optimize --> Engine
RL --> Engine
MAS --> Engine
Feedback --> Engine
MQTT_S --> Engine
File_S --> Engine
API_S --> Engine
Sim_S --> Engine
GIS --> Engine
Plugins --> Engine
Market --> Plugins
Connector --> Engine
Nodes --> Engine
Partition --> Nodes
GRPC --> Nodes
```

### Formal Model

Every simulation step follows:

```
S(t+1) = F(S(t), A(t), E(t))
```

- **S(t)** โ€” System state at time t (resources, metrics, counters)
- **A(t)** โ€” Agent actions at time t (movement, production, consumption)
- **E(t)** โ€” Environment factors at time t (zones, traffic, energy grid)
- **F** โ€” Transition function (combines all inputs โ†’ next state)

---

## ๐ŸŽฎ Demo Scenarios

| # | Scenario | Description | Agents | Zones | Ticks |
|---|----------|-------------|--------|-------|-------|
| ๐Ÿ™๏ธ | **Smart City Traffic** | Urban traffic with vehicles & pedestrians across mixed-use city zones | 105 | 8 | 300 |
| ๐Ÿญ | **Factory Optimization** | Production line with machines, workers, and energy constraints | 68 | 3 | 500 |
| โšก | **Energy Balancing** | Multi-source energy grid with varying demand patterns | 85 | 8 | 400 |
| ๐ŸŒค๏ธ | **Weather System** | Weather patterns with temperature, precipitation, and wind feedback | 90 | 13 | 600 |
| ๐Ÿ‘ฅ | **Population Dynamics** | Population growth, migration, and resource competition | 133 | 10 | 500 |
| ๐Ÿ”— | **Supply Chain** | Multi-node supply chain with factories, warehouses, and retail | 110 | 10 | 400 |
| ๐ŸŒพ | **Smart Agriculture** | Precision agriculture with irrigation and automated harvesting | 65 | 10 | 500 |
| ๐Ÿšจ | **Emergency Failure** | System resilience testing under power outages and breakdowns | 76 | 6 | 400 |

---

## ๐Ÿ“ Project Structure

```
worldsim-ai/
โ”œโ”€โ”€ ๐Ÿ worldsim/ # Python simulation engine
โ”‚ โ”œโ”€โ”€ core/ # Engine, state, events
โ”‚ โ”œโ”€โ”€ agents/ # Agent-based modeling (4 types)
โ”‚ โ”œโ”€โ”€ environment/ # World, zones, resources
โ”‚ โ”œโ”€โ”€ ai/ # Intelligence layer
โ”‚ โ”‚ โ”œโ”€โ”€ predictor.py # Linear regression, moving average
โ”‚ โ”‚ โ”œโ”€โ”€ optimizer.py # LP resource allocation
โ”‚ โ”‚ โ”œโ”€โ”€ ml_models.py # PyTorch LSTM, anomaly detection
โ”‚ โ”‚ โ”œโ”€โ”€ reinforcement_learning.py # Gymnasium RL, PPO/Q-learning
โ”‚ โ”‚ โ”œโ”€โ”€ multi_agent_system.py # Planner, Predictor, Optimizer agents
โ”‚ โ”‚ โ””โ”€โ”€ feedback.py # Adaptive feedback loops
โ”‚ โ”œโ”€โ”€ scenarios/ # 4 demo scenario configs
โ”‚ โ”œโ”€โ”€ api/ # FastAPI REST + WebSocket
โ”‚ โ”œโ”€โ”€ io/ # Data ingestion (MQTT, File, API, Sim)
โ”‚ โ”œโ”€โ”€ distributed/ # Multi-node simulation
โ”‚ โ”œโ”€โ”€ twin/ # Digital twin, GIS, plugins, marketplace
โ”‚ โ”œโ”€โ”€ data/ # Data pipeline & generation
โ”‚ โ”œโ”€โ”€ utils/ # Config, metrics, CLI
โ”‚ โ””โ”€โ”€ cli.py # worldsim command-line tool
โ”‚
โ”œโ”€โ”€ โš›๏ธ frontend/ # React visualization
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ components/ # Canvas, Charts, Controls, World3D
โ”‚ โ”‚ โ”œโ”€โ”€ services/api.js # Backend API client
โ”‚ โ”‚ โ”œโ”€โ”€ utils/simulation.js # Color maps, demo data
โ”‚ โ”‚ โ””โ”€โ”€ App.js # Main dashboard (2D + 3D)
โ”‚ โ”œโ”€โ”€ Dockerfile # Multi-stage build (node โ†’ nginx)
โ”‚ โ””โ”€โ”€ nginx.conf # API proxy + SPA fallback
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ config/ # YAML configurations
โ”œโ”€โ”€ ๐Ÿงช tests/ # Test suite
โ”œโ”€โ”€ ๐Ÿ“„ docs/ # Architecture, simulation guide
โ”œโ”€โ”€ ๐Ÿณ docker-compose.yml # One-command deploy (4 services)
โ”œโ”€โ”€ ๐Ÿณ Dockerfile # Backend image
โ”œโ”€โ”€ ๐Ÿ“‹ pyproject.toml # Python packaging + optional deps
โ””โ”€โ”€ ๐ŸŽฎ run_demo.py # Quick demo runner
```

---

## ๐Ÿ›  Tech Stack

| Layer | Technology |
|-------|-----------|
| **Simulation** | Python 3.11+, NumPy, SciPy |
| **AI/ML** | PyTorch (optional), Gymnasium (optional), stable-baselines3 (optional) |
| **API** | FastAPI, Uvicorn, WebSockets |
| **Frontend** | React 18, Three.js, React Three Fiber, recharts, HTML5 Canvas |
| **IoT** | paho-mqtt (optional) |
| **Distributed** | gRPC (optional), pickle/zlib |
| **Digital Twin** | GeoJSON, shapely (optional) |
| **Deployment** | Docker, Nginx |

---

## ๐Ÿ“Š API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| `GET` | `/` | API health & info |
| `GET` | `/scenarios` | List available scenarios |
| `POST` | `/simulations/start` | Start a new simulation |
| `GET` | `/simulations` | List all simulations |
| `GET` | `/simulations/{id}` | Get simulation status |
| `GET` | `/simulations/{id}/results` | Get simulation results |
| `GET` | `/simulations/{id}/metrics` | Get aggregated metrics |
| `GET` | `/health` | Health check |
| `WS` | `/ws/simulations/{id}` | Real-time updates |

---

## ๐Ÿค Contributing

Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

- ๐Ÿ†• New agent types and behavior models
- ๐ŸŒ New scenarios (epidemics, supply chain, climate...)
- ๐Ÿ“Š Visualization improvements
- ๐Ÿ”Œ New plugins for the marketplace
- ๐Ÿ“ Documentation & tutorials
- ๐Ÿ› Bug reports and feature requests

---

## ๐Ÿ“„ License

[MIT License](LICENSE) โ€” free for personal and commercial use.

---

## ๐Ÿ‘จโ€๐Ÿ’ป Author

**Rudra Sarker**

[![GitHub](https://img.shields.io/badge/GitHub-rudra496-181717?style=flat&logo=github)](https://github.com/rudra496)
[![Twitter/X](https://img.shields.io/badge/X-@Rudra496-000000?style=flat&logo=x)](https://twitter.com/Rudra496)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-Rudra_Sarker-0A66C2?style=flat&logo=linkedin)](https://www.linkedin.com/in/rudrasarker)
[![Facebook](https://img.shields.io/badge/Facebook-Rudra_Sarker-1877F2?style=flat&logo=facebook)](https://www.facebook.com/rudrasarker130)
[![Website](https://img.shields.io/badge/Website-rudra496.github.io-1DA1F2?style=flat&logo=firefox)](https://rudra496.github.io/site)
[![ResearchGate](https://img.shields.io/badge/ResearchGate-Rudra_Sarker-00CCBB?style=flat&logo=researchgate)](https://www.researchgate.net/profile/Rudra-Sarker-3)
[![SUST](https://img.shields.io/badge/SUST-Student-6C63FF?style=flat)](https://www.sust.edu)


๐Ÿš€ Open Source Developer | AI tools, code analysis & developer education


Creator of TermMind, CodeVista, DevRoadmaps & SignLanguage Dataset Hub



*Model the world. Optimize the future. Open source forever.* ๐ŸŒ

## Connect

- [![GitHub](https://img.shields.io/badge/GitHub-rudra496-181717?logo=github)](https://github.com/rudra496)
- [![LinkedIn](https://img.shields.io/badge/LinkedIn-rudrasarker-0A66C2?logo=linkedin)](https://www.linkedin.com/in/rudrasarker)
- [![X/Twitter](https://img.shields.io/badge/X-@Rudra496-000000?logo=x)](https://x.com/Rudra496)
- [![YouTube](https://img.shields.io/badge/YouTube-@rudrasarker9732-FF0000?logo=youtube)](https://youtube.com/@rudrasarker9732)
- [![Dev.to](https://img.shields.io/badge/Dev.to-rudra__sarker-000000?logo=devdotto)](https://dev.to/rudra_sarker)