# Power Flow Analyzer: MATPOWER, PSS/E RAW, CGMES Load Flow (`jumblemog/power-flow-analyzer`) Actor

Run AC/DC power flow, N-1 contingency, short-circuit and hosting capacity studies on power grids: MATPOWER, PSS/E RAW, CGMES, UCTE, pandapower or JSON tables. Get voltage and loading violations, losses, OPF prices, tables, Excel and grid diagrams. For engineers and AI agents.

- **URL**: https://apify.com/jumblemog/power-flow-analyzer.md
- **Developed by:** [Jumble Mog](https://apify.com/jumblemog) (community)
- **Categories:** Developer tools, AI, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Power Flow Analyzer: MATPOWER, PSS/E RAW, CGMES Load Flow

**Study a power grid in one API call: load flow, N-1 contingencies, short circuits, hosting capacity and optimal dispatch.** Give links to network files (MATPOWER `.m`, PSS/E `.raw`, CGMES, UCTE-DEF and more), paste one, describe a small grid as JSON tables, or name one of 46 built-in test grids. For each network you get back:

- **A load flow** (AC Newton-Raphson, or DC): every bus's voltage and angle, every line's and transformer's flows, loading and losses, with a verdict (ok, warning or critical) and a one-line headline.
- **Limit checks**: buses outside the voltage band and branches over their rating (the network's own limits, or yours), generators past their reactive or active power limits, and buses no source reaches.
- **N-1 contingency analysis**: each line and transformer (and, on request, each generator) taken out in turn, the most loaded first. Every outage gets a status (secure, violations, islanding or no solution) and its worst effect, such as "losing L-7-9-1 puts T-4-7-1 at 174%". Parts that split off keep running on their own generators, and generation an outage takes away is made up by the other generators in proportion to their output, as their governors would.
- **Short-circuit currents** to IEC 60909: three-phase or two-phase faults, maximum or minimum case, with the initial current Ik'', the peak current ip and the short-circuit power at every bus. Where the file has no short-circuit data, typical values are filled in and named.
- **Hosting capacity**: how much new generation (or load) each bus takes on its own before a voltage or loading limit is passed, and which limit stops it.
- **Optimal power flow** when the file has generator costs (MATPOWER's `gencost`): the lowest-cost dispatch within every limit, its cost against the case's own dispatch, the branches at their limit and each bus's marginal price (LMP).
- **Files**: CSV tables of buses, branches, generators, loads, outages, short circuits and hosting capacity, one Excel workbook with all of them, the network as pandapower JSON (and as a MATPOWER case on request), and pictures: the grid coloured by loading, every bus's voltage against the band, the worst outages and a hosting capacity map.

![The CIGRE medium-voltage benchmark at 130% load: the two 110/20 kV transformers in red at 127% and 111% of their rating, and nine buses circled below 0.95 pu](https://api.apify.com/v2/key-value-stores/Km5b4PG3kYHdZSb1E/records/power-flow-analyzer-grid.png?signature=1RnKisOqdYAirPmuq8z4l)

*The CIGRE MV benchmark with every load at 130%: two transformers over their rating (red) and nine buses below the voltage band (circled).*

![Hosting capacity of the built-in example: 147 load buses coloured by the MW of new generation each takes, from 6 to 36 MW](https://api.apify.com/v2/key-value-stores/Km5b4PG3kYHdZSb1E/records/power-flow-analyzer-hosting.png?signature=1FV78lM3wUKY4PsQHlHC9)

*Hosting capacity of the built-in example, a German 20 kV grid: the new generation each of its 147 load buses takes before a limit is passed.*

![N-1 study of the IEEE 14-bus PSS/E file: one bar per outage, the highest branch loading it causes; two outages in red put transformer T-4-7-1 at 174% and 125%](https://api.apify.com/v2/key-value-stores/Km5b4PG3kYHdZSb1E/records/power-flow-analyzer-contingencies.png?signature=g5fN5M6mGHNfH3KV73hr)

*N-1 on the IEEE 14-bus PSS/E file: each bar is one outage and the highest loading it causes. Two of the 20 overload transformer T-4-7-1.*

The power flow, short-circuit and optimal power flow calculations are [pandapower](https://www.pandapower.org/)'s, an open-source power system library from the University of Kassel and Fraunhofer IEE. PSS/E, CGMES, UCTE and the other exchange formats are read with [PowSyBl](https://www.powsybl.org/), the open-source grid toolkit started by RTE (the French transmission system operator), and converted by this tool. Every converted network is solved by both, and the voltages compared, so a conversion error shows up as a mismatch instead of a wrong answer. You install nothing: no MATPOWER, no PSS/E or PowerFactory licence, no Python.

It's made for:

- Distribution engineers checking where new solar, batteries or EV chargers fit (hosting capacity), or how a feeder copes with more load.
- Transmission planners and consultants who want N-1 screening and short-circuit levels from a PSS/E or CGMES file without opening PSS/E or PowerFactory.
- Students and researchers working with MATPOWER, PGLib-OPF or IEEE test cases: solved cases, N-1 tables and optimal dispatch from a link, in Excel or CSV.
- Developers building grid dashboards, interconnection screening or data pipelines who need power flow results by API, or a PSS/E or CGMES model converted to MATPOWER or pandapower.
- AI agents asked "is this grid N-1 secure?" or "how much solar can this feeder take?". A language model can't solve power flow equations; this tool hands it the findings as JSON and pictures it can show.

### How to use it

1. Give **Networks**: links to network files, or the name of a built-in grid. To try it, write `example`.
2. Pick the **Studies** (power flow, N-1 and short circuit by default; add hosting capacity and optimal power flow), and if you like the limits and options of each.
3. Click **Start**. The dataset has a row per network with the verdict, headline, numbers and findings. The files and pictures are in the run's key-value store, and `OUTPUT` sums up the run.

### How-to examples

The result lines come from runs of these inputs. The MATPOWER, PGLib-OPF and ANDES files are public test cases on GitHub; the tool downloads them from their links and they aren't part of it.

#### How to run a MATPOWER or PGLib-OPF case online

Put the link to the `.m` file in `networks` (a GitHub file page works) and add `opf` to the studies when the case has generator costs.

```json
{
  "networks": [
    "https://github.com/MATPOWER/matpower/blob/master/data/case118.m",
    "https://github.com/power-grid-lib/pglib-opf/blob/master/pglib_opf_case118_ieee.m"
  ],
  "analyses": ["powerflow", "contingency", "shortcircuit", "opf"]
}
```

Result for MATPOWER's case118: voltages 0.943 to 1.050 pu and 132.86 MW of losses (3.1%), with 6 generators past their reactive limits. The optimal dispatch costs 129,660.70 per hour, against 131,220.64 for the case's own. In the N-1 study 170 of 184 outages are secure; the worst, losing line 11 SouthBnd V2-13 Concord V2, leaves bus 13 Concord V2 at 0.902 pu. The PGLib-OPF version has branch ratings, and its own dispatch puts 10 branches over them (line 69-77 at 197% of 150 MVA). The optimal power flow brings its cost from 117,293.55 to 97,043.15 per hour within every limit, with line 49-69 and line 100-103 at theirs.

#### How to open a PSS/E RAW file without PSS/E

Give the link to the `.raw` file. The default studies are the power flow, N-1 and short circuit.

```json
{
  "networks": [
    "https://github.com/CURENT/andes/blob/master/andes/cases/ieee14/ieee14.raw",
    "https://github.com/CURENT/andes/blob/master/andes/cases/wecc/wecc.raw"
  ]
}
```

Result for the IEEE 14-bus file: voltages 1.010 to 1.030 pu and 2.73 MW of losses. In the N-1 study 18 of 20 outages are secure, and losing L-7-9-1 puts transformer T-4-7-1 at 174%. Short-circuit currents run from 23.69 kA at BUS1 down to 1.63 kA at BUS14, and PowSyBl's own load flow of the original file agrees to within 0.00001 pu. The WECC 179-bus file has 7 buses above its voltage band of 0.9 to 1.1 pu (highest 1.167 pu at 108 MIDWAY). Of its 263 outages, 217 are secure, 30 bring violations (losing T-160-161-1 leaves bus 160 NAUGHTON at 0.662 pu) and 13 find no solution.

#### How to find how much solar a feeder can take (hosting capacity)

Add `hosting` to the studies. Each bus with load is given new generation (or load, with `hostingKind` set to `load`) until a voltage or a branch passes its limit.

```json
{
  "networks": ["example"],
  "analyses": ["hosting"]
}
```

Result: the 147 load buses of the example, a German 20 kV grid, take 5.976 to 35.610 MW of new generation each (median 12.932 MW). Bus 92 takes the least, stopped by its own voltage passing 1.05 pu. High voltage is the limit at 101 buses and branch loading at 46. `hosting.png` maps it and `hosting-capacity.csv` has every bus. For one planned connection, name its bus in `hostingBuses`.

#### How to see how a grid copes with more load

Scale every load with `loadScalingPercent` (or every generator with `generationScalingPercent`).

```json
{
  "networks": ["cigremv"],
  "loadScalingPercent": 130,
  "analyses": ["powerflow", "contingency"]
}
```

Result: at 130% load the CIGRE medium-voltage benchmark is critical. Its two 25 MVA transformers carry 127% and 111% of their rating, and 9 buses fall below 0.95 pu (lowest 0.907 pu at Bus 11). In the N-1 study, losing Line 7-8 puts Trafo 0-1 at 133%, and 13 of the 17 outages cut off radial parts of the grid, the most load lost being 31.406 MW when Trafo 0-1 goes. The first picture on this page is this run's `grid.png`.

#### How to study a grid you describe yourself

Write it as JSON tables in `network`: pandapower's element tables (`bus`, `line`, `trafo`, `trafo3w`, `load`, `sgen`, `gen`, `ext_grid`, `shunt`, `switch`, `storage`, `impedance`, `ward`) with pandapower's parameter names, and buses referred to by name. Lines and transformers take one of pandapower's standard types (`std_type`) or their own parameters.

```json
{
  "network": {
    "name": "Two feeders",
    "bus": [{"name": "Grid", "vn_kv": 110}, {"name": "MV", "vn_kv": 20}, {"name": "A", "vn_kv": 20}, {"name": "B", "vn_kv": 20}, {"name": "C", "vn_kv": 20}],
    "ext_grid": [{"bus": "Grid", "vm_pu": 1.02}],
    "trafo": [{"name": "T1", "hv_bus": "Grid", "lv_bus": "MV", "std_type": "25 MVA 110/20 kV"}],
    "line": [
      {"name": "L1", "from_bus": "MV", "to_bus": "A", "length_km": 4, "std_type": "NA2XS2Y 1x240 RM/25 12/20 kV"},
      {"name": "L2", "from_bus": "A", "to_bus": "B", "length_km": 3, "std_type": "NA2XS2Y 1x95 RM/25 12/20 kV"},
      {"name": "L3", "from_bus": "MV", "to_bus": "C", "length_km": 6, "std_type": "NA2XS2Y 1x95 RM/25 12/20 kV"}
    ],
    "load": [{"name": "Town", "bus": "A", "p_mw": 3, "q_mvar": 1}, {"bus": "B", "p_mw": 4, "q_mvar": 1.2}, {"bus": "C", "p_mw": 2.5, "q_mvar": 0.8}],
    "sgen": [{"name": "PV", "bus": "B", "p_mw": 1.5}]
  },
  "analyses": ["powerflow", "shortcircuit", "hosting"],
  "hostingKind": "load"
}
```

Result: voltages 0.989 to 1.020 pu, L1 at 41% and 0.12 MW of losses. The short-circuit current is 26.25 kA at Grid (with a typical 5,000 MVA upstream grid, as the tables don't give one), 6.53 kA at the 20 kV busbar MV and 3.80 kA at C, the end of the longest cable. B and C each take 5.797 MW more load before their cable (L2, L3) reaches its rating, and A takes 8.560 MW before L1 does.

#### How to convert a PSS/E or CGMES model to MATPOWER or pandapower

Ask for the `network` and `matpower` outputs. The power flow runs either way, and `conversionCheck` says how closely the converted network's voltages match PowSyBl's load flow of the original file.

```json
{
  "networks": ["https://github.com/CURENT/andes/blob/master/andes/cases/wecc/wecc.raw"],
  "analyses": ["powerflow"],
  "outputs": ["network", "matpower"]
}
```

Result, in 3 seconds: `network.m`, a MATPOWER case with the bus names in `mpc.bus_name`, and `network.json`, a pandapower network. Read back in, the MATPOWER case gives the same voltages (0.950 to 1.167 pu) and losses (626.01 MW), and `conversionCheck` found no difference from PowSyBl's load flow over the 179 buses.

#### How to let an AI agent check a grid

Add the tool to the agent through Apify's MCP server at `https://mcp.apify.com/?tools=jumblemog/power-flow-analyzer`. Asked whether a grid is N-1 secure, the agent sends the file's link with `"analyses": ["powerflow", "contingency"]` and reads `verdict`, `headline`, `findings` and `contingency.worst` from the dataset. The headline is a sentence it can pass on as it is, such as "Solved: voltages 0.907 to 1.030 pu, highest loading 127% (Trafo 0-1), losses 0.34 MW (0.6%). 1 critical and 2 warnings: 2 branches over the limit: worst Trafo 0-1 at 127% of 25 MVA.", and the picture links are there for it to show.

### FAQ

**Which files can it read?**

- **MATPOWER** cases (`.m`, and `.mat` saved by MATLAB), with bus names (`mpc.bus_name`) and generator costs (`mpc.gencost`). PGLib-OPF and NESTA cases are MATPOWER cases.
- **PSS/E RAW** versions 32, 33 and 35, and RAWX. Older versions (30, 31) aren't supported; PSS/E can save a case as version 33.
- **CGMES** (CIM 2.4.15 and 3.0): a ZIP of the XML profiles. The boundary set can be in the same ZIP or a ZIP of its own, and a ZIP of several models gives a network per model.
- **UCTE-DEF** (`.uct`), the **IEEE common data format**, **PowerFactory DGS** exports, **PowSyBl IIDM** (`.xiidm`), **pandapower JSON** and **JSON tables** (below).

The format is found from the content, not the file name. gzip, bzip2, xz and ZIP files are unpacked, and `#text` at the end of a ZIP link takes only the files whose names contain the text.

**How accurate is it?**
The load flow solves the full AC equations, to a mismatch below 0.000001 MVA at every bus. On MATPOWER's own cases it gives MATPOWER's answers: case9's losses of 4.955 MW, and optimal dispatch costs of 5,296.68 per hour for case9 (MATPOWER: 5,296.69) and 129,660.70 for MATPOWER's case118 file (MATPOWER: 129,660.69). Converted PSS/E and CGMES files are checked against PowSyBl's OpenLoadFlow on the original file, and the dataset's `conversionCheck` gives the largest voltage difference; the largest seen in tests was 0.0021 pu (on the IEEE 300-bus case), and on the PSS/E files above it was below 0.0001 pu.

**What limits does it check against?**
Each bus's own voltage limits where the file has them (MATPOWER's `Vmin` and `Vmax`, PSS/E's normal limits), else 0.95 to 1.05 pu; and each line's and transformer's rating, at 100%. `minVoltagePu`, `maxVoltagePu` and `maxLoadingPercent` set your own for every bus and branch. MATPOWER writes 0 or 9,900 MVA for a branch without a rating; those branches aren't checked, and the findings say how many there are.

**How does the N-1 study handle a split network and lost generation?**
When an outage splits the network, a part with generators and load keeps running on its own generators, and only parts without any are counted as lost load. When an outage takes generation away (a generator, or the transformer that connects it), the other generators make it up in proportion to their output, as their governors would, instead of the slack making up all of it. An outage that leaves no solution is reported as such: it often means voltage collapse. A violation the base case already has counts again only when the outage makes it worse (by 0.01 pu, or 5 percentage points of loading).

**Is it a replacement for PSS/E, PowerFactory or MATPOWER?**
No: those do dynamics, protection, detailed control and much more. This tool does the everyday steady-state studies, by API, on many networks at once, and gives the results as JSON your code or agent can act on, plus Excel and CSV. It's also a quick way to open a PSS/E or CGMES file without a licence, and to convert it.

**How big a network can it take?**
Networks of several thousand buses work: the built-in `case9241pegase` (9,241 buses) was solved, with every table and picture, in 41 seconds at the default memory. N-1 takes one power flow per outage and hosting capacity 10 to 30 per bus, so they grow with the network: give the run more memory (a CPU core per 4 GB), lower `maxContingencies` and `hostingMaxBuses`, or raise `timeLimitSeconds`. A study that reaches the time limit stops early and says how far it got. Up to 50 networks a run and 500 files a ZIP.

**Is my data kept?**
Each network is read in a temporary folder by a separate process that has no access to your Apify token, and the folder is deleted when the run ends. pandapower files are read as data: one that would run code is refused. The outputs stay in your own Apify storage.

### Input

| Field | What it does |
|---|---|
| `networks` | Links to network files, or built-in grid names (`example`, `case9`, `case14`, `case39`, `case118`, `case300`, `case2869pegase`, `cigremv`, `gb` ...). Up to 50. |
| `upload` | A network file (or a ZIP of them) from your computer. |
| `networkText` | The text of a network file: a MATPOWER case, a PSS/E RAW file, UCTE-DEF, IEEE common data format or JSON. |
| `network` | A network as JSON tables (see the how-to above). |
| `analyses` | `powerflow`, `contingency`, `shortcircuit`, `hosting`, `opf` (the first three by default; the power flow always runs). |
| `method` | `ac` or `dc` (ac). |
| `enforceReactiveLimits` | Generators past their reactive limit hold it and give up their voltage set point (off, as in MATPOWER's `runpf`). |
| `loadScalingPercent`, `generationScalingPercent` | Every load, or every generator's active power, scaled (100). |
| `minVoltagePu`, `maxVoltagePu`, `maxLoadingPercent` | Your own voltage band and loading limit for every bus and branch (the network's own, else 0.95 to 1.05 pu and 100%). |
| `contingencyElements` | `line`, `trafo`, `trafo3w`, `gen`: what the N-1 study takes out (all but `gen`). |
| `maxContingencies` | Only the outages of the most loaded branches, up to this many (all, as far as the time limit allows). |
| `faultType`, `shortCircuitCase` | `3ph` or `2ph`; `max` or `min` (3ph, max). |
| `faultBuses` | Bus names or numbers for the short-circuit study (every bus up to 2,000 buses). |
| `gridShortCircuitMva` | The upstream grid's short-circuit power, for external grids that don't state it (typical values by voltage). |
| `hostingKind` | `generation` or `load` added at each bus (generation). |
| `hostingBuses`, `hostingMaxBuses` | The buses to study (the buses with load, the lowest voltage first), and the most to study (200). |
| `outputs` | `tables`, `excel`, `pictures`, `network`, `matpower` (all but `matpower`). |
| `frequencyHz` | The system frequency for files that don't state it (50; 60 for North America). |
| `timeLimitSeconds` | Downloading and studying stop after this long (300 s). |

### Output

- **Dataset**: one row per network, with `network`, `source`, `status`, `error`, `format`, `verdict`, `headline`, the element counts (`buses`, `lines`, `transformers`, `generators`, `loads` ...), the power flow (`converged`, `method`, `solver`, `iterations`, `loadMw`, `generationMw`, `slackMw`, `lossesMw`, `lossesPercent`, `lossesByVoltage`), the voltages (`minVoltagePu`, `minVoltageBus`, `maxVoltagePu`, `maxVoltageBus`, `lowVoltageBuses`, `highVoltageBuses`, `voltageViolations`), the loading (`maxLoadingPercent`, `maxLoadingBranch`, `overloadedBranches`, `overloads`, `unratedBranches`), supply (`unsuppliedBuses`, `unsuppliedLoadMw`, `generatorsOutsideLimits`), `voltageBand`, `loadingLimit`, `findings`, `checks`, the studies (`contingency`, `shortCircuit`, `hostingCapacity`, `opf`), `conversionCheck`, `notes`, the file links, `downloadMB`, `seconds` and `events`.
- Each finding has `severity` (`critical`, `warning` or `info`), `check` and `message`.
- **Key-value store**: `grid.png`, `voltage.png`, `contingencies.png`, `hosting.png`, `buses.csv`, `branches.csv`, `generators.csv`, `loads.csv`, `contingencies.csv`, `short-circuit.csv`, `hosting-capacity.csv`, `results.xlsx`, `network.json` and `network.m`. With several networks, the second network's files start with `net2-`, the third's with `net3-`, and so on.
- **OUTPUT**: the run as one JSON object, with every network's row and, for a single network, its file links at the top.

### How it works

1. Links are downloaded and uploads fetched. Web servers, S3 and other buckets, GitHub and GitLab file pages, Google Drive and Dropbox all work. Archives are unpacked, and network files are told apart from other files by their content.
2. Each network is read by a separate process, as an unprivileged user, in a throwaway folder. MATPOWER and pandapower files go straight to pandapower. The other formats are read by PowSyBl, converted to pandapower (lines, two- and three-winding transformers with their taps and phase shifts, generators with their limits, loads, shunts, switches, HVDC links), then solved by both and compared.
3. The power flow runs first. When Newton-Raphson finds no solution, three more ways are tried (a flat start, step-size control, more iterations), and then the DC power flow gives approximate flows, which the findings say. The other studies start from the solved case.

### Pricing

You pay per network studied, at the price shown on this page. One event covers a network of up to 20 MB downloaded and 30 seconds of processing at the default 2 GB memory.

- A bigger file costs one more event for each further started 20 MB.
- A longer study costs an event for each further 30 seconds. At 4 GB that's every 15 seconds, since the platform's cost follows memory; a run with 4 GB has a whole CPU core and finishes about twice as fast, for about the same price.

Each network's `events` says what it counted for. In the runs above, the `example` grid with the default studies counted 1 event (14 s), MATPOWER's case118 with N-1, short circuit and the optimal power flow 2 (37 s), the WECC 179-bus PSS/E file 2 (56 s), and the example's hosting capacity at 147 buses 3 (89 s). Networks that can't be downloaded or read are never charged. Downloads stop at what the run's maximum charge still covers.

### Speed

Times at the default 2 GB memory, which has half a CPU core, from the runs above:

| Network and studies | Time |
|---|---|
| WECC 179-bus PSS/E file converted to MATPOWER and pandapower (power flow only) | 3 s |
| `example`, 179 buses: power flow, N-1 (183 outages) and short circuit, with every file and picture | 14 s |
| IEEE 14-bus PSS/E file, default studies | 21 s |
| MATPOWER case118: power flow, N-1 (184 outages), short circuit and optimal power flow | 37 s |
| `case9241pegase`, 9,241 buses: power flow, with every file and picture | 41 s |
| WECC 179-bus PSS/E file, default studies (N-1 of 263 outages: 35 s) | 56 s |
| `example` hosting capacity, 147 buses | 89 s |

The N-1 and hosting capacity studies take most of the time on bigger networks. With 4 GB the run has a whole CPU core and the studies take about half as long.

### Tips and limits

- For a quick look at a big network, set `analyses` to `["powerflow"]`: the N-1 and hosting capacity studies take most of the time.
- To screen a planned connection, name its bus in `hostingBuses` with `hostingKind` set to `generation` (solar, wind, batteries feeding in) or `load` (EV chargers, heat pumps, data centres).
- Hosting capacity adds the new generation or load at unity power factor, at one bus at a time, to within 2%. It checks voltages and branch loading in steady state, not protection, flicker or harmonics.
- The optimal power flow limits each line's and transformer's current (its rating at nominal voltage), where MATPOWER limits apparent power. Where a branch limit binds and voltages are above nominal, the cost can come out slightly lower than MATPOWER's.
- Short-circuit currents use the data the file has. PSS/E RAW and MATPOWER files hold no short-circuit data for generators or the upstream grid, so typical values are used and named in `notes`; give `gridShortCircuitMva` for your own.
- The checks are a screening, not a sign-off: a finding is a lead for a closer look in your planning tools.

### For AI agents and developers

- **Input**: `networks` (links or built-in names), and optionally `analyses`, the limits and `outputs`.
- **Output**: in the dataset, each network's `verdict`, `headline`, `findings` and `checks`, the numbers behind them, and the studies (`contingency`, `shortCircuit`, `hostingCapacity`, `opf`). `OUTPUT` has every network with its file links.
- **Errors**: a network that can't be read gets `status: "failed"` and an `error` that says why: a web page instead of a file, not a network file, an unsupported PSS/E version, or a ZIP with nothing matching the `#` part. A name that is close to a built-in grid's gets a suggestion. Failed networks cost nothing.

Add the tool to an agent through Apify's MCP server at `https://mcp.apify.com/?tools=jumblemog/power-flow-analyzer`. Or get the findings from one HTTP call:

```bash
curl -X POST "https://api.apify.com/v2/acts/jumblemog~power-flow-analyzer/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"networks": ["https://example.com/models/feeder.raw"], "analyses": ["powerflow", "contingency"], "outputs": ["tables"]}'
```

In Python, with the `apify-client` package:

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_TOKEN")
run = client.actor("jumblemog/power-flow-analyzer").call(run_input={"networks": ["case118"], "analyses": ["powerflow", "contingency", "opf"]})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(row["network"], row["verdict"], row["headline"])
    for finding in row["findings"]:
        print("  ", finding["severity"], finding["check"], finding["message"])

store = client.key_value_store(run["defaultKeyValueStoreId"])
with open("results.xlsx", "wb") as f:
    f.write(store.get_record_as_bytes("results.xlsx")["value"])
```

### Credits

- Power flow, short circuit and optimal power flow: [pandapower](https://www.pandapower.org/) (BSD-3-Clause), with its built-in grids (MATPOWER's, PEGASE's and RTE's cases, the CIGRE benchmarks, the Kerber grids, LV Schutterwald and MV Oberrhein).
- PSS/E, CGMES, UCTE, IEEE common data format, DGS and IIDM: [PowSyBl](https://www.powsybl.org/) (pypowsybl, MPL-2.0), which also gives the second solver (OpenLoadFlow) for the conversion check.
- MATPOWER files: [matpowercaseframes](https://github.com/UGA-BSAIL/matpowercaseframes) (MIT). Grid layout: [igraph](https://igraph.org/) (GPL-2.0). Tables and pictures: [pandas](https://pandas.pydata.org/), [NumPy](https://numpy.org/), [SciPy](https://scipy.org/), [Matplotlib](https://matplotlib.org/) and [openpyxl](https://openpyxl.readthedocs.io/).
- The how-to examples link to public test cases: [MATPOWER](https://github.com/MATPOWER/matpower)'s `case118.m` (BSD-3-Clause), [PGLib-OPF](https://github.com/power-grid-lib/pglib-opf)'s `pglib_opf_case118_ieee.m` (CC BY 4.0) and [ANDES](https://github.com/CURENT/andes)' IEEE 14-bus and WECC 179-bus PSS/E files (GPL-3.0).

# Actor input Schema

## `networks` (type: `array`):

Links to network files: MATPOWER .m or .mat, PSS/E RAW (v32, v33, v35) or RAWX, CGMES (a ZIP of the XML profiles), UCTE-DEF, IEEE common data format, PowerFactory DGS, PowSyBl IIDM, pandapower JSON or JSON tables. The format is found from the content; gzip and ZIP work, and #text on a ZIP link takes only matching files. Web servers, buckets, GitHub, GitLab, Google Drive and Dropbox work. Or a built-in grid's name: example, case9, case14, case39, case118, case300, case2869pegase, cigremv, gb ...

## `upload` (type: `string`):

A network file (or a ZIP of them) from your computer, studied together with any links.

## `networkText` (type: `string`):

The text of a network file: a MATPOWER case (function mpc = ...), a PSS/E RAW file, UCTE-DEF, IEEE common data format, or JSON.

## `network` (type: `object`):

Tables of pandapower elements with pandapower's parameter names; buses are named and referred to by name. Lines and transformers take a standard type or their own parameters. Example: {"bus": \[{"name": "A", "vn_kv": 20}, {"name": "B", "vn_kv": 20}], "ext_grid": \[{"bus": "A"}], "line": \[{"from_bus": "A", "to_bus": "B", "length_km": 3, "std_type": "NA2XS2Y 1x95 RM/25 12/20 kV"}], "load": \[{"bus": "B", "p_mw": 2, "q_mvar": 0.5}]}

## `analyses` (type: `array`):

What to work out for each network. The power flow always runs; the other studies start from it.

## `method` (type: `string`):

AC unless the network is huge or only active power flows matter. When the AC power flow finds no solution after four tries, the DC one gives the flows and the findings say so.

## `enforceReactiveLimits` (type: `boolean`):

A generator that would pass its reactive power limit holds that limit and gives up its voltage set point (PV to PQ), as a real machine does. Off, generators hold their voltage whatever it takes, as MATPOWER's runpf does by default.

## `loadScalingPercent` (type: `number`):

Every load scaled by this much: 120 is a 20% heavier day.

## `generationScalingPercent` (type: `number`):

Every generator's active power scaled by this much (machines and static generators such as solar and wind); the slack makes up the difference. Scale load and generation together to keep the slack's share.

## `minVoltagePu` (type: `number`):

The voltage band's floor for every bus. Empty: the network's own limits per bus, else 0.95 pu.

## `maxVoltagePu` (type: `number`):

The voltage band's ceiling for every bus. Empty: the network's own limits per bus, else 1.05 pu.

## `maxLoadingPercent` (type: `number`):

A line or transformer above this share of its rating is overloaded. Empty: each branch's own limit where the network gives one, else 100%.

## `contingencyElements` (type: `array`):

What the N-1 study takes out, one at a time. Parts the outage splits off keep running on their own generators where they have any.

## `maxContingencies` (type: `integer`):

Only the most loaded branches' outages, up to this many. Empty: every one, as far as the time limit allows (the most loaded first).

## `faultType` (type: `string`):

The fault type for the IEC 60909 short-circuit study.

## `shortCircuitCase` (type: `string`):

IEC 60909's maximum case (voltage factor c = 1.1 above 1 kV) sizes breakers and busbars; the minimum case (c = 1.0 above 1 kV, the grid's smaller in-feed) checks that protection still sees a fault.

## `faultBuses` (type: `array`):

Bus names or numbers. Empty: every bus up to 2,000 buses, else the 500 best-connected buses at the highest voltages. Naming buses runs the study even when it isn't picked above.

## `gridShortCircuitMva` (type: `number`):

The upstream grid's short-circuit power, for external grids that don't state it. Empty: typical values by voltage (500 MVA at 20 kV, 5,000 MVA at 110 kV ...), named in the notes.

## `hostingKind` (type: `string`):

What is added at each bus, one bus at a time, until a voltage or loading limit is passed.

## `hostingBuses` (type: `array`):

Bus names or numbers. Empty: the buses with load (the lowest-voltage ones first, up to the most below). Naming buses runs the study even when it isn't picked above.

## `hostingMaxBuses` (type: `integer`):

Each bus takes 10 to 30 power flows.

## `outputs` (type: `array`):

Files for each network, saved in the run's key-value store. The dataset always gets a row per network with the numbers, the findings and links to the files.

## `frequencyHz` (type: `number`):

The system frequency, for files that don't state it (MATPOWER and PSS/E don't): line charging and short-circuit currents depend on it. 60 for North America.

## `timeLimitSeconds` (type: `integer`):

Downloading and studying stop after this long; what was done is kept. Long N-1 and hosting capacity studies stop early and say how far they got. Each network is billed for its own time.

## Actor input object example

```json
{
  "networks": [
    "example"
  ],
  "analyses": [
    "powerflow",
    "contingency",
    "shortcircuit"
  ],
  "method": "ac",
  "enforceReactiveLimits": false,
  "loadScalingPercent": 100,
  "generationScalingPercent": 100,
  "contingencyElements": [
    "line",
    "trafo",
    "trafo3w"
  ],
  "faultType": "3ph",
  "shortCircuitCase": "max",
  "hostingKind": "generation",
  "hostingMaxBuses": 200,
  "outputs": [
    "tables",
    "excel",
    "pictures",
    "network"
  ],
  "frequencyHz": 50,
  "timeLimitSeconds": 300
}
```

# Actor output Schema

## `networks` (type: `string`):

A row per network: verdict, headline, voltages, loading and losses.

## `findings` (type: `string`):

Every check's state, the findings, the violations and the notes.

## `studies` (type: `string`):

N-1 contingencies, short circuit, hosting capacity and optimal power flow.

## `grid` (type: `string`):

The network drawn by branch loading, with overloads and voltage problems marked.

## `voltage` (type: `string`):

Every bus's voltage against the band, by distance from the source.

## `results` (type: `string`):

Summary, findings and every table in one Excel workbook.

## `buses` (type: `string`):

Every bus: voltage, angle, load, generation and status.

## `branches` (type: `string`):

Every line and transformer: flows, losses, current, rating and loading.

## `output` (type: `string`):

The run's summary: every network, its numbers, findings and file links in one JSON object.

## `store` (type: `string`):

Every file in the run's key-value store (with several networks, the second one's files start with net2-, and so on).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "networks": [
        "example"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jumblemog/power-flow-analyzer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "networks": ["example"] }

# Run the Actor and wait for it to finish
run = client.actor("jumblemog/power-flow-analyzer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "networks": [
    "example"
  ]
}' |
apify call jumblemog/power-flow-analyzer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jumblemog/power-flow-analyzer"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/4IqwONTk4obYmuO8H/builds/0HpjtsIsoeypx1XeW/openapi.json
