Skip to main content

A high-performance power system analysis library

Project description

RustPower

Crates.io Docs.rs CI RustPower is a cutting-edge power flow calculation library written in Rust, specifically designed for steady-state analysis of electrical power systems. With the introduction of ECS-based architecture in version 0.2.0, RustPower offers unparalleled modularity and extensibility.


What's New in 0.5.0

  • Massive Performance Breakthrough:
    • 1.6x faster than LightSim2Grid (C++ Native) on PEGASE 9241 grid.
    • 3.5x faster than LightSim2Grid on IEEE 118 grid.
  • KLU Refactor Integration: Implemented klu_l_refactor support, bypassing expensive symbolic analysis and pivoting for iterations 2-5 of the NR process and subsequent time-series steps.
  • Zero-Allocation Hot Path: Optimized the core Newton-Raphson loop to eliminate all heap allocations (Vec clones) during iterations via unsafe pointer passing.
  • Bevy 0.19: Rustpower 0.5 deps on Bevy 0.19, which can iterate ECS archetype tables with true SIMD parallelism.

What's New in 0.4.1

  • Jacobian Optimization Backport: Backported the new Jacobian matrix formation from 0.5.0, resulting in a 20-40% speed-up per Newton-Raphson iteration.
  • Upgraded Archive System: Updated bevy_archive to 0.3.0 for enhanced ECS state persistence and case file management.

What's New in 0.3.0

  • New Solvers:
    faer: A highly efficient and scalable solver for large-scale power systems.
  • Inital support for native ECS archive files
  • Initali support for time-series simulations

What's New in 0.2.0

  • World's First ECS-Based Power Flow Solver:
    RustPower now adopts the Entity-Component-System (ECS) architecture using Bevy, enabling modular design and extensibility for domain-specific applications such as:

    • Time-series simulations.
    • Real-time monitoring.
    • Custom plugin development.
      The legacy PFNetwork is now deprecated but remains available as a demo for the basic Newton-Raphson solver.
  • Post-Processing Trait:
    Added a flexible post-processing trait to manage simulation results, allowing users to handle data as if working with a dataframe. This demonstrates Rust's compositional design philosophy and makes ECS highly effective for handling large datasets.

  • Experimental Switch Handling:
    Introduced two optional methods for modeling switch elements:

    1. Admittance-Based Method: Adjusts admittance matrices.
    2. Node-Merging Method: Merges connected nodes for simplified modeling.
      These are implemented as plugins and can be enabled as needed.

Key Features

  • High-performance power flow computation with Newton-Raphson.
  • Modular and extensible design using ECS for future-proof applications.
  • Support for pandapower JSON network files (with experimental CSV support).
  • Handles external grid nodes, transformers, and switch elements.
  • Includes both RSparse and KLU solvers (KLU requires SUITESPARSE_DIR on Windows).

Performance Comparison

RustPower is designed for extreme performance and memory efficiency. Below is a comparison between established industry standards and RustPower (all using the KLU solver where applicable, tested on Intel i7 10700K 4.7GHz with 32GB DDR4 3000 MHz).

Core Solve Time (Newton-Raphson)

Case Pandapower 3 (Default) LightSim2Grid (Native KLU) RustPower (KLU) Speedup vs Pandapower
IEEE 39 38.9 ms 0.12 ms 0.04 ms ~970x
IEEE 118 42.8 ms 0.35 ms 0.10 ms ~420x
PEGASE 9241 145.5 ms 51.2 ms 30.5 ms ~4.8x

Performance Comparison Note: For smaller grids like IEEE 39/118, RustPower is nearly 1000x faster than traditional Python-based tools and 3x faster than optimized C++ implementations.

Key Advantages

  • Extreme Memory Efficiency: For the 9241-node case, RustPower peaks at only ~34 MB of memory, while Python-based environments typically require 500+ MB. This 15x reduction enables running massive parallel simulations (e.g., N-1 analysis, Monte-Carlo) on standard hardware or cloud/docker containers with high resource utilization.
  • Zero-Clone Solver Path: Leveraging Rust's memory safety and our ECS-based architecture, the power flow loop avoids any heap allocations during iterations.
  • Interoperability: While RustPower provides a significant speedup for core calculations, it remains friendly to the ecosystem by supporting pandapower network formats.

Advanced Features

Plugin-Based Architecture

RustPower leverages the Bevy Plugin System, allowing users to extend the solver with custom logic without modifying the core. Current official plugins include:

  • Archive Plugin: A high-performance state persistence system.
  • QLim Plugin: Automatically enforces generator reactive power limits by dynamically switching PV buses to PQ during the iteration process.
  • Switch Plugins: Optional modeling for switch elements:
    • Type A: Node-merging method (aggregates nodes for simplified modeling).
    • Type B: Admittance-based method (directly processes switch admittance).
  • Time-Series Plugin: A complex, high-level plugin for handling quasi-static time-series simulations with scheduled events.

High-Performance Data Archiving

RustPower features a unique Archive System (based on bevy_archive) that enables flexible runtime handling of any ECS structure:

  • Custom Arrow Integration: To handle complex power system structures that are difficult for standard serde, we implemented custom schema overrides. This ensures type-safe and efficient data transition.
  • Multi-Format Persistence: Seamlessly save the entire network state and results into:
    • Apache Parquet: For compressed, high-performance binary storage (ideal for large-scale time-series).
    • CSV: For easy inspection and interoperability with Excel/Pandas.

Time-Series Simulations

By combining the ECS architecture with the Archive system, RustPower can execute large-scale time-series simulations with minimal overhead. Check the examples/time_series.rs for a complete workflow.


RustPower is available on Crates.io. You can add it to your project using:

cargo add rustpower

Or by adding the following to your Cargo.toml:

[dependencies]
rustpower = "0.5.0-rc.3"

Usage Example

Python API (Recommended for Data Science)

import rustpower as rp

# Load a network and solve
grid = rp.PowerGrid("cases/pegase9241/data.zip")
report = grid.solve()

if report:
    print(f"Converged in {report.iterations} iterations")
    print(grid.res_bus.head())

# Fast parameter updates
load = grid.load(bus=10)
load.p_mw = 100.0
grid.solve() # Runs an incremental solve (fast!)

Basic Rust ECS Example

use rustpower::{io::pandapower::*, prelude::*};
use ecs::post_processing::PostProcessing; // for print bus results

fn main() {
    let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let zipfile = format!("{}/cases/pegase9241/data.zip", dir);
    let net = load_csv_zip(&zipfile).unwrap();

    // Initialize the ECS application with plugins
    let mut pf_net = default_app();

    // Register the power network as a resource
    pf_net.world_mut().insert_resource(PPNetwork(net));
    pf_net.update(); // Initializes the data for the first run

    // Retrieve results
    let results = pf_net.world().get_resource::<PowerFlowResult>().unwrap();
    assert!(results.converged);
    println!("Converged in {} iterations", results.iterations);

    // Post-process and print results
    pf_net.post_process();
    pf_net.print_res_bus();
}

For more examples, check the examples and cases folder.


License

This project is licensed under the MPLv2 License. See the LICENSE file for more details.


Contributions

Contributions are welcome! Feel free to open an issue or submit a pull request to help improve the library.


Authors

  • Tianshi Cheng

Acknowledgements

This project draws inspiration from:

Special thanks to:
T. Cheng, T. Duan, and V. Dinavahi, "ECS-Grid: Data-Oriented Real-Time Simulation Platform for Cyber-Physical Power Systems," IEEE Transactions on Industrial Informatics, vol. 19, no. 11, pp. 11128-11138, 2023.

Although ECS-Grid is a more complex electromagnetic transient (EMT) simulation system, its design philosophy and methodologies greatly influenced the development of this steady-state power flow solver.

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.

rustpower-0.5.0-cp310-abi3-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

rustpower-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

File details

Details for the file rustpower-0.5.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rustpower-0.5.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for rustpower-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8ca0b21c593e0d2c461ef37b776031a550ccdb27fe77d9c023fed74e46c414d7
MD5 9f8b3b4487dd7f4fb656727e41e4e655
BLAKE2b-256 83772fceea550416802c737745e7954303e7fc30fb35f7690eb86ccbef398b82

See more details on using hashes here.

File details

Details for the file rustpower-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rustpower-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c00e327d91073d9fdd55ded0bf8908f4879c735f804428b836a53c10031dfd4
MD5 977c63ae6f3b18b1441efee46a499738
BLAKE2b-256 ca2e2d5d6921d937fb9c9e38aef2a5ead33bb868ec07f939237cb4e49b04f452

See more details on using hashes here.

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