Spaces:
Running
Running
fix: resolve merge conflicts, finalize inference + README
Browse filesFiles changed (7)
41 unmodified lines4243444546454647484941 unmodified linesdocker run --rm -p 7860:7860 -p 7861:7861 --name gridmind gridmind-rl```
- **7860** — Environment API (OpenEnv / agent traffic) - **7861** — Web dashboard (optional)- **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 lines3132333435343536373738394035 unmodified lines76777879798081828384838485868710 unmodified lines989910010110110210310410510510610710830 unmodified lines rc := 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. // Shift from pure penalty to a positive baseline: standardizing operations gives positive reward. // Baseline reward of 1.5, minus the relative cost. typicalCost := 4.0 rc.CostSavings = -(inp.StepCost / typicalCost) * 2.0 rc.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 (and optional overlay on others). // Low-carbon bonus: active for task 3. if inp.TaskID >= 3 { // Normalise carbon: iso-ne range roughly 100–700 gCO2/kWh carbonNorm := (inp.B.CarbonIntensity - 100.0) / 600.0 // Reward for reducing energy during high-carbon periods rc.CarbonReward = -inp.EnergyKWh * carbonNorm * 0.3 // Provide a baseline positive score, reduced by carbon footprint rc.CarbonReward = 0.5 - (inp.EnergyKWh * carbonNorm * 0.3) }
// ── Aggregate ────────────────────────────────────────────────────────────10 unmodified lines // Gaussian-shaped bonus: maximum at setpoint, degrades toward bounds deviation := math.Abs(temp - setpoint) sigma := (tMax - tMin) / 4.0 return math.Exp(-0.5*(deviation/sigma)*(deviation/sigma)) * 0.5 return math.Exp(-0.5*(deviation/sigma)*(deviation/sigma)) * 1.5 // Increased positive reward } // Outside bounds: proportional penalty excess := math.Max(temp-tMax, tMin-temp) return -excess * 0.4 return -excess * 0.6}
// computeGridResponse returns a bonus for shedding load during high grid stress,7 unmodified lines8910111213147 unmodified lines
author: LOKyu Teamtags: - openenv - reinforcement-learning - energy - demand-response4 unmodified lines5678891015 unmodified lines26272830293031323393 unmodified lines12712812913013113213313413513613713837 unmodified lines176177178179177180181182183184185186187121 unmodified lines3093103113053123133144 unmodified linesUses OpenAI-compatible API via API_BASE_URL / MODEL_NAME / HF_TOKEN environment variables.
Usage: export API_BASE_URL=https://router.huggingface.co/v1 export MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct export HF_TOKEN=hf_xxxx python 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")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 lines api_key=HF_TOKEN if HF_TOKEN else "none", ) self.model = MODEL_NAME self.fallback_mode = False
def 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 lines action = 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: {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 = True return self._heuristic_action(obs) time.sleep(1)
return self._heuristic_action(obs)121 unmodified lines
elapsed = time.time() - start_time grade = 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