Datasets:
File size: 24,443 Bytes
47ff7c8 | 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"version_major": 2,
"version_minor": 0,
"state": {
"94f1fcd174ee4ab1acf90f6250faf7f3": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_3e3ea8bc8ece4ba7bb9cdb834c204340",
"IPY_MODEL_238d03187d094d1c9b2ebfe793a565e1",
"IPY_MODEL_1434dd4522724a02973c388a0265b813"
],
"layout": "IPY_MODEL_cc783fd3277744d58a73842d483f57af"
}
},
"3e3ea8bc8ece4ba7bb9cdb834c204340": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_bccd0d8931524cd09f26598ec3bff956",
"placeholder": "",
"style": "IPY_MODEL_43ad95de270b4cd2b43056334145cb2a",
"value": "Loading weights: 100%"
}
},
"238d03187d094d1c9b2ebfe793a565e1": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_c78a5e4d89f44be2954b32b81202d1c8",
"max": 338,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_2bc0de8e11cc4b58a9becca78d229973",
"value": 338
}
},
"1434dd4522724a02973c388a0265b813": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_457ee4bac9a24413951152fb9397f160",
"placeholder": "",
"style": "IPY_MODEL_c6c02dc44b264d80ae333a3b1859c52a",
"value": " 338/338 [00:06<00:00, 73.10it/s]"
}
},
"cc783fd3277744d58a73842d483f57af": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"bccd0d8931524cd09f26598ec3bff956": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"43ad95de270b4cd2b43056334145cb2a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"c78a5e4d89f44be2954b32b81202d1c8": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"2bc0de8e11cc4b58a9becca78d229973": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"457ee4bac9a24413951152fb9397f160": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"c6c02dc44b264d80ae333a3b1859c52a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# 1-Install dependencies"
],
"metadata": {
"id": "qARzM3TXvSzp"
}
},
{
"cell_type": "code",
"source": [
"\n",
"!pip install -q transformers accelerate torch"
],
"metadata": {
"id": "YEaYLM8rvYIt"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# 2-Import dependencies and the model"
],
"metadata": {
"id": "EyX7C1xzvZCD"
}
},
{
"cell_type": "code",
"source": [
"import json\n",
"import torch\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"\n",
"model_id = \"Qwen/Qwen2.5-1.5B-Instruct\"\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
"model = AutoModelForCausalLM.from_pretrained(\n",
" model_id,\n",
" torch_dtype=torch.float16,\n",
" device_map=\"auto\"\n",
")\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 49,
"referenced_widgets": [
"94f1fcd174ee4ab1acf90f6250faf7f3",
"3e3ea8bc8ece4ba7bb9cdb834c204340",
"238d03187d094d1c9b2ebfe793a565e1",
"1434dd4522724a02973c388a0265b813",
"cc783fd3277744d58a73842d483f57af",
"bccd0d8931524cd09f26598ec3bff956",
"43ad95de270b4cd2b43056334145cb2a",
"c78a5e4d89f44be2954b32b81202d1c8",
"2bc0de8e11cc4b58a9becca78d229973",
"457ee4bac9a24413951152fb9397f160",
"c6c02dc44b264d80ae333a3b1859c52a"
]
},
"id": "yyVK7k-tvf4R",
"outputId": "53f74931-ef95-40b6-94aa-e2835f32b24c"
},
"execution_count": 3,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"Loading weights: 0%| | 0/338 [00:00<?, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "94f1fcd174ee4ab1acf90f6250faf7f3"
}
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"#3-define the test scenarios and the result"
],
"metadata": {
"id": "L3vCmaL1viCw"
}
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_2rx-VUltmVP",
"outputId": "a658b9b7-2f18-4e92-82f0-367c5ac543f3"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"=== Category: Standard Power Grid ===\n",
"Handling a 5% voltage drop across an urban transmission feeder involves several steps to ensure safety, reliability, and compliance with standards. Here’s a general outline of the process:\n",
"\n",
"1. **Identify the Source of Voltage Drop:**\n",
" - First, identify where the voltage drop is occurring. This could be due to resistance in conductors, capacitance effects, or other factors such as transformer impedance.\n",
"\n",
"2. **Determine the Impact on Equipment:**\n",
" - Assess how the voltage drop affects the equipment it powers. For example, if the voltage drops by more than 3%, it might cause issues like reduced motor efficiency, increased heating in motors, or even damage to sensitive electronic devices.\n",
"\n",
"3. **Evaluate Feeder Capacity:**\n",
" - Check the current capacity of the feeder lines. If the line can't handle additional load without increasing its impedance (resistance), consider upgrading the conductor size or adding more feeders.\n",
"\n",
"4. **Consult Standards and Codes:**\n",
" - Refer to local building codes, utility regulations, and industry standards (like IEEE standards) that govern voltage drop requirements. These guidelines typically specify maximum allowable voltage drops based on distance from the source.\n",
"\n",
"5. **Mitigate the Voltage Drop:**\n",
" - Address the root cause of the voltage drop:\n",
" - Reduce the load on the affected section.\n",
" - Replace old, corroded, or damaged conductors with new ones.\n",
" - Add reactors at appropriate points to absorb excess reactive power and reduce voltage drop.\n",
" - Consider using higher-capacity transformers if feasible.\n",
"\n",
"6. **Implement Safety Measures:**\n",
" - Ensure all modifications comply with safety standards. This includes proper grounding, insulation, and protection against overcurrent conditions.\n",
"\n",
"7. **Monitor and Test:\n",
"\n",
"==================================================\n",
"\n",
"=== Category: Constrained Sub-Saharan Microgrid ===\n",
"Given the critical situation described, here's a detailed plan for immediate action:\n",
"\n",
"### Immediate Actions:\n",
"1. **Emergency Power Supply:**\n",
" - **Solar Panel Backup:** Deploy backup solar panels or generators to provide emergency power until the grid can be restored.\n",
" \n",
"2. **Battery Management:**\n",
" - **Cooling System Activation:** Activate the cooling system immediately if it has been shut down due to lack of telemetry data. This will help extend the life of the batteries by reducing internal temperatures.\n",
"\n",
"3. **Load Shedding:**\n",
" - **Critical Load Priority:** Prioritize critical loads such as refrigeration units and medical equipment over non-essential loads like lighting and entertainment systems.\n",
" - **Shed Non-Critical Loads:** Temporarily disconnect non-critical loads that do not require constant operation, such as fans and lights, to free up more energy for vital services.\n",
"\n",
"4. **Communication Recovery:**\n",
" - **Relay Communication:** If possible, use any available communication devices (e.g., walkie-talkies) to relay information about the situation back to the central control room. This could include updates on the status of the solar panel backup and the health of the battery bank.\n",
"\n",
"5. **Temperature Monitoring:**\n",
" - **Thermal Sensors:** Install additional thermal sensors around the medical storage unit to monitor temperature changes closely and adjust cooling measures accordingly.\n",
"\n",
"6. **Backup Cooling Measures:**\n",
" - **Water-Based Cooling Systems:** If feasible, activate water-based cooling systems designed for extreme heat conditions to further reduce battery temperatures.\n",
"\n",
"7. **Safety Protocols:**\n",
" - **Fire Safety:** Ensure there are no flammable materials near the medical storage area to prevent fires caused by overheating.\n",
" - **First Aid Kits:**\n",
"\n",
"==================================================\n",
"\n"
]
}
],
"source": [
"evaluation_prompts = [\n",
" {\n",
" \"category\": \"Standard Power Grid\",\n",
" \"prompt\": \"Explain the standard protocol for handling a 5% voltage drop across an urban transmission feeder.\"\n",
" },\n",
" {\n",
" \"category\": \"Constrained Sub-Saharan Microgrid\",\n",
" \"prompt\": \"You are managing an isolated rural microgrid in northern Cameroon. Ambient temperature is 41°C. Solar input drops 70% in 3 minutes due to a sudden dust storm (Harmattan). The local battery bank lacks active cooling. Telemetry link to the central station is severed. What immediate dispatch and load-shedding actions must be taken within 10 seconds to protect essential medical cold-storage?\"\n",
" }\n",
"]\n",
"\n",
"results = []\n",
"\n",
"for item in evaluation_prompts:\n",
" messages = [\n",
" {\"role\": \"system\", \"content\": \"You are an expert electrical and power systems engineer.\"},\n",
" {\"role\": \"user\", \"content\": item[\"prompt\"]}\n",
" ]\n",
" text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)\n",
" inputs = tokenizer([text], return_tensors=\"pt\").to(\"cuda\")\n",
"\n",
" with torch.no_grad():\n",
" generated_ids = model.generate(\n",
" **inputs,\n",
" max_new_tokens=350,\n",
" temperature=0.2\n",
" )\n",
"\n",
" generated_ids = [\n",
" output_ids[len(input_ids):] for input_ids, output_ids in zip(inputs.input_ids, generated_ids)\n",
" ]\n",
" response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]\n",
"\n",
" results.append({\n",
" \"category\": item[\"category\"],\n",
" \"prompt\": item[\"prompt\"],\n",
" \"model_output\": response\n",
" })\n",
" print(f\"=== Category: {item['category']} ===\")\n",
" print(response)\n",
" print(\"\\n\" + \"=\"*50 + \"\\n\")\n"
]
},
{
"cell_type": "markdown",
"source": [
"#4- Save the result"
],
"metadata": {
"id": "ghAobiPuvwyw"
}
},
{
"cell_type": "code",
"source": [
"with open(\"results_log.json\", \"w\") as f:\n",
" json.dump(results, f, indent=2)\n",
"\n",
"print(\"Evaluation complete. Results saved to results_log.json\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Yzjztcr6vwEz",
"outputId": "c606e1b4-80d1-4f6c-c030-b3bbaebef005"
},
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Evaluation complete. Results saved to results_log.json\n"
]
}
]
}
]
} |