# -*- coding: utf-8 -*- """ write_glm_snippets.py Write a few canonical GLM snippets under kb/snippets/glm for reference. These are small, human-readable examples — not full runnable feeders. Usage: %run scripts/write_glm_snippets.py """ from pathlib import Path SNIPS = { "open_switch_status.glm": r"""// Minimal switch example (OPEN) object switch { name microgrid_switch_YYY; status OPEN; // CLOSE to reconnect } """, "close_switch_status.glm": r"""// Minimal switch example (CLOSED) object switch { name microgrid_switch_YYY; status CLOSED; } """, "set_inverter_Pref_Qref.glm": r"""// Inverter real/reactive setpoints (values indicative) object inverter_dyn { name inverter_XXX; Pref 10000; // [W] Qref 0; // [var] // Pmax 50000; // [W] (if present in your models) // Qmax 30000; // [var] // Vset 4800; // [mV] or [V] depending on your modeling (verify in your pipeline) } """, "set_load_constant_power_A.glm": r"""// Load constant power (phase A) object load { name load_41; constant_power_A 25000; // [VA], can be complex like 60000+12000j } """, "set_generator_power_out.glm": r"""// Diesel generator phase power outputs object diesel_dg { name gen_01; power_out_A 60000+12000j; // [VA], complex // power_out_B 40000+8000j; // power_out_C 30000+5000j; } """, "set_capacitor_phase.glm": r"""// Capacitor phase state/setting (model-specific) object capacitor { name cap_01; // Some models use per-phase flags or discrete steps; confirm with your code. // Examples (choose one representation your pipeline expects): // capacitor_A CLOSED; // capacitor_B OPEN; // capacitor_C CLOSED; } """, "set_regulator_tap.glm": r"""// Regulator tap steps (example) object regulator { name reg_01; tap_A 3; // integer step tap_B 2; tap_C 4; } """, "README.md": r"""These snippets are tiny GLM fragments used as **reference** for RAG. They are not full feeders. Use them to: - ground the LLM on property spellings and typical values, - show OPEN/CLOSED vs numeric edits, - remind how inverter/load/generator/regulator properties look in GLM. **REALITY FILTER**: - Where semantics are unclear, this folder includes comments marked [Inference] or asks you to verify in your pipeline. - Prefer your actual GLM corpus (via RAG) for precise formatting when available. """ } def main(): outdir = Path("kb/snippets/glm") outdir.mkdir(parents=True, exist_ok=True) for fname, text in SNIPS.items(): (outdir / fname).write_text(text.strip() + "\n", encoding="utf-8") print("[ok] wrote", len(SNIPS), "files to", outdir.resolve()) if __name__ == "__main__": main()