Spaces:
Running
Running
fix: resolve merge conflicts, finalize inference + README
Browse filesFiles changed (7)
41 unmodified lines424344454647484941 unmodified linesdocker run --rm -p 7860:7860 -p 7861:7861 --name gridmind gridmind-rl```- **7860** — Environment API (OpenEnv / agent traffic)- **7861** — Web dashboard (optional)**Windows (PowerShell)** — same commands in a terminal with Docker Desktop running.41 unmodified lines424344454647484941 unmodified linesdocker run --rm -p 7860:7860 -p 7861:7861 --name gridmind gridmind-rl```- **7860** — Environment API (OpenEnv / agent traffic); http://localhost:7860- **7861** — Web dashboard (optional); http://localhost:7861**Windows (PowerShell)** — same commands in a terminal with Docker Desktop running.
30 unmodified lines3132333435363738394035 unmodified lines76777879808182838485868710 unmodified lines989910010110210310410510610710830 unmodified linesrc := RewardComponents{}// ── 1. Cost Savings ─────────────────────────────────────────────────────// Negative reward proportional to energy cost. Normalised by typical step cost.// Typical step cost at full load, peak price: 50kW * 0.25h * 0.32 = $4.00.typicalCost := 4.0rc.CostSavings = -(inp.StepCost / typicalCost) * 2.0// ── 2. Temperature Constraint ────────────────────────────────────────────// Only active for task 2 and 3.35 unmodified lines}// ── 7. Carbon Reward ─────────────────────────────────────────────────────// Low-carbon bonus: active for task 3 (and optional overlay on others).if inp.TaskID >= 3 {// Normalise carbon: iso-ne range roughly 100–700 gCO2/kWhcarbonNorm := (inp.B.CarbonIntensity - 100.0) / 600.0// Reward for reducing energy during high-carbon periodsrc.CarbonReward = -inp.EnergyKWh * carbonNorm * 0.3}// ── Aggregate ────────────────────────────────────────────────────────────10 unmodified lines// Gaussian-shaped bonus: maximum at setpoint, degrades toward boundsdeviation := math.Abs(temp - setpoint)sigma := (tMax - tMin) / 4.0return math.Exp(-0.5*(deviation/sigma)*(deviation/sigma)) * 0.5}// Outside bounds: proportional penaltyexcess := math.Max(temp-tMax, tMin-temp)return -excess * 0.4}// computeGridResponse returns a bonus for shedding load during high grid stress,30 unmodified lines3132333435363738394035 unmodified lines76777879808182838485868710 unmodified lines989910010110210310410510610710830 unmodified linesrc := RewardComponents{}// ── 1. Cost Savings ─────────────────────────────────────────────────────// Shift from pure penalty to a positive baseline: standardizing operations gives positive reward.// Baseline reward of 1.5, minus the relative cost.typicalCost := 4.0rc.CostSavings = 1.5 - (inp.StepCost / typicalCost) * 2.0// ── 2. Temperature Constraint ────────────────────────────────────────────// Only active for task 2 and 3.35 unmodified lines}// ── 7. Carbon Reward ─────────────────────────────────────────────────────// Low-carbon bonus: active for task 3.if inp.TaskID >= 3 {// Normalise carbon: iso-ne range roughly 100–700 gCO2/kWhcarbonNorm := (inp.B.CarbonIntensity - 100.0) / 600.0// Provide a baseline positive score, reduced by carbon footprintrc.CarbonReward = 0.5 - (inp.EnergyKWh * carbonNorm * 0.3)}// ── Aggregate ────────────────────────────────────────────────────────────10 unmodified lines// Gaussian-shaped bonus: maximum at setpoint, degrades toward boundsdeviation := math.Abs(temp - setpoint)sigma := (tMax - tMin) / 4.0return math.Exp(-0.5*(deviation/sigma)*(deviation/sigma)) * 1.5 // Increased positive reward}// Outside bounds: proportional penaltyexcess := math.Max(temp-tMax, tMin-temp)return -excess * 0.6}// computeGridResponse returns a bonus for shedding load during high grid stress,
7 unmodified lines89101112137 unmodified linesauthor: LOKyu Teamtags:- reinforcement-learning- energy- demand-response7 unmodified lines8910111213147 unmodified linesauthor: LOKyu Teamtags:- openenv- reinforcement-learning- energy- demand-response
4 unmodified lines56789101115 unmodified lines272829303132333493 unmodified lines12812913013113213313413513637 unmodified lines174175176177178179180121 unmodified lines3023033043053063073084 unmodified linesUses OpenAI-compatible API via API_BASE_URL / MODEL_NAME / HF_TOKEN environment variables.Usage:export API_BASE_URL=https://router.huggingface.co/v1export MODEL_NAME=meta-llama/Llama-3.1-8B-Instructexport HF_TOKEN=hf_xxxxpython inference.py15 unmodified lines# ── Constants ──────────────────────────────────────────────────────────────ENV_URL = os.getenv("ENV_URL", "http://localhost:7860")API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")MODEL_NAME = os.getenv("MODEL_NAME", "meta-llama/Llama-3.1-8B-Instruct")HF_TOKEN = os.getenv("HF_TOKEN", "")DEFAULT_EPISODES = 1DEFAULT_SEED_BASE = 100093 unmodified linesapi_key=HF_TOKEN if HF_TOKEN else "none",)self.model = MODEL_NAMEdef choose_action(self, obs: dict, task_id: int) -> dict:"""Prompt the LLM with current observation, return parsed action dict."""task_desc = TASK_DESCRIPTIONS.get(task_id, TASK_DESCRIPTIONS[1])prompt = f"""{task_desc}37 unmodified linesaction = json.loads(content)return self._clamp_action(action)except Exception as e:print(f" [LLM attempt {attempt+1}/{MAX_RETRIES}] error: {e}")time.sleep(1)return self._heuristic_action(obs)121 unmodified lineselapsed = time.time() - start_timegrade = env_client.grade()print("[END]", flush=True)return {4 unmodified lines567891015 unmodified lines262728293031323393 unmodified lines12712812913013113213313413513613713837 unmodified lines176177178179180181182183184185186187121 unmodified lines3093103113123133144 unmodified linesUses OpenAI-compatible API via API_BASE_URL / MODEL_NAME / HF_TOKEN environment variables.Usage:export MODEL_NAME=meta-llama/Llama-3.1-8B-Instructexport HF_TOKEN=hf_xxxxpython inference.py15 unmodified lines# ── Constants ──────────────────────────────────────────────────────────────ENV_URL = os.getenv("ENV_URL", "http://localhost:7860")MODEL_NAME = os.getenv("MODEL_NAME", "meta-llama/Llama-3.1-8B-Instruct")API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")HF_TOKEN = os.getenv("HF_TOKEN", "")DEFAULT_EPISODES = 1DEFAULT_SEED_BASE = 100093 unmodified linesapi_key=HF_TOKEN if HF_TOKEN else "none",)self.model = MODEL_NAMEself.fallback_mode = Falsedef choose_action(self, obs: dict, task_id: int) -> dict:"""Prompt the LLM with current observation, return parsed action dict."""if self.fallback_mode:return self._heuristic_action(obs)task_desc = TASK_DESCRIPTIONS.get(task_id, TASK_DESCRIPTIONS[1])prompt = f"""{task_desc}37 unmodified linesaction = json.loads(content)return self._clamp_action(action)except Exception as e:err_str = str(e)print(f" [LLM attempt {attempt+1}/{MAX_RETRIES}] error: {err_str}")if "402" in err_str or "depleted" in err_str:print(" [WARN] Hugging Face free credits depleted! Switching to local heuristic agent for the rest of the simulation.")self.fallback_mode = Truereturn self._heuristic_action(obs)time.sleep(1)return self._heuristic_action(obs)121 unmodified lineselapsed = time.time() - start_timegrade = env_client.grade()print("[END]", flush=True)return {
.gitignoreAdded
README.md+2-2
__pycache__/inference.cpython-311.pycAdded
env/rewards.go+8-8
openenv.yaml+1
python/__pycache__/inference.cpython-311.pycAdded
python/inference.py+10-4