Usage#

A study needs three things: a power flow engine holding the network, the strategies the algorithm may use, registered in an EnhancementStrategyRegistry, and a CostModel with the price of every action they can take.

Example#

The example below builds a small LV feeder with an overloaded cable and an under-voltage, and resolves them. It is gridforge/examples/quick_start.py, which the tests run, and the Quick Start of the README:

import pandapower as pp

from gridforge import CostModel, PandaPowerEngine
from gridforge.core.grid_enhancement import (
    EnhancementStrategyRegistry,
    GridEnhancementAlgorithm,
)
from gridforge.strategies.line_upgrade import LineUpgradeStrategy
from gridforge.strategies.tap_change import TapChangeStrategy
from gridforge.strategies.transformer_upgrade import TransformerUpgradeStrategy

# A small LV feeder: a 250 kVA substation and a 250 m cable feeding 120 kW
net = pp.create_empty_network()
mv_bus = pp.create_bus(net, vn_kv=20.0, name="MV bus")
lv_bus = pp.create_bus(net, vn_kv=0.4, name="LV busbar")
end_bus = pp.create_bus(net, vn_kv=0.4, name="Feeder end")
pp.create_ext_grid(net, bus=mv_bus, vm_pu=1.0, name="Grid")
pp.create_transformer(
    net, hv_bus=mv_bus, lv_bus=lv_bus, std_type="0.25 MVA 20/0.4 kV", name="Substation"
)
pp.create_line(
    net,
    from_bus=lv_bus,
    to_bus=end_bus,
    length_km=0.25,
    std_type="NAYY 4x50 SE",
    name="Cable",
)
pp.create_load(net, bus=end_bus, p_mw=0.12, q_mvar=0.04, name="Load")

engine = PandaPowerEngine()
engine.network = net

# The cable is overloaded and the feeder end is under-voltage
engine.run_power_flow()
for violation in engine.check_violations():
    print(f"Before: {violation.constraint_type.value} at {violation.element_id}")

# The strategies try the cheapest fixes first: tap changes, then line and
# transformer upgrades: a larger type, or one more conductor or unit of the type
# in place, whichever is cheaper at the prices below.
registry = EnhancementStrategyRegistry()
registry.register_strategy(TapChangeStrategy())
registry.register_strategy(
    LineUpgradeStrategy(
        line_types={
            "lv": {
                "overhead": [],
                "underground": ["NAYY 4x50 SE", "NAYY 4x120 SE", "NAYY 4x150 SE"],
            }
        }
    )
)
registry.register_strategy(
    TransformerUpgradeStrategy(["0.25 MVA 20/0.4 kV", "0.4 MVA 20/0.4 kV"])
)

# Every type of these ladders needs a price: a missing one raises
# MissingUnitCostError before the run (see "Unit Costs" in the usage docs).
cost_model = CostModel(
    {
        "line_upgrade": {  # €/km
            "NAYY 4x50 SE": 50.0e3,
            "NAYY 4x120 SE": 70.0e3,
            "NAYY 4x150 SE": 80.0e3,
        },
        "transformer_upgrade": {  # € per unit
            "0.25 MVA 20/0.4 kV": 5000.0,
            "0.4 MVA 20/0.4 kV": 8000.0,
        },
        "tap_change": 10.0,  # € per tap step
    }
)

algorithm = GridEnhancementAlgorithm(
    power_flow_engine=engine,
    strategy_registry=registry,
    cost_model=cost_model,
)
success, results = algorithm.run()

print(f"Resolved: {success}, total cost: {results['total_cost']:.0f} €")
for action in results["actions_applied"]:
    print(f"- {action['type']}")
print(f"Remaining violations: {len(results['remaining_violations'])}")

To study an existing network, load it into the engine with engine.load_network("my_grid.json") (pandapower JSON, pickle or Excel), or assign a pandapower network to engine.network as above.

The engine, the strategies and the results identify buses, lines and transformers by their name. Loads and static generators are identified by their index, in get_flexibility_data, apply_flexibility_action and the flexibility actions of the results, but their flexibility settings (engine.flexibility_settings, and the max_flex_pct of create_load and create_generator) are keyed by their name. Each of these elements must therefore have a name, and two buses, two lines, two transformers, two loads or two static generators must not share one; elements of different tables may (a bus and a line, a load and a static generator). engine.check_names(), which can be called right after loading a network, and run_power_flow before each power flow, raise a ValueError that lists the elements without a name (None, NaN or "") by their index, and the shared names with the indices of their elements. Nothing is renamed for you. Networks that leave elements unnamed, as several of pandapower’s example networks do (create_dickert_lv_network, create_synthetic_voltage_control_lv_network), are named with engine.fill_missing_names(), which gives them names of the form bus_<index>, line_<index>_<from bus>_to_<to bus>, trafo_<index>_<hv bus>_to_<lv bus>, load_<index>_<bus> and sgen_<index>_<bus>, never one that another element of the table already has:

import pandapower.networks as pn

engine = PandaPowerEngine()
engine.network = pn.create_dickert_lv_network()
engine.fill_missing_names()
engine.check_names()

A load or a static generator named so has no flexibility until it is given a setting under its new name. Shared names are for you to change, before giving the settings. The MV/LV feeder case study does it as it loads a feeder (mv_lv_feeder.make_shared_names_unique): of the loads of one name, the first keeps it and the others take it followed by _2, _3…, which changes nothing there, as every load is given the same flexibility. create_load and create_generator refuse a name that another load (static generator) already has, or no name, before creating anything: the max_flex_pct they store under it would otherwise change the setting of the element that has it.

The ZIP shares of the loads (const_z_p_percent, const_z_q_percent, const_i_p_percent and const_i_q_percent, in percent of the power of the load) must be numbers, not missing (NaN, None or pd.NA). pandapower’s power flow does not converge on NaN, and the error does not say why (on the SimBench network, “did not converge after 50 iterations”): engine.check_zip_shares(), which can be called right after loading a network, and run_power_flow before each power flow, raise a ValueError that gives up to five of the loads concerned, by index, and the columns. A share of 0 means constant power, as it does for a load made by create_load; nothing is filled in for you. simbench leaves all four NaN, so a SimBench network needs net.load[ZIP_SHARES] = net.load[ZIP_SHARES].fillna(0.0) (ZIP_SHARES, the list of the four columns, is in gridforge.engines.pandapower_engine), as the SimBench case study does. The loads that are not in the power flow are not checked: those out of service or at a bus that is out of service or in an island with no source (but pandapower leaves NaN in the results of an out-of-service load that has NaN shares, in res_load and in res_bus.p_mw at its bus, so fill them anyway if you read these), and so is a network solved with voltage_depend_loads set to False, in the power flow settings or in net.user_pf_options (the settings first), which does not read the shares. The check applies whatever the algorithm, although gs and fdbx converge with NaN shares. A missing column is not NaN: pandapower 3.2 raises a KeyError that names it, while the loads are voltage-dependent. Static generators have no ZIP shares in this version. GridEnhancementAlgorithm.run lets this ValueError go, as it does the one of check_names, when it comes from the initial power flow.

The sensitivities of the engine answer only from a run of its own run_power_flow: on a network solved outside it, with pandapower.runpp for instance, they refuse until run_power_flow has been run.

PandaPowerEngine can also change the topology of a network, for the strategy that builds a new MV/LV substation (NewSubstationStrategy, below): split_line puts a new bus inside a line, open_line opens a line by an open switch at one of its ends (a normally-open point: the line stays in place), and add_bus, add_line and add_transformer create a bus, a line or a transformer, the last with the vector group and tap changer of an existing unit when it is given one (like). get_bus_coordinates and get_line_geometry read the geodata (geo columns, or a bus_geodata table) as (longitude, latitude), None where there is none. These operations take and return buses by their index, the nodes of create_topology_graph, and lines and transformers by their name; each element they create gets a name no other element of its table has (_2, _3… added when needed). They forget the cached partition of the network, and do not run a power flow. A change is undone by putting back a copy of the network taken before it, as the algorithm does. The strategy also reads the buses by index with their solution (get_buses_info), and the parameters of a transformer and of a transformer type (get_transformer_parameters, get_transformer_type_parameters). The other engines raise NotImplementedError, the default of PowerFlowEngine.

NewSubstationStrategy (gridforge.strategies.new_substation, #80) resolves LV over-voltages and under-voltages that the cables cannot, because the busbar of the LV network has no headroom left, by new MV/LV units that each feed a part of the network:

from gridforge.strategies.new_substation import NewSubstationStrategy

registry.register_strategy(
    NewSubstationStrategy(
        transformer_types=["0.25 MVA 20/0.4 kV", "0.4 MVA 20/0.4 kV", "0.63 MVA 20/0.4 kV"],
        mv_line_type="NA2XS2Y 1x95 RM/25 12/20 kV",
    )
)

In each radial LV network with violations that one unit feeds, it ranks the buses by LinDistFlow and lets a power flow decide between the first n_checked (3), adding up to max_new_substations (3) units per LV network over a run. Each LV bus is then fed by the nearest unit along the cables, and the lines between parts are opened by an open switch. A new unit takes the tap changer of the unit in place, at the position that gives one of Enedis’s no-load rises of the LV voltage (new_unit_taps, 0, +2.5 and +5 %) with the rated voltages of its type: positions 0, 1 and 2 for a 20/0.4 kV unit tapped on the LV side by 2.5 % steps, -1, 0 and 1 for one rated 410 V. A network whose unit has a tap changer other than a ratio one (Symmetrical, Tabular, or a phase shift per step) is left out. A new unit is sized for its part (Enedis’s winter and summer situations, on what its loads, storage units, static generators and generators draw and produce, a load of negative power producing), and is teed into the nearest MV line of its MV network by a cable of mv_line_type at most max_mv_distance_km (0.5 km) long, mv_detour_factor (1.0) times the straight distance. Without geodata it places no unit unless default_mv_distance_km is set; the cable then runs that length from the MV bus of the unit in place, whatever max_mv_distance_km, as a setting chosen rather than a distance found. An LV network whose MV side is beyond the MV limits is left out and reported as MV-limited: that is the MV network’s problem. The action ("type": "new_substation") lists, for each new unit, its transformer, type and tap (position, rise chosen and rise as built), its LV bus, the MV line teed into and the fraction of its length, the MV cable and its length, the lines opened, the buses it feeds, and the loading of the unit in place before and after; for each LV network, the new parts of the MV lines it split (split_lines, with the line each is a part of); and, under created, the units and lines it created, for a later upgrade of them to be charged from nothing (see Unit Costs). It needs an engine with the operations above (PandaPowerEngine), and takes no action on another; with a cost model, each new substation is charged its works, its unit and its MV cable (new_substation, see Unit Costs). It is registered by the extended and hosting_capacity profiles of the case study, not by standard (see Planning profiles).

Two parameters take back upgrades before a unit is placed. take_back_line_upgrades is off in the strategy; take_back_transformer_upgrades is on, but acts only with the first. The extended and hosting_capacity profiles turn on the first (see Planning profiles). With take_back_line_upgrades=True, before it places a unit in an LV network the strategy takes back the line upgrades the run has made there, for its loading as for its voltage: each line gets the type and conductors it had at the start of the run, which the algorithm lends the strategies as lines_at_start, and the unit is placed on the network as it was then. The action lists these lines under lines_taken_back; with a cost model, they are charged as the line upgrades charge a line, from its state at the start of the run, so that what the earlier actions were charged for them is refunded, and a line upgraded again later is charged from that state again. The action’s cost is the price of its substations (substation_cost) plus that of the take-back (take_back_cost, a refund, 0 or less); the summary of a run gives the first as new_substation_cost and the refund as new_substation_take_back_refund, and does not report a line taken back as at the conductor cap unless it is at the cap at the end. With take_back_transformer_upgrades (True by default), the take-back also gives the MV/LV unit feeding the network, if it was in place at the start of the run, its type and number of units of then (transformers_at_start, lent as lines_at_start), keeping its tap position; the action lists it under transformers_taken_back, it is refunded with the lines, and the summary counts it in new_substation_transformers_taken_back. A unit the run created is not taken back. If no unit is placed in the network, its lines and its unit keep their upgrades. units_per_call caps the units one call adds to an LV network (None, the default: up to max_new_substations); at 1, the line upgrades of the next pass reinforce what the unit leaves, and the strategy is called again if they are not enough.

The registry addresses the violation types in its priority order, by default transformer loading, line loading, over-voltage, then under-voltage, and for each type tries the strategies that apply to it in the order of their cost levels, each on what the previous ones left.

Each violation has the level of its network, "mv" or "lv" (ConstraintViolation.level; PandaPowerEngine gives that of the bus, of the buses of a line, and of the LV side of a transformer, so that an MV/LV unit is in the LV network it feeds). An entry of the priority order can be a type at a level, a pair, whose turn takes the violations of that level alone; during it, the engine reports the strategies the violations of that level alone, as they read them again after their steps. A strategy registers for the levels of applicable_levels() (both by default); in an order without levels, as the default one, it gets every violation of its types. TOP_DOWN_ORDER (gridforge.core.grid_enhancement) is the MV network first, then the LV networks: transformer loading, line loading, over-voltage and under-voltage at "mv", then the same at "lv". A violation an LV turn brings about in the MV network gets the MV turn again in the pass:

from gridforge.core.grid_enhancement import TOP_DOWN_ORDER
from gridforge.strategies.no_load_tap import NoLoadTapStrategy

registry = EnhancementStrategyRegistry(violation_priority_order=TOP_DOWN_ORDER)
registry.register_strategy(NoLoadTapStrategy())

NoLoadTapStrategy moves the no-load tap of the MV/LV unit feeding an LV network with over- or under-voltages, one position at a time, among the positions that give the rises of taps (Enedis’s 0, +2.5 and +5 % by default, positions 0 to 2 of the feeder files’ units; (-2.5, 0.0, 2.5) for Enedis’s older units), while that leaves fewer buses beyond the limit and none more beyond the other; a unit outside those positions goes to the nearest of them in the direction of the move. It is a planning strategy of the LV networks, at cost level 1: the tap is set off load and kept through the works that follow, unlike the operation strategy TapChangeStrategy, with which it should not share units. It is priced per intervention, a site visit, whatever the positions moved (no_load_tap): each unit is charged from its tap position at the start of the run, which the algorithm lends the strategies as tap_positions_at_start, so that a run pays one intervention per unit whose tap ends away from it. A second move of a unit already moved adjusts the first and costs nothing more, a move back to its start takes the first back, and a unit the run created costs nothing (its tap is set when it is commissioned). Each entry of the action records its start_position and the interventions it adds; the summary counts them in no_load_tap_interventions. A tap moved by a transformer upgrade (brought within the range of a new type) is not an intervention, and is not told apart: a later move back to the start of such a unit would be refunded what was not charged.

With a cost model, the algorithm also tries that chain of strategies from the second strategy, from the third, and so on, and keeps the one whose run ends with the fewest violations, then the lowest cost: each chain is followed by the rest of the run, made in the order of the cost levels. A strategy is thus chosen for what it costs, together with what it leaves to the strategies after it, rather than for its cost level. The rest of the run is followed as long as it improves: it is given up after a pass that removed no violation and lowered no cost, so that a run which does not resolve its violations is not replayed to its last pass at each choice. As the chain in the order of the cost levels is among those rated, the run does not end with more violations, or as many at a higher cost, than in that order. Where a rating was given up and another chain was preferred, the order of the cost levels could have done better over the passes the rating did not follow: the algorithm then also makes the run in that order, and returns whichever of the two ends with fewer violations, then with the lower cost. The choice can take several times longer than the order of the cost levels. GridEnhancementAlgorithm(..., strategy_choice="first") keeps the order of the cost levels, as does a run without a cost model.

Results#

run() returns (success, results). success tells whether every violation was resolved, and results holds:

  • actions_applied: the actions, in order, each a dictionary with its type (tap_change, line_upgrade, …) and the details of what was changed;

  • total_cost: their total price, in euros, or 0 without a cost model;

  • remaining_violations: the violations of the returned state;

  • iterations: the number of passes made (see below);

  • diverged and divergence_events: whether a strategy made the power flow diverge;

  • history and summary: the state after each step, and statistics of the run.

The summary counts in lines_at_conductor_cap (and names in lines_at_conductor_cap_names, and counts by level in lines_at_conductor_cap_lv and lines_at_conductor_cap_mv) the lines that the cap on conductors in parallel of LineUpgradeStrategy (max_parallel_conductors, 3 by default) stops on, for the violations the run leaves: a violation that only more conductors would resolve is left, and reported there, rather than resolved by a stack of conductors (see “Conductors in Parallel” in the methodology). Each line is judged against its own cap.

The cap of 3 is a modelling choice of the case study, not an Enedis rule: Enedis lays no cables in parallel on its LV and MV feeders, but on the direct MV feeders of a customer (Enedis-NMO-RES_011E §3.2.3). max_parallel_conductors also takes a cap by level of network (#80, step 6g), the levels of ConstraintViolation.level (“lv” for a line between buses of 1 kV or less), None or a level left out for no cap there, and uncapped_lines exempts lines from it: a collection of names, or a rule, a function of the engine that gives the names. dedicated_lines is such a rule: the MV lines of a direct feeder, one that leaves a source busbar and serves one customer alone. Without the source busbars (an external grid’s bus or the MV side of an HV/MV transformer, with the buses closed bus-bus switches join it to), the network falls into parts; a part that hangs from one busbar, has no transformer and one bus with a customer (an element in service: a load, a generator, a storage unit, whatever its power) is a direct feeder, and all its lines are dedicated, however many segments in series. A spur off a shared feeder, or a feeder that also serves an MV/LV unit or another customer, is not. The rule depends on the structure of the network alone (it needs get_customer_buses of the engine; on an engine without it, no line is dedicated). A cap of one conductor on the LV and MV lines, with the direct MV feeders exempt, is:

from gridforge.strategies.line_upgrade import LineUpgradeStrategy, dedicated_lines

LineUpgradeStrategy(
    line_types,
    max_parallel_conductors={"lv": 1, "mv": 1},
    uncapped_lines=dedicated_lines,
)

In the case study, line_upgrade_max_parallel_conductors (3) and line_upgrade_uncap_dedicated_lines (off) of CaseStudyConfig, create_strategy_registry(max_parallel_conductors=..., uncap_dedicated_lines=...) and profile_study.py --max-parallel-conductors lv=1,mv=none --uncap-dedicated-lines on set them.

With NewSubstationStrategy (new MV/LV substations against LV over- and under-voltages, #80), the summary counts the units it added in new_substations, of which new_substations_over_voltage and new_substations_under_voltage by the direction of the violations they were placed for, their MV cable in new_substation_mv_cable_km, the LV lines they opened in new_substation_lv_lines_opened and the price of their actions in new_substation_cost (later upgrades of what they created are priced in the upgrade actions). lv_networks_mv_limited (and lv_networks_mv_limited_names, by their unit) counts the LV networks with an over- or under-voltage left whose MV side is beyond the MV limits, which no new substation can resolve. All are 0 without the strategy.

TransformerUpgradeStrategy(transformer_types, parallel_units="allowed") adds units of the type in place in parallel among its options, as before #83. With parallel_units="with_works", each unit added beside the units a transformer had at the start of the run is also charged the works of a new substation of its type (new_substation["works"], which the run then requires for every configured type); with "none", a transformer is only replaced by a type that carries it with its units, and one that no type carries keeps its violation. The summary counts these in units_at_the_top_of_the_ladder (and names them in units_at_the_top_of_the_ladder_names), 0 with the other settings (see “Transformer Upgrades” in the methodology). In the case study, transformer_upgrade_parallel_units ("allowed") of CaseStudyConfig, create_run(parallel_units=...) and profile_study.py --parallel-units allowed|with_works|none set it, and the config’s transformer_upgrade_extra_types (none), create_run(extra_transformer_types=...) and profile_study.py --extra-transformer-types FT_Standard_Standard_1000kVA add types at the top of its ladder, such as Enedis’s 1,000 kVA unit, whose price in the case study (28,000 € the unit, 34,878 € the works) is an extrapolation, not a sourced price. NewSubstationStrategy refunds a unit in place it takes back by the parallel_units of the transformer upgrades of the run, which the algorithm lends it, unless it is given transformer_parallel_units; a run whose strategies disagree on it refuses to start.

The engine’s network is left in the returned state, so it can be saved or plotted.

Power flow divergence#

A strategy can push the network past the point where the power flow is solvable. When the power flow diverges after a strategy, the algorithm undoes that strategy completely and tries the next one, so run() still returns the best solution it found and leaves the network in a solved state. The results tell such a run apart from one that simply found no strategy able to do more:

if results["diverged"]:
    for event in results["divergence_events"]:
        print(f"{event['strategy_name']} made the power flow diverge "
              f"({event['violation_type']}): {event['message']}")

diverged is also True when another strategy then resolved all violations. If the initial power flow diverges, there is no solution to return and run() raises gridforge.PowerFlowNotConverged.

PandaPowerEngine.run_power_flow() raises gridforge.PandaPowerNotConverged, which is both a PowerFlowNotConverged and pandapower’s LoadflowNotConverged: code that catches either around a power flow sees a divergence.

Passes and partial solutions#

The algorithm works in passes: a pass addresses each violation type of the priority order once, and gives a type whose turn has passed one more turn, before the next type, when a later turn brings about violations of it that were not there as its turn ended: a flexibility call for the over-voltages that overloads a line, for instance, is followed by the turn of the line overloads again. A type gets at most one more turn a pass, and its history entry reads “Applied strategy for … again”. max_iterations is the maximum number of passes, and results["iterations"] the number made; the turns given again do not count as passes. A violation type that the priority order of the EnhancementStrategyRegistry leaves out is not addressed: its violations remain, with a warning, and the run cannot succeed while they do.

A run that does not resolve every violation returns its best partial solution: the state with the fewest violations, then the cheapest, so that spending that resolves no violation is not kept, then the one with the least severe violations. Severity is the sum of the excesses over the limits, each relative to its limit for a loading, and to the width of the allowed band (the distance of the limit from 1 pu) for a voltage: a bus at 0.85 pu against a limit of 0.90 pu counts 0.5, a line at 110 % of its limit 0.1.

The states compared are the state the run starts from and each state a strategy leaves when it returns, including those between two strategies of a violation type; the steps inside a strategy are not compared. The count of violations comes first, whatever their size, and a state with as many violations but smaller excesses is kept over a cheaper one only when their costs are equal, to the precision of the power flow: a dearer state is never kept for its severity. A strategy that takes many steps, as a flexibility call does, is thus rated by the state it ends in, which can be dearer than a state it went through on the way with as many violations. On a see-saw network of the bench of #65, two overloads at 5 % and 8.6 % and a single flexibility strategy, the run returns, after 3 passes, the state left by the first call, one overload of 0.16 % for 3,090.06 €, over those of the next two calls (0.017 % for 3,325.07 €, 0.0016 % for 3,349.55 €) and over the initial state, which costs nothing but has two violations; the first call went through states with that one overload, at 1.4 %, from 1,018.37 € on (measured after each power flow of the call).

Unit Costs#

CostModel takes a dictionary of prices, in euros. The keys it reads are:

Key

Shape

Price

line_upgrade

type → €/km

Replacing a conductor of a line by this type (LineUpgradeStrategy). A line with parallel conductors is charged for each of them, as they are all replaced.

new_line

type → €/km

Optional. Adding a parallel line of this type, when that is not the line_upgrade price of the type.

transformer_upgrade

type → € per unit

Replacing a transformer by this type, or adding one in parallel (TransformerUpgradeStrategy). A transformer of several units in parallel is charged for each unit replaced.

new_substation

works: type → €; mv_cable: type → €/km

A new MV/LV substation (NewSubstationStrategy): its works by the type of its unit, and its MV cable by cable type. Its unit is charged at the transformer_upgrade price of its type.

tap_change

€ per tap step

A change of tap position (TapChangeStrategy).

no_load_tap

€ per intervention

A change of the no-load tap of a unit in place, one site visit whatever the positions moved (NoLoadTapStrategy). 700 € HT in the case study, the direct cost of a visit (see “The price of a no-load tap” below). A unit with works in the run (another type, or another number of units in parallel) pays none: the crew of the works sets its tap.

load_shedding

€/MW

Reducing a flexible load (FlexibilityStrategy).

generation_curtailment

€/MW

Reducing a flexible generator (FlexibilityStrategy).

The price of a no-load tap#

Enedis publishes no price for a change of no-load tap: de-energising network assets for works is on quote (CRE, délibération n°2026-142). The case study’s 700 € HT per intervention (decided on 2026-11-27) is the direct cost of one visit, rebuilt from quantities:

  • 1.5 agent-hours of preparation, then 2 agents for 1 h of travel and 1.5 h on site (switching, consignation, the tap, re-energising, a voltage check), 6.5 agent-hours at 100 € per agent-hour: about 650 €. The crew size and the hours are assumptions: no public source gives them. The rate is assumed too, between the billing rates of a French energy syndicate, 70 €/h for one agent with a light vehicle (SDE65, règlement financier 2026), and of the Walloon DSO ORES, 163.78 € per extra hour of a technician in an MV cabin (ORES, tarifs non périodiques); INSEE gives 53.8 € per hour worked of direct labour cost in the production and distribution of energy (2020).

  • A posted notice to the customers of the unit: 47.9 letters at 1.52 €, 73 € (39.6 M customers over 826,527 MV/LV substations, Enedis, rapport RSE 2025; the letter rate of Service-Public.fr).

  • The outage is not valued, as the other prices of the study are outlays, from Enedis’s price list or unit prices.

The range is 300 to 3,000 € HT. What drives it: the labour rate (1,000 to 1,600 € on the same quantities with the outage valued), a mobile generator to keep the customers supplied (about 1,700 €, plus delivery and fuel), the outage valued at the TURPE 7 incentive on criterion B, 6.4 M€ per minute (CRE, délibération n°2025-40), about 465 € for an hour, 1,200 € in all, and rural units without MV switchgear, which must be de-energised from further up the feeder (2,500 € and more). Two published figures for the same operation bracket it: SA Power Networks’ planning cost of AUD 5,000 (about 3,020 €, regulatory proposal 2025-30) and AUD 1,000 to 2,000 per trip (about 600 to 1,200 €, Renew for Energy Consumers Australia).

A unit the run replaces, or gives a unit in parallel, pays no intervention on its tap, in whatever order the works and the tap move come: the crew is already on site, and Enedis’s price for a transformer power increase in an existing substation (barème de raccordement, CRE délibération n°2026-160) has no line for the tap. The marginal labour of a retap during works, about 50 €, is left out as a simplification (at most about 5.6 k€ over the 33 units of the case study it concerned). The derivation is in research_notes/New MV-LV substations/no_load_tap_price.md.

A line upgraded in several steps is charged once, for what the run lays: the conductors it had when the run started at the line_upgrade price of their final type if the type has changed, and each conductor added at the new_line price of that type. The types it went through on the way are not charged, as they are never laid. This holds across the actions of a run: when a line upgraded for its loading is upgraded again for its voltage, the second action is charged the difference between what the line costs after it and what it had already been charged. A transformer is charged in the same way, for the units the run leaves laid on it: every unit it has at the end, at the transformer_upgrade price of its final type, if that type is not the one it had when the run started, and otherwise each unit added, at the price of its type. A unit taken from 250 to 400 kVA by one action and to 630 kVA by another is charged for the 630 kVA unit only, the second action being charged its price less that of the 400 kVA unit; a unit added in parallel and then replaced, with the others, by units of another type is not charged. The summary likewise counts such a line once in lines_upgraded and total_line_length_upgraded, and each conductor added in lines_added and total_line_length_added. The power a transformer gains, in total_transformer_power_added_parallel and total_transformer_power_added_upgrade, is counted from the rating of its units in the transformer table, whether or not they have a catalogued type: the upgrades record that of one unit before the step as old_rating (VA), and an upgrade without it is read from the catalogue. A conductor that a line upgrade adds and then takes back, replacing the conductors of the line by fewer of a larger type, is neither charged nor counted as added; the entry of that type change gives the conductors it takes back as conductors_removed. A thermal upgrade takes back conductors it has added itself; an upgrade for a voltage violation can also take back those that an earlier action of the run added, for instance the second conductor a thermal upgrade gave the line (see “Voltage Steps with Prices” in the methodology). A caller that counts the conductors added to a line from the entries, as the largest parallel_count less the conductors the line had before, must subtract the conductors_removed of the entries that follow, in the same action or a later one, which only a run with a cost model records.

A new MV/LV substation is charged three prices: its works, the enclosure, MV switchgear, LV board and civil works (new_substation["works"] of the type of its unit), its unit (the transformer_upgrade price of its type), and its MV cable from the tee to the unit (new_substation["mv_cable"] of the cable type, per km, times its length). Splitting the MV line it is teed into and opening LV lines cost nothing. The works are priced by the type of the unit so that the price follows the class of substation a unit fits in: the case study (MV_LV_FEEDER) gives 11,491 € for a compact substation (PRCS/PSS) up to 250 kVA and 34,878 € for a prefabricated one above, fitted with its unit prices to Enedis’s list prices of a compact substation up to 250 kVA (17,787 € HT up to 160 kVA, 21,898 € HT up to 250 kVA, Enedis-NMO-RAC_009E v8 §17), and the prefabricated works to Enedis’s 42,545 € HT for the other prefabricated types (the same section), which gives 16,491, 19,491 and 21,491 € at 100, 160 and 250 kVA and 49,878 and 54,878 € at 400 and 630 kVA, where Enedis prices on quote. The cable has a price of its own, which does not fall back on the new_line or line_upgrade price of its type: these are what the line upgrades charge for a conductor of that type, and the cable of a new substation, trench included, is dearer (145,000 €/km in the case study, Enedis’s 145 €/m, against 90,000 €/km for a conductor of U_AL_150_mv).

Types are those given to the strategies, written the same way. The price of an action is never assumed: run() raises gridforge.MissingUnitCostError before starting, with the list of the missing prices, if one that the configured strategies can need is not there. The flexibility prices are only needed when a load or a generator has flexibility. The line and transformer strategies need the price of the types they are given; NewSubstationStrategy the works and unit prices of each of its transformer_types and the cable price of its mv_line_type.

A line can also be given a parallel conductor, and a transformer a unit in parallel, of the type it has, whatever the types given to the strategies. Whether a run adds one is not known before it, so a run starts without the prices of the types in place on the network (the new_line or line_upgrade price of a line type, the transformer_upgrade price of a transformer type) and logs a warning that lists the missing ones. If an action then needs one of them, run() raises MissingUnitCostError when the action is priced, and leaves the network as it was before that action. With strategy_choice="lookahead", a chain of strategies that needs a missing price is left out of the choice, and the run raises only if no other chain is left.

The prices also choose how an overloaded line or transformer is reinforced: with a larger type, or with conductors or units of the type in place in parallel, whichever is cheaper (see “Thermal Sizing” in the methodology). GridEnhancementAlgorithm lends its cost model to its strategies, as cost_model, for the time of each run, with the type and conductors of each line as the run started, as line_origins, and the type and units of each transformer, as transformer_origins, for an option on a line or a transformer to be priced as the run charges it, and gives them back their own when the run ends, however it ends. A line or a transformer is charged for what the run leaves laid on it, from its state at the start of the run: a type laid and then replaced within the run is not charged, and the costs of the actions on an element add up to that of its final state. The upgrades of an action record the state at the start of the run as origin_type and origin_conductors (lines) or origin_units (transformers), as does a strategy used on its own that is given line_origins or transformer_origins. An element that an action of the run creates, the unit or the MV cable of a new substation, is charged from nothing, (None, 0): a later upgrade of it is charged what it costs then, at the line or transformer prices, less what it cost as created, at those prices too, so that a new 630 kVA unit taken to 1000 kVA costs the 1000 kVA unit in all, not both units (with the works of its type, below). A new cable whose one conductor is replaced by a larger type is likewise charged the difference of the line prices of the two types: the part of its own price above the line price of its type, the trench, stays with the new substation, and is not taken off the upgrade, which would then be charged less than nothing. A unit created with a new substation is charged, for each unit, the works of a substation of its type with its unit price, whatever the path: a new 250 kVA unit (a compact substation) taken to 400 kVA is charged the difference of the works and of the units, so that it costs in all what a new 400 kVA substation costs (49,878 € and its cable in the case study), and a unit added in parallel to it costs its works and unit again. Every type a transformer upgrade can take a new unit to thus needs a works price: without one, that type is left out of the options for a new unit, with a log line, and an action that takes a new unit there anyway stops on MissingUnitCostError when it is priced. A unit in place at the start of the run is charged its unit price alone, as before. The part of an MV line split to tee a new substation into is charged from the state of that line at the start of the run. The action lists what it created under created ({"transformers": {name: None}, "lines": {name: None or the line split}}); the algorithm adds their states to those it lends as an action is applied, and drops them as it is undone, in a chain of strategies that lookahead does not keep for instance. An engine that cannot list its lines (PowerFlowEngine.get_lines_info) or its transformers (PowerFlowEngine.get_transformers_info) has them charged from their state before each action, not from their state at the start of the run (PandaPowerEngine lists both). A parallel element whose price is missing is then left out of that choice. With prices, a line that an action has given conductors in parallel can still be given fewer conductors of a larger type once they carry its current for less, the conductors the action added being taken back, never those the line had before the action. A run without a cost model, or a strategy used on its own without one, takes the smallest type that carries the overload, and elements in parallel only when no type does.

A type change of a line for a voltage violation, with prices or without, and a type given to a line or a transformer for a loading violation with no more elements than the step leaves, are checked by the power flow the strategy runs after it: if the element is over its limit, the step is undone and the action goes on as if that type had not been offered with so few elements (see “Steps Checked After the Power Flow” in the methodology). The check needs an engine that can save an element and give it back (save_line and restore_line, save_transformer and restore_transformer) and save the solution of its latest power flow and put it back (save_solution and restore_solution), as PandaPowerEngine does. The other engines raise NotImplementedError, the default of PowerFlowEngine: their steps are taken unchecked, as before, and no conductor is taken back. So does PandaPowerEngine.save_solution when the controllers of the engine act (run_control in power_flow_specific_settings, with a controller in service), as undoing a step would not undo what a controller changed in the power flow after it. An engine that gives a df column in get_lines_info has its lines rated with that derating factor when a type change is sized on their current. A type change also gives a line the rating of its new type, even where its own max_i_ka in the line table was set below that of its old type: a derating that must survive a type change belongs in df, which is kept.

A transformer that has no type (a std_type of None, NaN or "", as pandapower writes it for a unit created from its parameters) is sized on the rating of its table, sn_mva, and so is one whose type is not in the standard types. It is never replaced by a type of lower rating: when no configured type is larger, or when that is the cheaper option, it is given a unit in parallel, of its own kind. That unit is charged at the transformer_upgrade price under the key None for a transformer that has no type, and at the price of its type name otherwise; the warning names it as unit_costs['transformer_upgrade'][None]. None is one price for every transformer without a type, whatever its rating:

CostModel({"transformer_upgrade": {
    "0.63 MVA 20/0.4 kV": 12000.0,
    None: 30000.0,  # a unit added next to a transformer that has no type
}})

A line that has no type, likewise, is sized on the rating of its table, max_i_ka. As neither its voltage level nor its category (overhead or underground) is known, it is not replaced by a configured type: it is given conductors of its own kind in parallel, and a voltage upgrade leaves it as it is. Such a conductor is charged at the new_line price under the key None, or failing that at the line_upgrade price under it, as for a line of a type outside the configured ones; the warning names it as unit_costs['new_line'][None]:

CostModel({"line_upgrade": {
    "NAYY 4x150 SE": 70000.0,
    None: 60000.0,  # per km, a conductor added next to a line that has no type
}})

A price is a real number, 0 or more: an int, a float, a Decimal or a numpy scalar. Anything else that is given as a price (a string, even one that reads as a number, NaN, an infinite or a negative value) raises gridforge.InvalidUnitCostError, before the run for the prices that the configured strategies can need. The flexibility prices are charged for the power taken off the network: for a pandapower load or generator with a scaling, its p_mw times its scaling.

To make an action free, declare it with a price of 0.0. To compute no cost at all, run the algorithm without a cost model. With strategy_choice="first" a price only changes the reported total_cost; with the default "lookahead" the prices also decide between the strategies of a violation type (see “Passes and partial solutions”).

load_shedding and generation_curtailment are prices per MW, not per MWh: the algorithm works on one operating point and has no duration. The price must carry that assumption, on the same horizon as the investments it is added to, as described in the methodology. For instance, a compensation of 100 €/MWh, 50 equivalent hours of curtailment per year and a 20-year horizon give "generation_curtailment": 100 * 50 * 20, that is 100000 €/MW. These figures only illustrate the calculation.

Visualization#

You can visualize the network and violations using the plotting utilities:

# Plot the initial state with violations
pf_engine.plot_network_violations(show_ids=True)

# After running the algorithm, plot the results
pf_engine.plot_network_violations(
    enhancement_results=results,
    show_ids=True
)

Case Studies#

The scripts and notebooks of gridforge/case_study run the algorithm on example networks, with the types and prices of gridforge/case_study/config.py. From the root of a clone, after uv sync:

  • MV/LV feeders (mv_lv_feeder.py): the 150 feeders fetched with uv run python -m gridforge.data fetch (see “Data” in Installation), with loads at 2.5 times their value, without flexibility and with 30 % of every load flexible. uv run python gridforge/case_study/mv_lv_feeder.py runs the 300 cases, in one process by default, so as never to take all the cores of a shared machine, and writes the HTML page of each run in results/. Its options are --workers (the number of processes, 1 by default), --data-dir (the feeder files, by default where python -m gridforge.data fetch writes them), --feeders (names of feeder files of --data-dir, not paths; all of them by default) and --out (the directory of the pages, results). It warns, before the runs, of published feeders that are not those of the version of the data gridforge pins, and, when it runs a whole directory that holds some of them, of those it lacks; a feeder of one’s own, of another name, is not checked:

    OMP_NUM_THREADS=1 uv run python gridforge/case_study/mv_lv_feeder.py --workers 4 \
        --feeders 52_MVFeeder1118 11_MVFeeder0725
    

    benchmarks/profile_study.py runs the same cases, with the same --data-dir and --feeders, and --workers (4 by default, not 1), and records the time and the version of the data in a JSON file:

    OMP_NUM_THREADS=1 uv run python benchmarks/profile_study.py study --workers 4 \
        --feeders 52_MVFeeder1118 11_MVFeeder0725 --out study.json
    

    Without --feeders, both run all of them (see Performance). profile_study.py refuses feeder files that are not those of the version of the data gridforge pins (a file of version 1 left from gridforge 0.3.0, for instance), unless --allow-other-data is given.

    The case study runs a planning profile (see Planning profiles). standard is the default (profile of CaseStudyConfig in config.py): the default order, with the lookahead, priced, and with the line upgrades, the transformer upgrades and the no-load tap of the unit in place. screening, extended and hosting_capacity search otherwise. To choose one:

    • mv_lv_feeder.py --profile NAME runs the case study with a profile.

    • mv_lv_feeder.create_run(with_flex, profile=NAME, **overrides) gives the registry and the options of the algorithm; create_strategy_registry gives the registry alone. Both take the settings of the profile as overrides: order (default, top_down or loading_first), no_load_tap, new_substation (registers NewSubstationStrategy, with the new_substation_* fields of the config), max_new_substations (3 in the config), units_per_call, take_back_line_upgrades, take_back_transformer_upgrades, restrict_to_violation_zone and one_upgrade_per_zone. create_run also takes strategy_choice and priced. max_parallel_conductors and uncap_dedicated_lines are the study’s data, not the profile’s.

    • benchmarks/profile_study.py study --profile NAME runs the 150 feeders with a profile, and --order, --strategy-choice, --new-substation on|off, --max-new-substations N, --no-load-tap on|off, --max-parallel-conductors (an integer, none, or a cap by level such as lv=1,mv=none) and --uncap-dedicated-lines on|off set the study’s cap, which no profile sets. It records these as registry_options, the profile of each run and the figures of the new substations and of the no-load taps (new_substation*, no_load_tap_interventions, lv_networks_mv_limited):

    OMP_NUM_THREADS=1 uv run python benchmarks/profile_study.py study --workers 3 \
        --profile extended --max-new-substations 2 --out study_extended_2.json
    
  • Dickert LV networks: uv run python -m gridforge.case_study.dickert_lv_network_script, and the notebook dickert_lv_network.ipynb, on networks that pandapower builds. They need igraph, which the development environment provides.

  • SimBench: uv run python gridforge/case_study/simbench_network_test_case.py, from any directory, on a SimBench LV network (from the simbench package of the development environment), without and with 25 % of flexibility. It writes gridforge/case_study/test_case_results.csv, next to the script, which the notebook test_case_visualisation.ipynb plots; --out writes the CSV file elsewhere (the notebook then needs that path in its RESULTS).

The notebooks run in the environment of the notebooks group: uv run --group notebooks jupyter notebook gridforge/case_study.