How georgkordowich/diffpssi works
Project Type and Purpose
• DiffPSSi is a simulation framework for dynamic power systems that supports both traditional dynamic simulation and optimization using automatic differentiation.
• It is designed for research and educational purposes, enabling users to simulate power system dynamics while leveraging backends like numpy and torch for gradient computation.
• The repository includes example models (IBB, IEEE-9 bus, K2a, etc.) and components to simulate, optimize, and analyze power system behavior.
Analyzing the File Structure
• Top-level directories include:
• “examples”: Contains usage examples and example models (e.g., ibb_model, ieee_9bus, k2a) with model definitions, simulation scripts, and associated data.
• “src”: Contains the core library “diffpssi”, which has submodules like:
▪ “optimization_lib”: Includes optimizers (e.g., optimizers.py and ps_optimization.py) for gradient-based parameter optimization.
▪ “power_sim_lib”: Contains core simulation components such as simulation backend (backend.py), load flow analysis (load_flow.py), various power system models (models directory), the main simulation engine (simulator.py), and numerical solvers (solvers.py).
• “pf_util”: A utility module for performing power flow calculations.
• “tests”: Integration tests to validate simulation and optimization functionality.
• The distribution of examples with different power system models highlights that the framework is modular and supports various simulation setups.
Main Components
• Simulation Engine: Core element powering the simulation. (Found in src/diffpssi/power_sim_lib/simulator.py)
• Mathematical Solvers: Euler, Runge Kutta, and possibly custom solver implementations (in src/diffpssi/power_sim_lib/solvers.py).
• Power System Models: Abstract and concrete models for components such as exciters, governors, stabilizers, synchronous machines, etc. (located in src/diffpssi/power_sim_lib/models)
• Optimization Library: Responsible for gradient computation and parameter optimization enabled by automatic differentiation. (src/diffpssi/optimization_lib)
• Backend Selection: Choice between torch and numpy for numerical computations, enabling differentiation.
• Examples and Use Cases: Demonstrate how end-users build simulations by either passing a model dictionary or manually defining buses, generators, lines, and events.
• Testing and Utility Modules: Integration tests (in tests directory) and utilities (pf_util, tools) that support additional features and validations.
Depicting Relationships and Interactions
• A key relationship is between the simulation setup and the simulation engine. The simulation engine interacts with the model definitions (which include various power system component representations) and numerical solvers.
• The Optimization Library wraps around the simulation engine to enable gradient computations. It communicates with the simulation components to adjust parameters and records simulation outputs.
• The selection of a backend (torch or numpy) affects both the simulation and optimization layers.
• Utilities and tests ensure the integration and proper functioning of these modules.
Architectural Patterns and Design Principles
• Modularity: Notice how the repository cleanly separates simulations (simulation engine, solvers) from model specifications and optimization routines. This indicates a modular architecture that supports extensibility.
• Separation of Concerns: The framework segments responsibilities such as model definitions, simulation execution, numerical solving, and optimization.
• Extensibility: The use of dedicated modules for models (like governors, exciters, etc.) suggests that new components can easily be added.