Skip to main content

AC/DC power flow solver for large-scale transmission networks

Project description

surge-py

Python bindings for Surge.

surge-py provides the curated Python interface to Surge, a Rust-native power systems analysis engine. The package surface is intentionally small at the root and uses explicit namespaces for specialist workflows such as transfer studies, prepared contingency studies, batch runs, and advanced power-flow methods.

Installation

# Distribution name declared in pyproject metadata
pip install surge-py

# From source (requires Rust toolchain + maturin)
cd src/surge-py
pip install maturin
maturin develop --release

When surge-py is built with COPT_HOME pointing at a COPT 8.x install, the wheel bundles the Surge COPT NLP shim and the surge package auto-configures SURGE_COPT_NLP_SHIM_PATH at import time. End users still need a working COPT runtime installation and license to run nlp_solver="copt", but they do not need to build a separate shim by hand.

Source builds keep optional commercial backends runtime-loaded. If you want the build to fail unless the packaged COPT NLP shim is bundled, require it explicitly:

COPT_HOME=/opt/copt80 SURGE_PY_REQUIRE_COPT_NLP_SHIM=1 maturin develop --release

System dependencies (build from source)

  • Rust stable toolchain
  • libsuitesparse-dev (KLU sparse solver)
  • libhighs-dev (HiGHS LP solver for OPF — install via system package manager)
  • coinor-libipopt-dev (optional, open-source AC-OPF backend — install via system package manager)
  • COPT 8.x install + license (optional, commercial AC-OPF backend)

Note: pip install highspy and pip install cyipopt do not provide the C shared libraries Surge needs. Both HiGHS and Ipopt must be installed via your system package manager (brew install highs ipopt / apt install libhighs-dev coinor-libipopt-dev).

Quick Start

import surge

# Load a MATPOWER/PSS-E/CIM case
net = surge.load("case118.m")
print(f"{net.n_buses} buses, {net.n_branches} branches")

# AC power flow (Newton-Raphson)
sol = surge.solve_ac_pf(net)
print(f"Converged: {sol.converged}, max mismatch: {sol.max_mismatch:.2e}")

# Results as pandas DataFrame when pandas is installed
df = sol.to_dataframe()
print(df[["bus_id", "vm_pu", "va_deg"]].head())

# DC optimal power flow
opf = surge.solve_dc_opf(net)
print(f"Total cost: ${opf.total_cost:.2f}/hr")
print(f"LMPs: {opf.lmp}")  # numpy array

# N-1 contingency analysis
ca = surge.analyze_n1_branch(net)
print(f"{ca.n_with_violations} contingencies with violations")

to_dataframe() returns a pandas DataFrame when pandas is installed and a plain column dictionary otherwise.

The repository metadata declares the distribution name surge-py and the import module surge. Publication status is a release-process question, not an unresolved naming question.

Pandas Network Construction

For pandas-native workflows, build a network directly from DataFrames:

import pandas as pd
import surge

buses = pd.DataFrame(
    [
        {"number": 1, "type": "Slack", "base_kv": 230.0, "name": "SWING"},
        {"number": 2, "type": "PV", "base_kv": 230.0, "name": "GEN"},
        {"number": 3, "type": "PQ", "base_kv": 230.0, "name": "LOAD", "pd_mw": 90.0, "qd_mvar": 30.0},
    ]
)
branches = pd.DataFrame(
    [
        {"from_bus": 1, "to_bus": 2, "r": 0.01, "x": 0.10, "rate_a": 250.0},
        {"from_bus": 2, "to_bus": 3, "r": 0.01, "x": 0.08, "rate_a": 250.0},
        {"from_bus": 1, "to_bus": 3, "r": 0.02, "x": 0.12, "rate_a": 250.0},
    ]
)
generators = pd.DataFrame(
    [
        {"bus": 1, "pg": 100.0, "pmax": 150.0, "qmax": 80.0, "qmin": -80.0},
        {"bus": 2, "pg": 40.0, "pmax": 80.0, "vs": 1.02},
    ]
)

net = surge.construction.from_dataframes(buses, branches, generators, name="pandas-demo")
sol = surge.solve_ac_pf(net)
print(sol.converged)

surge.construction.from_dataframes(...) follows a MATPOWER-like schema:

  • buses: required number, base_kv; optional type, name, pd_mw, qd_mvar, vm_pu, va_deg
  • branches: required from_bus, to_bus, r, x; optional b, rate_a, tap, shift, circuit
  • generators: required bus, pg; optional pmax, pmin, qmax, qmin, vs, machine_id

This helper is intentionally narrow for 0.1. It does not ingest separate load tables, shunts, HVDC, topology assets, or market objects. See docs/tutorials/09-pandas-construction.md for the full schema and error semantics.

Subsystems

surge.subsystem.Subsystem gives you a named, reusable bus-set view over a network for area/zone, voltage-level, or explicit-bus filtering:

import surge

net = surge.case118()
extra_high = surge.subsystem.Subsystem(net, name="ehv", kv_min=345.0)
area_one_load = surge.subsystem.Subsystem(net, areas=[1], bus_type="PQ")

print(extra_high.bus_numbers[:5])
print(area_one_load.total_load_mw)
print(area_one_load.tie_branches[:3])

Subsystem filters intersect. branches includes only lines whose endpoints are both inside the bus set, while tie_branches includes exactly one-in / one-out connections. See docs/tutorials/10-subsystems.md for examples.

Prepared DC Studies

For repeated DC power flow and sensitivity work on one network, prepare the DC study once and reuse it. The prepared study supports both single-island and multi-island AC networks:

import surge

net = surge.load("case118.m")
dc = surge.dc.prepare_study(net)

monitored = [
    surge.dc.BranchKey(net.branches[i].from_bus, net.branches[i].to_bus, net.branches[i].circuit)
    for i in (0, 3, 7)
]
outages = [
    surge.dc.BranchKey(net.branches[i].from_bus, net.branches[i].to_bus, net.branches[i].circuit)
    for i in (1, 5)
]

pf = dc.solve_pf()
ptdf = dc.compute_ptdf(
    surge.dc.PtdfRequest(monitored_branches=monitored, bus_numbers=[1, 5, 10])
)
lodf = dc.compute_lodf(
    surge.dc.LodfRequest(monitored_branches=monitored, outage_branches=outages)
)
workflow = dc.run_analysis(
    surge.dc.DcAnalysisRequest(
        monitored_branches=monitored,
        lodf_outage_branches=outages,
        n2_outage_pairs=[
            (monitored[0], monitored[1]),
            (monitored[1], monitored[0]),
        ],
    )
)

Prepared Transfer Studies

For repeated transfer work on one network, prepare the transfer study once and reuse it across ATC, AFC, and multi-interface runs:

import surge

net = surge.load("case118.m")
study = surge.transfer.prepare_transfer_study(net)

path = surge.transfer.TransferPath("north_to_south", [8], [1])
atc = study.compute_nerc_atc(
    path,
    surge.transfer.AtcOptions(
        monitored_branches=list(range(net.n_branches)),
        contingency_branches=list(range(net.n_branches)),
    ),
)
afc = study.compute_afc(
    path,
    [surge.transfer.Flowgate("fg0", 10, 500.0)],
)
multi = study.compute_multi_transfer(
    [
        surge.transfer.TransferPath("north", [8], [1]),
        surge.transfer.TransferPath("west", [10], [2]),
    ],
    weights=[1.0, 1.5],
)

For repeated contingency screening on one network, build a study object once, run it on demand, and reuse the latest analysis for follow-on corrective redispatch. The same ContingencyStudy surface is used for branch N-1, generator N-1, and branch N-2:

import surge

net = surge.load("case118.m")
n1 = surge.contingency.n1_branch_study(net, surge.ContingencyOptions(screening="lodf"))
gen_n1 = surge.contingency.n1_generator_study(net, surge.ContingencyOptions(screening="lodf"))
n2 = surge.contingency.n2_branch_study(net, surge.ContingencyOptions(screening="lodf", top_k=100))

analysis = n1.analyze()
scrd = n1.solve_corrective_dispatch()

Supported Entry Points

Solver Function Description
Newton-Raphson solve_ac_pf() Full AC power flow (KLU sparse)
Fast Decoupled surge.powerflow.solve_fdpf() BX/XB decoupled AC power flow
DC Power Flow solve_dc_pf() Linear B-theta approximation
HVDC Power Flow solve_hvdc() Coupled AC/DC HVDC power flow with automatic topology-aware method selection
DC-OPF solve_dc_opf() Optimal dispatch via LP (HiGHS)
AC-OPF solve_ac_opf() Optimal dispatch via NLP (auto-detected runtime backend; COPT first, then Ipopt)
SCOPF solve_scopf() Security-constrained OPF (DC/AC, preventive/corrective)
N-1 Contingency analyze_n1_branch() Parallel contingency analysis
Contingency Study surge.contingency.n1_branch_study() Reusable branch N-1 / generator N-1 / N-2 study object family
Prepared DC Study surge.dc.prepare_study() Reusable DC power flow + sensitivity study object
DC Analysis Workflow surge.dc.run_analysis() Canonical one-call DC flow + PTDF/LODF/N-2 sensitivities
PTDF/LODF surge.dc.compute_ptdf() / surge.dc.compute_lodf() Individual sensitivity matrix entry points
Prepared Transfer Study surge.transfer.prepare_transfer_study() Reusable ATC / AFC / multi-transfer study object
NERC ATC surge.transfer.compute_nerc_atc() Canonical transfer capability entry point
GSF surge.transfer.compute_gsf() Generation shift factors
Voltage Stress surge.contingency.compute_voltage_stress() Base-case exact L-index and local Q-V proxy screening

DC power flow angle reporting can be controlled independently of slack distribution. For example:

dc = surge.solve_dc_pf(
    net,
    surge.DcPfOptions(
        participation_factors={101: 0.7, 205: 0.3},
        angle_reference="distributed_load",
    ),
)

This changes only the reported bus-angle reference frame; it does not change branch flows or how the slack mismatch is shared.

The Python package intentionally does not expose unfinished or out-of-scope study surfaces such as continuation PF, planning/compliance helpers, protection convenience layers, dynamics/ride-through workflows, state estimation, fault analysis, arc flash, GIC, or distribution solves until they have a supported package contract.

Supported File Formats

Format Read Write
MATPOWER (.m) Yes Yes
PSS/E RAW (.raw) Yes Yes
PSS/E DYR (.dyr) Yes Yes
IEEE CDF Yes
CGMES/CIM XML Yes Yes, via surge.io.cgmes.save(...)
UCTE-DEF Yes Yes
JSON Yes Yes

License

PolyForm Noncommercial 1.0.0 — free for non-commercial use. Commercial use requires a license from Amptimal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

surge_py-0.1.5-cp314-cp314-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.14Windows x86-64

surge_py-0.1.5-cp314-cp314-manylinux_2_28_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

surge_py-0.1.5-cp314-cp314-manylinux_2_28_aarch64.whl (9.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

surge_py-0.1.5-cp314-cp314-macosx_11_0_arm64.whl (8.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

surge_py-0.1.5-cp313-cp313-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.13Windows x86-64

surge_py-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

surge_py-0.1.5-cp313-cp313-manylinux_2_28_aarch64.whl (9.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

surge_py-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (8.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

surge_py-0.1.5-cp312-cp312-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.12Windows x86-64

surge_py-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

surge_py-0.1.5-cp312-cp312-manylinux_2_28_aarch64.whl (9.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

surge_py-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (8.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file surge_py-0.1.5-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: surge_py-0.1.5-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 10.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for surge_py-0.1.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b9960bbe9fa087bef53c0b86b05f25ab39c3bdc5eb147bb3cfb20e9f88cca214
MD5 9b9fc8d3e485877a3209bc280ced95d5
BLAKE2b-256 0f73c16076981be52d6b7c8bcd8094b8bd2a4117dd064f3b6d879228cb5b7f3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp314-cp314-win_amd64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f5e9bcd0e9904d14a5228e770c88e725f5f64251c5ee66bbd83131dfd172ce2
MD5 6ee3bb8a20f323fe4377aca16a797d50
BLAKE2b-256 2948eba38acd4fcb1be03e7af530a9e5f109e6fc0eb3b3a77de82a16e84d9031

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3903e8543c18cabde20c9605c5c1d4c370314c1a64ea6cc3a220ad1b6ebf4d5f
MD5 ccfc1fcb6729c82ad52b02c67a91af56
BLAKE2b-256 40cf9b0a2bf1c53811f4d7597693909fe211f6f59e40873c999c924932c82cd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp314-cp314-manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ddb1bbff6e5e2fd6fdce275bc4660ab620695b34d8dd5a36f86014ce4dfa1b7
MD5 212ed7dbbbbf5ae97b9431c2fb5a56b5
BLAKE2b-256 879952464784a6eddfea4ccf88a4796b27ec8d4dbf59a2838e15c7a97a1c41a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: surge_py-0.1.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 10.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for surge_py-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 417c5955ab8642913d97f89e8e57acb847aa9095e78e089e95c237bcb58ef76c
MD5 4777aeb4c5c06e45094b2ca6f6e4df39
BLAKE2b-256 ab2bc8ca02393fefa69bffd91711c3649418dcfed5b8b25c01fa70c6d124a0b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5eb63c33c3e7221418618d762c282c6674e67a9c595ee10dc8a8c321db5d5450
MD5 ed563b9c6b0b9d14399cf643e68056df
BLAKE2b-256 09c7ed2932f153d5f582e9062807bd0db0ea6429e0b87e94c49a81ccea918a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 24757d6aca25f09ed92737deab201c8843f866ec26b5de097e4934241737edee
MD5 1afcb4df9ca627e816ddaca060d12fe1
BLAKE2b-256 71d16d1f5a49a29799b28771ccb15838b865dcda945814f9baabeaa01521660c

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89a2c5f2619c0b6e2e0cc12ea56892eae73cd90c1dd5b01098c61097a9f96555
MD5 1462a7ffb408eef8d168d60710cad776
BLAKE2b-256 eac5887c714e8b262ba5ddb1a8e1d2fe799886b9f005a6ef8f9eecfbb66c4456

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: surge_py-0.1.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 10.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for surge_py-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ba252f62a61db08549b26c01f01f78f4e6d4ad12ff8cb6bb7410a4c12dd13d79
MD5 acf391ed33287c7a0e16e3b8512d86ee
BLAKE2b-256 10f5dc961ecdbf986539cf79a3fb4262437e6892d9513848729070b8d264a826

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3628269ecff8b148d2a0ea045907a9b63adc0991ad0a734d39d391deb57096bb
MD5 99e458569ef60e43555d2b6b9ebf3a16
BLAKE2b-256 26cdc22fef143d05e01bab9750fe77843677e751a6b8988d575d1805fb3709fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eb7929dc5a43c056b8ac2ff0f59ed2ffe99825b883b8d0ef7bca52f2d3beb092
MD5 0858f26abaafecedc683ddbaced7e327
BLAKE2b-256 99aa20b5d8087d8bee7cab0ac53f1f7b3574dd2640d088ec83e4b146bbfc80b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file surge_py-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for surge_py-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ac5a7b19a1ce81441d8f3f43a91fa5d29fc7e1201116a75c5eafabdaf48ed49
MD5 d48133c4fb9b393ade57c3347a55650b
BLAKE2b-256 c4e2e350472bcd8c6d46c41853b5b3b987d3c99f52e06752dfdcc17a5472dfdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for surge_py-0.1.5-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on amptimal/surge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page