Spaces:
Sleeping
Sleeping
File size: 5,313 Bytes
7da907d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ๐๏ธ FairRecovery++: Fair Long-Horizon Disaster Recovery RL\n",
"\n",
"**FairRecovery++** is a production-grade multi-agent OpenEnv environment designed to train LLMs to make fair, strategic, and resilient decisions in complex post-disaster systems. It combines adaptive world-modeling, multi-agent dynamics (citizens, NGOs, adversaries), and a curriculum-weighted reward engine to teach agents to balance speed with equity.\n",
"\n",
"### ๐ Judge's Demo Guide\n",
"This notebook provides a complete environment to:\n",
"1. **Validate Integrity**: Run the full suite of 38 unit tests.\n",
"2. **Fast Evaluation**: Generate all performance reports and reward/fairness plots using a heuristic baseline.\n",
"3. **Real LLM Run**: (Optional) Execute a live training session if a GPU is available.\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Setup Environment\n",
"We install the core dependencies and clone the official repository."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Install dependencies (approx. 1-2 mins)\n",
"!pip install -U trl transformers accelerate peft bitsandbytes datasets matplotlib pytest pydantic uvicorn fastapi\n",
"\n",
"# Clone the repository\n",
"!git clone https://github.com/joshua400/FairRecovery-PlusPlus.git\n",
"\n",
"# Install the project in editable mode\n",
"%cd FairRecovery-PlusPlus\n",
"!pip install -e .[dev]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Integrity Check (38 Tests)\n",
"Verify that the environment core, multi-agent manager, reward engine, and safety shield are all functioning perfectly."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pytest tests/ -v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Fast Performance Demo (No LLM Required)\n",
"This cell runs a **heuristic-driven smoke test** that simulates 24 episodes using greedy and fair policies. This generates all the project's analytical plots instantaneously for judge review."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run the fast evaluation (uses heuristic agents to simulate environment dynamics)\n",
"!python train_sarvam_online.py --no-llm --episodes 24\n",
"\n",
"# Generate the final summary plots (Heatmap, Reward Curves, etc.)\n",
"!python generate_summary_plots.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Visual Reports & Graphs\n",
"The following plots demonstrate how the agent learns to balance **Utility** (recovery speed) with **Fairness** (equity across zones) over a long horizon."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image, display\n",
"import os\n",
"\n",
"plots = [\n",
" ('assets/training_results.png', 'Baseline vs Trained Reward Comparison'),\n",
" ('assets/score_heatmap.png', 'Per-Episode Reward Stability'),\n",
" ('assets/training_loss.png', 'Curriculum Reward Curve (Utility -> Fairness)'),\n",
" ('assets/utility_vs_fairness.png', 'Utility-Fairness Pareto Scatter')\n",
"]\n",
"\n",
"for path, title in plots:\n",
" if os.path.exists(path):\n",
" print(f\"### {title}\")\n",
" display(Image(filename=path))\n",
" print(\"\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. (Optional) Real LLM Policy Evaluation\n",
"If you have a GPU (T4/A10) and want to see the environment interact with a real language model, you can run this cell. It uses a lightweight `Qwen2.5-0.5B` model for fast inference."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Note: Requires GPU and ~5-10 mins to run\n",
"# !python train_real_llm_colab.py --episodes 5 --difficulty medium"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"### ๐ What to look for in the results:\n",
"- **Fairness Delta**: Notice how the 'Trained' policy maintains higher service parity across zones.\n",
"- **Safety Shield**: The logs will show the Shield blocking 'early-submit' exploits, forcing the agent to plan for the long horizon.\n",
"- **Stage Discipline**: The agent correctly moves through *Analyze -> Allocate -> Execute -> Adapt* stages."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|