Optimal Power Flow (OPF) in Electrisim — pandapower tutorial model

Symbolic network diagram for power flow and OPF documentation

This walk-through follows the classic four-bus example from the pandapower tutorial opf_basic.ipynb: one 220/110 kV transformer, a triangular 110 kV loop, loads, an external grid, and two controllable generators with polynomial (poly_cost) objectives. Electrisim uses the same pandapower OPF stack (runopp / rundcopp) when you run analysis from the app.

1. Download the import script

Save the ready-made network builder (same topology and loss-minimization costs as the notebook's first OPF setup):

The file defines only net and cost rows; it does not call runopp, so the backend can convert the model to a diagram even if a solver is unavailable during import. Optional commented blocks show how to apply differentiated generator costs or a transformer loading limit, matching later sections of the notebook.

2. Import into Electrisim

In the diagram editor, use File → Import from → Device... (or open from device), select the .py file, and confirm. The app sends the script to the backend, executes it in an environment where pandapower is available as pp, and expects a variable named net. The returned model is placed on the canvas (same pipeline as other pandapower imports). See also Importing Network Models in the documentation.

3. Run Optimal Power Flow

Open Simulate → Optimal Power Flow.... In the dialog, choose AC Optimal Power Flow (runopp) for parity with the notebook (or DC OPF if you are experimenting). The tutorial notebook tightens the OPF equality tolerance with delta=1e-16; you can set Delta (Convergence Tolerance) to 1e-16 in the dialog for the closest match.

After a successful run, review generator dispatch, branch flows, and transformer loading in the OPF results view. To reproduce the notebook's constrained-transformer case, edit the transformer on the diagram (or uncomment the relevant lines in the script before re-import) so max_loading_percent is 50, then run OPF again.

What the objective represents

With equal linear marginal costs on the external grid and both generators, pandapower minimizes total active-power procurement at those buses, which in this topology corresponds to loss-oriented dispatch (see the notebook's "Loss Minimization" section). Changing the cp1_eur_per_mw coefficients reroutes dispatch toward cheaper sources; the optional comments in the download mirror those experiments.

References

Run pandapower OPF in the browser at app.electrisim.com after importing the script above.

Try Electrisim Pro for $5/month

Run pandapower & OpenDSS load flow, short-circuit, OPF and harmonic studies in your browser — cancel anytime, no setup fees.

Subscribe Secure via Stripe · 1-click cancel

Copyright @2026 Electrisim. All Rights Reserved by Electrisim