Installation#

GridForge requires Python 3.12 or later and is managed with uv. Install it from source:

git clone https://git.persee.minesparis.psl.eu/energy-alternatives/gridforge.git
cd gridforge
uv sync

uv sync creates .venv from uv.lock, including the development tools. Run commands through it with uv run, for example uv run pytest gridforge/tests.

Optional dependencies are installed on request:

uv sync --extra roseau --extra opendss  # Roseau and OpenDSS libraries
uv sync --group docs                    # Sphinx documentation
uv sync --group notebooks               # Jupyter, for the case-study notebooks

To build the documentation:

uv run --group docs sphinx-build -b html docs/source docs/build/html

Data#

The MV/LV case study runs on 150 MV/LV feeders that are not in the repository. Fetch them once, from a clone:

uv run python -m gridforge.data fetch

or, where gridforge is installed with pip, python -m gridforge.data fetch; in Python, gridforge.data.fetch_feeders(). The command downloads one archive of 10 MB (94 MB once extracted) from the permanent link of the dataset on data.gouv.fr, checks it against the SHA-256 pinned in gridforge, extracts only its 150 networks/*.json files, checks each against the SHA256SUMS of the archive, and moves each into place once checked, so that an error leaves no partial file. When the 150 files are there and unchanged, it downloads nothing. When any is missing, it downloads the whole archive again, and writes only the missing files; the others are left as they are. A file of version 1 of the feeders, which gridforge 0.3.0 used (see Versions of the feeders), is replaced by that of version 2 as a missing file is written, without --replace: a fetch upgrades a directory of version 1, and says how many files it replaced. A file that differs from the published ones of both versions is an error, before any download, unless --replace is given, which replaces it. A fetch that was killed can leave a directory .gridforge-fetch-* in the directory of the feeders: the next fetch removes those older than a day. --dest DIR writes elsewhere, and --url file:///path/to/archive.tar.xz installs from a copy of the archive, for a machine without access to data.gouv.fr. python -m gridforge.data where prints where gridforge looks and how many of the feeders it finds there, with the fetch command when some are missing.

gridforge looks for the feeders, and gridforge.data_path["pandapower"] points, to the first of:

  1. the directory named by the environment variable GRIDFORGE_FEEDER_DIR;

  2. gridforge/data/pandapower of a source checkout, if it holds feeder files besides the two of the repository (for instance after fetch --dest gridforge/data/pandapower). The package is in a source checkout, or an editable install of one, when pyproject.toml is next to its directory; an installed package never is, and the files put in its data/pandapower for gridforge 0.3.0 are no longer used (where says so);

  3. the user’s data directory, $XDG_DATA_HOME/gridforge/pandapower, by default ~/.local/share/gridforge/pandapower (%LOCALAPPDATA%\gridforge\pandapower on Windows), where fetch writes, whether it exists yet or not.

data_path is resolved once, when gridforge is imported, while gridforge.data.feeder_dir() reads GRIDFORGE_FEEDER_DIR at each call: set the variable before importing gridforge. A relative value is resolved against the working directory at the time it is read. The case studies and the benchmarks that find no feeder there say so and give the fetch command. They also check the feeders they find against the checksums that gridforge pins (gridforge.data.check_feeders(), as where does), since a file of version 1, or one changed, gives other results than the study: mv_lv_feeder.load_network loads such a file with a warning, once a file, and the case study warns before its runs; benchmarks/profile_study.py, which makes the reference figures, refuses it, and refuses a directory that lacks some of the 150 when it runs them all, unless --allow-other-data is given, and records in its output the version of the data and the digest of its checksums ("data"). After upgrading from gridforge 0.3.0, run python -m gridforge.data fetch to replace the files of version 1. The tests do not use data_path: they read the two feeders of the repository from the checkout.

Provenance and licence#

The feeders are those of the dataset Départs HTA représentatifs pour l’analyse des réseaux de distribution Français, published on data.gouv.fr by the author of gridforge under the Licence Ouverte / Open Licence 2.0, which allows their reuse and redistribution, with attribution (the source and the date of its last update). As the dataset describes them, they were built from open data (the network routes published by Agence ORE, local energy consumption data, and the building footprints of the IGN BD TOPO), and chosen by clustering to be representative of the distribution networks across France.

The dataset holds them in the format of Roseau Load Flow (departs-hta-representatifs-roseau-v012.zip), with a report on their selection, and in pandapower format, in the two versions below. The pandapower files have the names of the Roseau ones and the same numbers of buses, lines, transformers and loads, except 84_MVFeeder4049, repaired to be read by pandapower 3.2 and described with the line types of the other feeders (#45, #54), which has 486 loads against 594. In all: 90,020 buses, 84,220 lines, 5,500 transformers of 20/0.4 kV and 147,896 loads, balanced, with loads of constant power, on a base of 100 MVA (sn_mva); the case study multiplies the loads by 2.5 as it reads them. The LISEZMOI.md of each archive describes its files and lists their known limits.

Versions of the feeders#

  • Version 1 (departs-hta-representatifs-pandapower-gridforge-0.3.0.tar.xz) is the files exactly as gridforge 0.3.0 uses them. It stays published, to reproduce the results of 0.3.0, and pandapower-feeders-v1.sha256 holds its checksums.

  • Version 2 (departs-hta-representatifs-pandapower-gridforge-v2.tar.xz, which fetch downloads) is version 1 with two cells changed in each file, on the slack bus, two columns removed from one, and nothing else (#14). scripts/repair_feeders.py of the repository makes it from version 1, byte for byte, and checks that a comparison of the two versions read by pandapower, every table, column and cell, finds no other difference:

    • the closed bus-bus switch at the head of each feeder, between the bus of the external grid (MVVoltage_source) and the first MV bus, has z_ohm = 0 instead of 0.1 Ω, so that pandapower fuses the two buses. The switch is ideal in the Roseau source (it has no impedance); the 0.1 Ω came from the conversion to pandapower, and was a branch of 0.1 Ω in series with every feeder. At the load of the case study (2.5 times that of the files), the voltages rise by 0.0019 p.u. at the median of the feeders and 0.012 p.u. at most, and the buses under their voltage limit at the start go from 6,967 to 6,228;

    • the slack bus has the coordinates of the first MV bus, to which it is connected, instead of [nan, nan], which is not JSON, and which pandapower 3.5 refuses to read. The Roseau source gives the slack bus no coordinates. gridforge’s plots put it at the first MV bus already, as they could not read those coordinates;

    • in 84_MVFeeder4049 only, the load columns const_z_percent and const_i_percent are removed. They are the names of pandapower before 3.0 for the shares of constant impedance and current, which the repair of that file (#45) left beside those of pandapower 3 (const_{z,i}_{p,q}_percent), and they equal them (all 0). The power flow of pandapower 3.2 ignores them; pandapower 3.5 renames them to the names of pandapower 3, which are taken, and refuses the file.

    pandapower 3.2.2, which gridforge requires, reads and solves the 150 feeders of both versions. pandapower 3.5.6 reads and solves those of version 2, with the same results (to 1e-11 p.u.), and refuses all those of version 1.

Model of the feeders#

The feeders are balanced (one phase stands for three), and their loads draw a constant power. Their loads have no rated power (sn_mva is empty, as in the loads that pandapower creates by default), which the power flow does not use.

1,626 loads, on 143 feeders, have the type delta. They are exactly the loads of the Roseau source connected without neutral (phases abc), under the same names: the label is that of the source, and is kept. In a balanced power flow of constant-power loads, as pandapower’s and gridforge’s, it changes nothing. An engine or a converter that cannot take delta loads (that of power-grid-model refuses them) has to map them itself, for instance to wye loads of the same power, which gives the same balanced results; a four-wire or unbalanced model (#16) has to connect them between phases. 84_MVFeeder4049 has no load of type delta: its 8 Roseau loads without neutral are among the 108 that its repair (#45) left out. In that feeder, four names are each shared by two loads; the MV/LV case study makes them unique as it reads the feeder (mv_lv_feeder.make_shared_names_unique).

What is in git#

gridforge/data/ holds the code of the fetch, the pinned checksums of the 150 files of version 2 (pandapower-feeders.sha256) and of version 1 (pandapower-feeders-v1.sha256), and two of the feeders, pandapower/52_MVFeeder1118.json and pandapower/84_MVFeeder4049.json, identical to those of the archive of version 2, which the tests read from the checkout. They are under the licence of the dataset, not the MIT licence of the code. The wheel holds no feeder. Fetched feeders put in gridforge/data/pandapower are ignored by git. scripts/repair_feeders.py makes version 2 from version 1 and writes its archive.

Installing from PyPI#

The PyPI distribution is distgridforge. Its import name is gridforge:

pip install distgridforge

The wheel holds no feeder: fetch them with python -m gridforge.data fetch (see Data) to run the MV/LV case study.

Do not run pip install gridforge. The PyPI project named gridforge is an unrelated table-formatting library that provides the same import name, so the two cannot be installed in one environment, and that command installs the wrong package.

Dependencies#

GridForge depends on the following packages:

  • pandas

  • numpy

  • scipy

  • matplotlib

  • networkx

  • pandapower (for the default power flow engine)

  • numba

  • pyyaml

  • folium

  • shapely