diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3154acb..bb17b678 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: # floor of requires-python, and every version the classifiers claim - python-version: ["3.10", "3.12", "3.13", "3.14"] + python-version: ["3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v6 @@ -30,7 +30,7 @@ jobs: run: | python -m pip install --upgrade pip # [pscad] is psutil, which PSCAD/tests import. [surge] is surge-py, - # whose marker (>=3.12,<3.15) leaves it uninstalled on 3.10, where the + # whose marker (>=3.12,<3.15) leaves it uninstalled on 3.11, where the # suite skips itself. python -m pip install -e ".[pscad,surge]" pytest diff --git a/ANDES/README.md b/ANDES/README.md index 2f7a65ac..227c981d 100644 --- a/ANDES/README.md +++ b/ANDES/README.md @@ -6,7 +6,7 @@ MCP server for ANDES (Python-based power system dynamic analysis), enabling powe ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - [ANDES](https://andes.readthedocs.io/) Install dependencies: diff --git a/ANDES/requirements.txt b/ANDES/requirements.txt index 566f59cd..3b22bf55 100644 --- a/ANDES/requirements.txt +++ b/ANDES/requirements.txt @@ -1,3 +1,3 @@ andes mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/Egret/README.md b/Egret/README.md index dbfd94d4..b09cef12 100644 --- a/Egret/README.md +++ b/Egret/README.md @@ -4,7 +4,7 @@ MCP server for Egret power system optimization, enabling unit commitment, AC OPF ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - [Egret](https://github.com/grid-parity-exchange/Egret) - Gurobi or ipopt solver for different tasks diff --git a/Egret/egret_mcp.py b/Egret/egret_mcp.py index 8b0e2f57..4a2ac746 100644 --- a/Egret/egret_mcp.py +++ b/Egret/egret_mcp.py @@ -39,7 +39,7 @@ # MATPOWER marks an unlimited branch with rateA/B/C = 0. Egret's own parser # stores that as None, which its models read as "no thermal limit", but they # index these keys directly, so a converter that leaves them out (powerio 0.11.5 -# does) fails with KeyError: 'rating_long_term'. +# through 0.12.1 do) fails with KeyError: 'rating_long_term'. _BRANCH_RATING_KEYS = ("rating_long_term", "rating_short_term", "rating_emergency") diff --git a/Egret/requirements.txt b/Egret/requirements.txt index 6ea57e10..8cfe843b 100644 --- a/Egret/requirements.txt +++ b/Egret/requirements.txt @@ -1,4 +1,4 @@ gridx-egret pyomo mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/GenX/README.md b/GenX/README.md index f0bc86b7..ed5cd183 100644 --- a/GenX/README.md +++ b/GenX/README.md @@ -69,7 +69,7 @@ Below is the computation calling this skill executes. ## Setup -Requires Python ≥ 3.10 and (for submission) a SLURM cluster with `sbatch` on +Requires Python ≥ 3.11 and (for submission) a SLURM cluster with `sbatch` on `PATH` plus a local GenX.jl checkout. GenX itself is Julia; this connector reads the CSVs a completed run produces and submits new ones. diff --git a/GenX/requirements.txt b/GenX/requirements.txt index 58fc0b4f..211c88d8 100644 --- a/GenX/requirements.txt +++ b/GenX/requirements.txt @@ -2,6 +2,6 @@ # `pip install "powermcp[genx]"` covers the same ground. mcp>=2,<3 # GenX/server.py imports powermcp.sandbox, which re-exports powerio's path policy. -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 pandas>=2.0,<3 matplotlib>=3.7 diff --git a/LTSpice/README.md b/LTSpice/README.md index b74ad56d..2f3f3e39 100644 --- a/LTSpice/README.md +++ b/LTSpice/README.md @@ -4,7 +4,7 @@ MCP server for LTSpice electronic circuit simulation, enabling automated netlist ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - [PyLTSpice](https://github.com/nunobrum/LTSpice) - LTSpice installed on your system (or via Wine on macOS/Linux) diff --git a/LTSpice/requirements.txt b/LTSpice/requirements.txt index 6d7d8511..89c9b0dd 100644 --- a/LTSpice/requirements.txt +++ b/LTSpice/requirements.txt @@ -1,6 +1,6 @@ # Core MCP dependencies mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 # Circuit simulation dependencies matplotlib diff --git a/OpenDSS/README.md b/OpenDSS/README.md index ef1cd5c7..f6da77b8 100644 --- a/OpenDSS/README.md +++ b/OpenDSS/README.md @@ -4,7 +4,7 @@ MCP server for OpenDSS distribution studies using `py_dss_toolkit` and `py_dss_i ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - Install from the **PowerMCP** repository root so the editable path resolves: ```bash diff --git a/OpenDSS/requirements.txt b/OpenDSS/requirements.txt index b774dfde..c11239d3 100644 --- a/OpenDSS/requirements.txt +++ b/OpenDSS/requirements.txt @@ -1,3 +1,3 @@ py_dss_toolkit mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/PSCAD/README.md b/PSCAD/README.md index 49b7a769..3f6c2129 100644 --- a/PSCAD/README.md +++ b/PSCAD/README.md @@ -17,7 +17,7 @@ A professional, robust Model Context Protocol (MCP) server for **Power System Co ### 1. Prerequisites - **Windows OS**: Required for local PSCAD automation (RMI). - **PSCAD Installed**: Ensure PSCAD and its Python libraries are available on your system. -- **Python 3.10+**: Recommended for best compatibility. +- **Python 3.11+**: Recommended for best compatibility. ### 2. Automated Setup The easiest way to get started is by running the automated installer: diff --git a/PSCAD/pyproject.toml b/PSCAD/pyproject.toml index 3aff1f6a..f63ecf06 100644 --- a/PSCAD/pyproject.toml +++ b/PSCAD/pyproject.toml @@ -7,14 +7,14 @@ name = "pscad-mcp" version = "0.1.0" description = "A professional, robust MCP server for PSCAD." readme = "README.md" -requires-python = ">=3.10" +requires-python = ">=3.11" license = {text = "MIT"} authors = [ {name = "LL0pez20", email = "luansantos@poli.ufrj.br"} ] dependencies = [ "mcp>=2,<3", - "powerio[mcp,matrix]>=0.11.2,<0.12", + "powerio[mcp,matrix]>=0.12.1,<0.13", "psutil" ] diff --git a/PSLF/README.md b/PSLF/README.md index af38b028..4d9e68e5 100644 --- a/PSLF/README.md +++ b/PSLF/README.md @@ -4,7 +4,7 @@ MCP server for PSLF (GE Positive Sequence Load Flow), enabling case management, ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - PSLF with PSLF_PYTHON API - [pandas](https://pandas.pydata.org/) diff --git a/PSLF/requirements.txt b/PSLF/requirements.txt index 053febe1..3833a167 100644 --- a/PSLF/requirements.txt +++ b/PSLF/requirements.txt @@ -1,3 +1,3 @@ pandas mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/PSSE/README.md b/PSSE/README.md index a436c2ac..eca8995d 100644 --- a/PSSE/README.md +++ b/PSSE/README.md @@ -4,7 +4,7 @@ MCP server for PSS/E (Siemens PTI) power system analysis. Supports PSSE 35+ with ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - PSSE 35+ installed with Python API (PSSPY) - [mcp](https://pypi.org/project/mcp/) diff --git a/PSSE/requirements.txt b/PSSE/requirements.txt index f9288ae0..91199848 100644 --- a/PSSE/requirements.txt +++ b/PSSE/requirements.txt @@ -1,2 +1,2 @@ mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/PowerFactory/requirements.txt b/PowerFactory/requirements.txt index b8c249eb..607595cd 100644 --- a/PowerFactory/requirements.txt +++ b/PowerFactory/requirements.txt @@ -1,6 +1,6 @@ # MCP Python SDK 2 server framework mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 # Scientific stack numpy>=1.26 diff --git a/PowerWorld/README.md b/PowerWorld/README.md index 7fc3ca8c..7c9c39f6 100644 --- a/PowerWorld/README.md +++ b/PowerWorld/README.md @@ -4,7 +4,7 @@ MCP server for PowerWorld Simulator via Easy SimAuto (ESA), enabling power flow ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - [Easy SimAuto (ESA)](https://github.com/mzy2240/ESA) Install dependencies: diff --git a/PowerWorld/requirements.txt b/PowerWorld/requirements.txt index faa3af5f..c6e1d450 100644 --- a/PowerWorld/requirements.txt +++ b/PowerWorld/requirements.txt @@ -1,4 +1,4 @@ esa numba mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/PyPSA/README.md b/PyPSA/README.md index c8657974..3b377660 100644 --- a/PyPSA/README.md +++ b/PyPSA/README.md @@ -5,7 +5,7 @@ A comprehensive Model Context Protocol (MCP) server for PyPSA (Python for Power ## Requirements - [PyPSA](https://pypsa.org/) >= 0.35.2 and < 2 -- Python 3.10 or higher +- Python 3.11 or higher - MCP Python SDK 2.x - At least one LP solver supported by PyPSA: - **Open Source**: HiGHS (recommended), CBC, GLPK diff --git a/PyPSA/pypsa_mcp.py b/PyPSA/pypsa_mcp.py index 9664137c..2fb12d61 100644 --- a/PyPSA/pypsa_mcp.py +++ b/PyPSA/pypsa_mcp.py @@ -65,6 +65,20 @@ def _optimize(network: Network, **kwargs): return network.optimize(**kwargs) +def _line_loading_pct(network: Network): + """Loading of each line in the first snapshot, as a percentage of the + bound PyPSA enforces, ``s_nom * s_max_pu``. + + powerio >= 0.12 writes an unlimited branch as a positive placeholder + ``s_nom`` with ``s_max_pu = inf``, so ``s_nom`` alone is not a limit. A line + with no bound, or with a zero bound, reads 0 %. + """ + flow = np.sqrt(network.lines_t.p0.iloc[0] ** 2 + network.lines_t.q0.iloc[0] ** 2) + s_max_pu = network.get_switchable_as_dense("Line", "s_max_pu").iloc[0] + loading = flow / (network.lines.s_nom * s_max_pu) * 100 + return loading.replace([np.inf, -np.inf], np.nan).fillna(0.0) + + # ============= Network Information ============= @mcp.tool() @@ -175,11 +189,7 @@ def run_contingency_analysis( network.pf(use_seed=True) base_v = network.buses_t.v_mag_pu.iloc[0] - base_p0 = network.lines_t.p0.iloc[0] - base_q0 = network.lines_t.q0.iloc[0] - base_s_nom = network.lines.s_nom - base_loading = np.sqrt(base_p0**2 + base_q0**2) / base_s_nom * 100 - base_loading = base_loading.replace([np.inf, -np.inf], np.nan).fillna(0.0) + base_loading = _line_loading_pct(network) base_case = { "converged": True, @@ -248,11 +258,7 @@ def run_contingency_analysis( voltage_violations.append({"bus": bus, "vm_pu": round(v, 4)}) # Check thermal violations - p0 = n.lines_t.p0.iloc[0] - q0 = n.lines_t.q0.iloc[0] - s_nom = n.lines.s_nom - loading = np.sqrt(p0**2 + q0**2) / s_nom * 100 - loading = loading.replace([np.inf, -np.inf], np.nan).fillna(0.0) + loading = _line_loading_pct(n) loading_violations = [] for line_id_inner in loading.index: @@ -820,7 +826,9 @@ def import_case_from_any( source_format: Input format name (matpower, powermodels-json, egret-json, psse, powerworld); inferred from the file extension when omitted - overwrite_zero_s_nom: Replacement s_nom for branches with rating 0 + overwrite_zero_s_nom: Replacement s_nom for branches whose thermal + bound is zero. An unlimited branch (MATPOWER rate 0, an absent + Egret rating) arrives unbounded, with s_max_pu = inf, and is kept operating_point: Compatibility alias for time_index study_commit: Retired package selector; export a Tellegen Study state as IR time_index: Explicit TimeSeries index @@ -906,7 +914,9 @@ def import_case_from_json( Args: network_json: The JSON transport string from powerio output_path: Where to save the imported network (.nc) - overwrite_zero_s_nom: Replacement s_nom for branches with rating 0 + overwrite_zero_s_nom: Replacement s_nom for branches whose thermal + bound is zero. An unlimited branch (MATPOWER rate 0, an absent + Egret rating) arrives unbounded, with s_max_pu = inf, and is kept operating_point: Compatibility alias for time_index study_commit: Retired package selector; export a Tellegen Study state as IR time_index: Explicit TimeSeries index diff --git a/PyPSA/requirements.txt b/PyPSA/requirements.txt index b6d28b75..0ca78072 100644 --- a/PyPSA/requirements.txt +++ b/PyPSA/requirements.txt @@ -3,4 +3,4 @@ pypsa>=0.35.2,<2 numpy>=1.24.0 pandas>=2.0.0 mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/README.md b/README.md index ea5ba1d8..08262fec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPI](https://img.shields.io/pypi/v/powermcp.svg)](https://pypi.org/project/powermcp/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -[![Python Version](https://img.shields.io/badge/python-3.10%20to%203.14-blue.svg)](https://www.python.org/downloads/) +[![Python Version](https://img.shields.io/badge/python-3.11%20to%203.14-blue.svg)](https://www.python.org/downloads/) PowerMCP is an open-source collection of MCP servers for power system software such as PSS/E, PowerWorld, PowerFactory, PSLF, PSCAD, OpenDSS, pandapower, and PyPSA. These tools enable LLMs to directly interact with power system applications, facilitating intelligent coordination, simulation, and control in the energy domain. @@ -99,7 +99,7 @@ After it finishes, restart your MCP client (start a new Claude Code or Codex ses ### Install it yourself -PowerMCP installs as a single Python package with an interactive CLI. Python 3.10 through 3.14 is supported. +PowerMCP installs as a single Python package with an interactive CLI. Python 3.11 through 3.14 is supported. ```bash pip install powermcp @@ -185,12 +185,14 @@ These tools wrap commercial or locally-installed software, so PowerMCP stores th ### Case compilation between servers (PowerIO) PowerIO IR is the exchange format of this repository. PowerMCP runs the -server shipped in PowerIO 0.11.2 (`powermcp run powerio` is `python -m +server shipped in PowerIO 0.12 (`powermcp run powerio` is `python -m powerio.mcp`); that server parses every grid exchange format, emits every target, summarizes, diagnoses, normalizes, lowers multiconductor networks, and -calculates matrices. Its `parse` tool returns serialized **PowerIO IR -generation 2** (`"schema": "pio-ir"`, `"version": 2`), a typed module carrying -the electrical value, its provenance and its diagnostics. Every other server +calculates matrices. Its `parse` tool returns serialized **PowerIO IR** +(`"schema": "pio-ir"`, with `"version"` naming the PowerIO release that wrote +it, such as `"0.12.1"`; documents from PowerIO 0.11 state `2` and still +read), a typed module carrying the electrical value, its provenance and its +diagnostics. Every other server here consumes that document: the pandapower, PyPSA, ANDES and Egret adapters turn it into their own model with PowerIO's writers. PowerMCP itself never re-parses, re-validates, or recomputes what PowerIO states; it routes a diff --git a/llms-install.md b/llms-install.md index 051d4088..1e69e4a8 100644 --- a/llms-install.md +++ b/llms-install.md @@ -40,7 +40,7 @@ python3 --version # macOS / Linux py -0p # Windows: lists every installed Python ``` -- Python **3.10 to 3.14** is supported. Prefer **3.12 or 3.13**, which every extra +- Python **3.11 to 3.14** is supported. Prefer **3.12 or 3.13**, which every extra supports (`surge` needs 3.12 to 3.14; PLEXOSDB's `r2x` dependencies need 3.11 to 3.13). - **PSS/E and PowerFactory load a vendor Python module built for one Python version.** diff --git a/pandapower/README.md b/pandapower/README.md index 70afe6c3..a7088a21 100644 --- a/pandapower/README.md +++ b/pandapower/README.md @@ -4,7 +4,7 @@ MCP server for pandapower transmission system analysis, enabling network creatio ## Requirements -- Python 3.10 or higher +- Python 3.11 or higher - [pandapower](https://github.com/e2nIEE/pandapower) Install dependencies: diff --git a/pandapower/requirements.txt b/pandapower/requirements.txt index d756c61b..61dc7421 100644 --- a/pandapower/requirements.txt +++ b/pandapower/requirements.txt @@ -1,3 +1,3 @@ pandapower mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/powermcp/README.md b/powermcp/README.md index e41de5fe..775a69f5 100644 --- a/powermcp/README.md +++ b/powermcp/README.md @@ -12,7 +12,7 @@ This guide shows how to **install** and **test** the packaged version. ## 1. Install (as a user) -Requires **Python 3.10 through 3.14**. +Requires **Python 3.11 through 3.14**. ```bash pip install powermcp diff --git a/powermcp/config.py b/powermcp/config.py index a39ccb2b..1615d3b2 100644 --- a/powermcp/config.py +++ b/powermcp/config.py @@ -18,10 +18,7 @@ from pathlib import Path from typing import Any -try: # Python 3.11+ - import tomllib -except ModuleNotFoundError: # Python 3.10 - import tomli as tomllib # type: ignore[no-redef] +import tomllib import tomli_w diff --git a/powermcp/solver_case.py b/powermcp/solver_case.py index d997ee55..81ca45ab 100644 --- a/powermcp/solver_case.py +++ b/powermcp/solver_case.py @@ -21,7 +21,6 @@ _IR_FORMATS = frozenset({"pio-ir", "pio"}) IR_SCHEMA = "pio-ir" -IR_VERSION = 2 _QUIET_SEVERITIES = frozenset({"remark", "note"}) @@ -85,15 +84,9 @@ def diagnostic_records(items: Any) -> list[dict[str, Any]]: def value_type_name(module: powerio.PioModule) -> str: - """The PowerIO structural type of a module's value. - - powerio 0.11.2 publishes no accessor for it; its own MCP server reads the - same private attribute in `_canonical_type`. Isolating it here makes a - future public accessor a one-line change. - """ - inner = getattr(module, "_inner", None) - name = getattr(inner, "_type_name", None) - return str(name) if name else f"powerio.{type(module.value).__name__}" + """The PowerIO structural type of a module's value, such as + ``powerio.BalancedNetwork`` (``PioModule.type_name``, public since 0.12).""" + return module.type_name def check_diagnostics(items: Any) -> None: @@ -428,7 +421,9 @@ def resolve_solver_case( ``powerio_ir`` is the serialized module the powerio server's ``parse``, ``to_normalized`` or ``to_balanced`` tools return; ``network_json`` is its - compatibility alias and must carry the same generation-2 document. + compatibility alias and must carry the same document. IR is recognized by + its ``"schema": "pio-ir"`` header alone; powerio decides which header + versions it reads (0.12 reads its own release series and 0.11's ``2``). ``operating_point`` is a compatibility spelling for ``time_index``. Study history belongs to Tellegen; legacy package commits require migration. ``edits`` are typed updates applied before validation; ``to_balanced`` diff --git a/powermcp/wizard.py b/powermcp/wizard.py index 37dbe8ce..6f119ef1 100644 --- a/powermcp/wizard.py +++ b/powermcp/wizard.py @@ -90,10 +90,7 @@ def _existing_managed_tools(client_names: list[str]) -> set[str]: keys: list[str] = [] try: if name == "codex": - try: - import tomllib - except ModuleNotFoundError: # py3.10 - import tomli as tomllib # type: ignore + import tomllib keys = list((tomllib.loads(text).get("mcp_servers") or {}).keys()) else: import json diff --git a/pyproject.toml b/pyproject.toml index 4640881a..9a4960fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,14 +14,13 @@ version = "0.5.1" description = "MCP servers for power-system software (PowerWorld, OpenDSS, PSS/E, pandapower, PyPSA, and more)" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.10" +requires-python = ">=3.11" authors = [{ name = "PowerMCP contributors" }] keywords = ["mcp", "power systems", "energy", "simulation", "pandapower", "pypsa", "powerworld", "opendss", "pss/e"] classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", @@ -48,10 +47,10 @@ dependencies = [ "mcp>=2,<3", # powerio supplies the conversion server, module model, native solver # writers, shared JSON transports, and path policy used by the bridges. - # PowerMCP uses the typed PowerIO 0.11.2 module APIs. + # PowerMCP uses the typed PowerIO 0.12 module APIs. # powerio ships the server itself (`python -m powerio.mcp`), so this repo # bundles no copy of it and `powermcp run powerio` runs powerio's. - "powerio[mcp,matrix]>=0.11.2,<0.12", + "powerio[mcp,matrix]>=0.12.1,<0.13", # CLI / installer toolkit: # packaging: the doctor compares an installed version against the floor # declared right here, so it has to read a version specifier. @@ -61,7 +60,6 @@ dependencies = [ "rich>=13", "tomli-w>=1.0", "tomlkit>=0.13", - "tomli>=2.0; python_version < '3.11'", ] [project.optional-dependencies] diff --git a/surge/requirements.txt b/surge/requirements.txt index 09e8397d..1960cda4 100644 --- a/surge/requirements.txt +++ b/surge/requirements.txt @@ -1,3 +1,3 @@ surge-py>=0.1.5 mcp>=2,<3 -powerio[mcp,matrix]>=0.11.2,<0.12 +powerio[mcp,matrix]>=0.12.1,<0.13 diff --git a/surge/test_integration.py b/surge/test_integration.py index 0098ff75..1c41108d 100644 --- a/surge/test_integration.py +++ b/surge/test_integration.py @@ -29,7 +29,7 @@ import pytest # ``surge-py`` is an optional extra whose marker is ``>=3.12,<3.15`` and which -# ships no sdist, so it is legitimately absent on Python 3.10. Skipping rather +# ships no sdist, so it is legitimately absent on Python 3.11. Skipping rather # than failing keeps that honest. # # The ``__file__`` check is the load-bearing part. This repository has its own diff --git a/tests/test_doctor.py b/tests/test_doctor.py index 90ce47ff..475486ec 100644 --- a/tests/test_doctor.py +++ b/tests/test_doctor.py @@ -98,7 +98,7 @@ def test_namespace_shadow_not_false_positive(monkeypatch): then pass or fail for reasons having nothing to do with the logic it covers. Bypass surge's Python-version gate (3.12-3.14 only) so the probe path is exercised on every interpreter, rather than short-circuiting to the - version warning on 3.10. + version warning on 3.11. """ real_find_spec = importlib.util.find_spec @@ -166,14 +166,14 @@ def test_the_floor_is_found_without_top_level_distribution_metadata(monkeypatch) monkeypatch.setattr( doctor, "requires", - lambda _distribution: ("powerio[mcp,matrix]>=0.11.2,<0.12",), + lambda _distribution: ("powerio[mcp,matrix]>=0.12.1,<0.13",), ) req = doctor._declared_requirement("powerio") assert req is not None assert doctor._canonical(req.name) == "powerio" - assert Version("0.11.2") in req.specifier - assert Version("0.11.1") not in req.specifier + assert Version("0.12.1") in req.specifier assert Version("0.12.0") not in req.specifier + assert Version("0.13.0") not in req.specifier def test_an_out_of_date_dependency_under_another_name_is_caught(monkeypatch): diff --git a/tests/test_powerio_server.py b/tests/test_powerio_server.py index 87a544a4..b3a6de2d 100644 --- a/tests/test_powerio_server.py +++ b/tests/test_powerio_server.py @@ -11,9 +11,10 @@ import types from pathlib import Path +import numpy as np import pytest -pytest.importorskip("powerio", minversion="0.11.2") +pytest.importorskip("powerio", minversion="0.12.1") import powerio # noqa: E402 from powerio.mcp import server as powerio_mcp # noqa: E402 @@ -77,14 +78,18 @@ def test_parse_ir_round_trips(): assert result["value_type"] == "powerio.BalancedNetwork" assert result["summary"]["elements"]["buses"] == 9 document = json.loads(result["powerio_ir"]) - assert (document["schema"], document["version"]) == ("pio-ir", 2) + assert document["schema"] == "pio-ir" + assert document["version"] == powerio.versions()["powerio_ir"]["version"] + assert document["version"].startswith("0.12.") assert powerio.deserialize(result["powerio_ir"].encode()).value.n_buses == 9 def test_registered_tools_are_canonical(): tools = {tool.name: tool for tool in asyncio.run(powerio_mcp.mcp.list_tools())} assert {"parse", "emit", "summarize", "to_normalized", "calc_matrix", - "diagnostics", "display", "about", "to_balanced", "to_balanced_report"} <= tools.keys() + "diagnostics", "about", "to_balanced", "to_balanced_report"} <= tools.keys() + # powerio 0.12 removed the display tool; parse reads .pwd files instead. + assert "display" not in tools for name in ("summarize", "to_normalized", "calc_matrix"): props = tools[name].input_schema["properties"] assert {"path", "content", "powerio_ir", "format"} <= props.keys() @@ -320,12 +325,44 @@ def test_pypsa_legacy_optimizer_options_fail_clearly(tmp_path): assert "legacy Pyomo" in pyomo["message"] -def test_pypsa_import_overwrite_zero_s_nom(tmp_path): +def test_pypsa_import_reads_matpower_rate_zero_as_unlimited(tmp_path): + # MATPOWER's rate 0 means "no limit". powerio >= 0.12 reads it as an + # infinite bound and writes PyPSA's own spelling of that, s_max_pu = inf, + # so nothing arrives with s_nom 0 and there is nothing to overwrite. + src = tmp_path / "zero.m" + src.write_text(ZERO_RATE_CASE) + out = tmp_path / "unlimited.nc" + + r = pypsa_mcp.import_case_from_any(str(src), str(out)) + + assert r["status"] == "success", r + assert not any("rating 0" in w for w in r["warnings"]), r["warnings"] + lines = pypsa.Network(str(out)).lines + assert (lines.s_nom > 0).all() + assert np.isinf(lines.s_max_pu).all() + + +def _zero_bound_egret_case(tmp_path): + """ZERO_RATE_CASE as Egret JSON whose branches state a numeric zero bound.""" src = tmp_path / "zero.m" src.write_text(ZERO_RATE_CASE) + document = json.loads(powerio.emit(powerio.parse(src), "egret-json").text) + for branch in document["elements"]["branch"].values(): + branch["rating_long_term"] = 0.0 + path = tmp_path / "zero_bound.json" + path.write_text(json.dumps(document)) + return path + + +def test_pypsa_import_overwrite_zero_s_nom(tmp_path): + # Egret's numeric 0 is a real zero bound (powerio >= 0.12), which the + # PyPSA writer states as s_nom 0. + src = _zero_bound_egret_case(tmp_path) bare = pypsa_mcp.import_case_from_any(str(src), str(tmp_path / "bare.nc")) + assert bare["status"] == "success", bare assert any("rating 0" in w for w in bare["warnings"]), bare["warnings"] + assert (pypsa.Network(str(tmp_path / "bare.nc")).lines.s_nom == 0).all() out = tmp_path / "set.nc" r = pypsa_mcp.import_case_from_any(str(src), str(out), overwrite_zero_s_nom=100.0) @@ -333,6 +370,22 @@ def test_pypsa_import_overwrite_zero_s_nom(tmp_path): assert (pypsa.Network(str(out)).lines.s_nom == 100.0).all() +def test_pypsa_contingency_loading_ignores_unlimited_lines(tmp_path): + # An unlimited line imports as s_nom 100 with s_max_pu inf. Its loading is + # measured against s_nom * s_max_pu, the bound PyPSA itself enforces, so + # the placeholder s_nom cannot raise a thermal violation. + src = tmp_path / "heavy.m" + src.write_text(ZERO_RATE_CASE.replace("\t2 1 50 10", "\t2 1 150 10")) + network = tmp_path / "heavy.nc" + assert pypsa_mcp.import_case_from_any(str(src), str(network))["status"] == "success" + + r = pypsa_mcp.run_contingency_analysis(str(network)) + + assert r["base_case"]["converged"], r + assert r["base_case"]["max_line_loading_pct"] == 0.0 + assert all(not c["loading_violations"] for c in r["contingencies"]), r + + def test_pypsa_import_missing_file(tmp_path): # The absent case sits inside an allowed root, so the refusal states what is # wrong with the file rather than where it is. @@ -783,34 +836,28 @@ def test_gridfm_missing_dir_maps_cleanly(tmp_path): # --------------------------------------------------------------------------- -# PowerWorld .pwd display files. display is provided by the canonical -# powerio.mcp.server; these tests exercise the re-exported tool. +# PowerWorld .pwd display files. powerio 0.12 removed the display tool; the +# canonical parse tool reads a .pwd display as a GeoLayer. # --------------------------------------------------------------------------- -def test_display_decodes_pwd(): - r = powerio_mcp.display(str(ACTIVSG200_PWD)) - assert r["format"] == "powerworld-pwd" - assert r["canvas"]["width"] > 0 and r["canvas"]["height"] > 0 - subs = r["substations"] - assert subs, "expected at least one substation" - assert all(set(s) == {"number", "name", "x", "y"} for s in subs) - assert any(s["name"] for s in subs) - assert all( - isinstance(s["x"], (int, float)) and isinstance(s["y"], (int, float)) - for s in subs - ) +def test_parse_reads_pwd_display_as_geo_layer(): + r = powerio_mcp.parse(path=str(ACTIVSG200_PWD)) + assert r["value_type"] == "powerio.GeoLayer" + assert r["summary"]["features"] > 0 + layer = powerio.deserialize(r["powerio_ir"].encode()) + assert layer.type_name == "powerio.GeoLayer" -def test_read_display_missing_file_maps_cleanly(tmp_path): +def test_parse_missing_pwd_maps_cleanly(tmp_path): with pytest.raises(ValueError): - powerio_mcp.display(str(tmp_path / "nope.pwd")) + powerio_mcp.parse(path=str(tmp_path / "nope.pwd")) -def test_read_display_garbage_file_maps_cleanly(tmp_path): +def test_parse_garbage_pwd_maps_cleanly(tmp_path): bad = tmp_path / "garbage.pwd" bad.write_bytes(b"not a real display file\x00\x01\x02") - with pytest.raises(ValueError): - powerio_mcp.display(str(bad)) + with pytest.raises(ValueError, match="PARSE.SOURCE.MALFORMED"): + powerio_mcp.parse(path=str(bad)) # --------------------------------------------------------------------------- diff --git a/tests/test_publish_workflow.py b/tests/test_publish_workflow.py index ab344e2f..68b8d6e8 100644 --- a/tests/test_publish_workflow.py +++ b/tests/test_publish_workflow.py @@ -5,10 +5,7 @@ import re from pathlib import Path -try: - import tomllib -except ModuleNotFoundError: # Python 3.10 - import tomli as tomllib # type: ignore[no-redef] +import tomllib REPO_ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_registry.py b/tests/test_registry.py index 88525ab9..0de4d05a 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -3,10 +3,7 @@ from __future__ import annotations import importlib.util -try: - import tomllib -except ModuleNotFoundError: # Python 3.10 - import tomli as tomllib +import tomllib import pytest diff --git a/tests/test_solver_case.py b/tests/test_solver_case.py index 0928f5c1..25eb4f24 100644 --- a/tests/test_solver_case.py +++ b/tests/test_solver_case.py @@ -44,11 +44,24 @@ def test_ir_preserves_auditable_context(tmp_path): resolved = resolve_solver_case(file_path=str(source)) assert resolved.network.n_buses == 9 assert resolved.package["schema"] == "pio-ir" - assert resolved.package["generation"] == 2 + # From 0.12 the IR header states the writing release as a string. + assert resolved.package["generation"] == powerio.versions()["powerio_ir"]["version"] assert resolved.package["producer"]["name"] == "powerio" assert resolved.package["selection"] == {} +def test_ir_written_by_powerio_0_11_still_resolves(tmp_path): + # powerio 0.12 reads the integer "version": 2 header every 0.11 release + # wrote; recognising IR by its schema alone keeps those documents usable. + document = json.loads(ir(powerio.parse(CASE9))) + document["version"] = 2 + source = tmp_path / "case.pio.json" + source.write_text(json.dumps(document)) + resolved = resolve_solver_case(file_path=str(source)) + assert resolved.network.n_buses == 9 + assert resolved.package["generation"] == 2 + + def test_invalid_identities_cannot_reuse_stale_diagnostics(): document = json.loads(ir(powerio.parse(CASE9))) buses = document["value"]["data"]["buses"] diff --git a/tests/test_transport.py b/tests/test_transport.py index 1fd8b0b1..a2dc8fd1 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -16,7 +16,7 @@ import pytest -pytest.importorskip("powerio", minversion="0.11.2") +pytest.importorskip("powerio", minversion="0.12.1") from mcp import ClientSession, StdioServerParameters # noqa: E402 from mcp.client.stdio import stdio_client # noqa: E402 @@ -59,7 +59,6 @@ async def steps(session): "about", "calc_matrix", "diagnostics", - "display", "emit", "parse", "summarize",