{"id":17324298,"url":"https://github.com/georgkordowich/diffpssi","last_synced_at":"2025-04-14T16:43:11.468Z","repository":{"id":209687452,"uuid":"724686253","full_name":"georgkordowich/diffpssi","owner":"georgkordowich","description":"A Python based framework for differentiable power system simulation and dynamic optimization","archived":false,"fork":false,"pushed_at":"2024-09-13T15:45:54.000Z","size":5145,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T17:59:34.929Z","etag":null,"topics":["automatic-differentiation","differentiable-simulation","optimisation","power-system-dynamics","power-system-simulation","powerflow","python","pytorch","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/georgkordowich.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-28T15:32:05.000Z","updated_at":"2024-10-14T08:08:04.000Z","dependencies_parsed_at":"2024-09-14T05:09:10.572Z","dependency_job_id":"8d309a17-3cbf-4b20-9e0c-ee1d150efaba","html_url":"https://github.com/georgkordowich/diffpssi","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.33333333333333337","last_synced_commit":"9f113d0641cfda812154fd3031e4651daffb2448"},"previous_names":["georgkordowich/psipsy","georgkordowich/diffpssi"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgkordowich%2Fdiffpssi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgkordowich%2Fdiffpssi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgkordowich%2Fdiffpssi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgkordowich%2Fdiffpssi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georgkordowich","download_url":"https://codeload.github.com/georgkordowich/diffpssi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240122602,"owners_count":19751144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-differentiation","differentiable-simulation","optimisation","power-system-dynamics","power-system-simulation","powerflow","python","pytorch","simulation"],"created_at":"2024-10-15T14:10:10.794Z","updated_at":"2025-02-25T17:31:19.548Z","avatar_url":"https://github.com/georgkordowich.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DiffPSSi: A Framework for Differentiable Power System Simulations\n## Quickstart\n1. Clone the repository:\n   ```\n   git clone git@github.com:georgkordowich/diffpssi.git\n   ```\n2. Install required packages:\n    ```\n    pip install -r requirements.txt\n    ```\n3. Run one of the example simulations, e.g. the IBB model simulation:\n    ```\n    python ibb_sim.py\n    ```\n\n## Overview\nDiffPSSi contains a framework designed for simulating and optimizing the dynamic behavior \nof power systems. The framework has two main benefits: (I) Serve as a modular and relatively efficient dynamic \npower system simulation over which users have full control for research and educational purposes. (II) Enable \nthe use of automatic differentiation for dynamic power system simulations. Effectively, this allows for the \ncalculation of gradients of all simulation parameters with respect to a desired output of the simulation. \nThis is useful for parameter optimization or identification or integration of neural networks into the simulation.\n\nIt includes detailed models of various power system components such as synchronous machines, \nexciters, governors, and power system stabilizers. The toolkit is built in Python and leverages the power of \nlibraries like numpy efficient computation, and torch for automatic differentiation.\n\nThe code is strongly based on [this](https://github.com/hallvar-h/DynPSSimPy) repository, but required a rewrite to \nenable the gradient calculation for optimization purposes. The code is still under development and will be extended \nin the future.\n\n**Note: This repository is still under development and will be extended in the future. Use at your own risk.**\n\n## Features\n- **Inherently Parallel Implementation:** A unique and important feature of this simulation framework, as it allows the execution of multiple simulations in parallel by using vectors of parameters for every element.\n- **Dynamic Simulation:** Allows for detailed dynamic simulations of power systems, including interactions between various components.\n- **Extensible Model Library:** Contains models of AVRs, governors, stabilizers, static models like lines, loads, transformers, and more.\n- **Backend Flexibility:** Choose between `torch` and `numpy` as backend for computations.\n- **Solver Options:** Includes Euler and Runge Kutta methods for numerical integration.\n\n## Installation\nDiffPSSi is tested with Python 3.9. To install the required packages, run the following command:\n```\npip install -r requirements.txt\n```\nDiffPSSi is also released as a package on PyPI. To install the package, run the following command:\n```\npip install diffpssi\n```\nThe package is still under development and might not be up to date with the latest version in this repository.\n\n\n## Usage and Examples\nDetailed usage instructions and examples can be found in the `examples` directory. \n\nGenerally, there are two options to create a simulation. One option is to create the model as a dictionary and pass it \nto the simulation. This is the recommended way. For an example, check out \nthe IBB model simulation example under `examples/models/ibb_model/ibb_sim.py` and the corresponding model \nin `examples/models/ibb_model.py`.\n\nThe other option is to create the model manually in the simulation file. This can be seen in the example under\n`examples/models/ibb_model/ibb_sim_manual.py`. For this option, first a simulation must be created and afterward,\nbusses, generators, and lines can be added to the simulation. The following code snippet shows how to create\na simulation and add busses, generators, and lines to it.\n```python\nsim = Pss(parallel_sims=parallel_sims,\n          sim_time=10,\n          time_step=0.005,\n          solver='heun',\n          )\n\nsim.fn = 60\nsim.base_mva = 2200\nsim.base_voltage = 24\n\nsim.add_bus(Bus(name='Bus 0', v_n=24))\nsim.add_bus(Bus(name='Bus 1', v_n=24))\n\nsim.add_line(Line(name='L1', from_bus='Bus 0', to_bus='Bus 1', length=1, s_n=2200, v_n=24, unit='p.u.',\n                  r=0, x=0.65, b=0, s_n_sys=2200, v_n_sys=24))\n\nsim.add_generator(SynchMachine(name='IBB', bus='Bus 0', s_n=22000, v_n=24, p=-1998, v=0.995, h=3.5e7, d=0,\n                               x_d=1.81, x_q=1.76, x_d_t=0.3, x_q_t=0.65, x_d_st=0.23, x_q_st=0.23, t_d0_t=8.0,\n                               t_q0_t=1, t_d0_st=0.03, t_q0_st=0.07, f_n_sys=60, s_n_sys=2200, v_n_sys=24))\nsim.add_generator(SynchMachine(name='Gen 1', bus='Bus 1', s_n=2200, v_n=24, p=1998, v=1, h=3.5, d=0, x_d=1.81,\n                               x_q=1.76, x_d_t=0.3, x_q_t=0.65, x_d_st=0.23, x_q_st=0.23, t_d0_t=8.0, t_q0_t=1,\n                               t_d0_st=0.03, t_q0_st=0.07, f_n_sys=60, s_n_sys=2200, v_n_sys=24))\n\nsim.set_slack_bus('Bus 0')\n```\n\nOnce the model is defined, you can run a simulation. One unique feature of this framework is that you can define\nthe number of parallel simulations to run. This is useful for parameter optimization, where you can run multiple\nsimulations in parallel to speed up the process. It is also possible to add events to the simulation, such as\na short circuit event.\n```python\nsim = mdl.get_model(parallel_sims)\nsim.add_sc_event(1, 1.05, 'Bus 1')\nsim.set_record_function(record_desired_parameters)\n\n# Run the simulation. Recorder format shall be [batch, timestep, value]\nt, recorder = sim.run()\n``` \n\nTo acquire and record data during the simulation, you can define a record function. This function is called\nat every time step and can be used to record any desired parameters. The function shall return a list of\ndesired parameters, which will be recorded during the simulation. The recorder format shall be `[batch, timestep, value]`.\nBy using this function during the simulation, parameters can be plotted afterward.\n```python\ndef record_desired_parameters(simulation):\n    # Record the desired parameters\n    record_list = [\n        simulation.busses[1].models[0].omega.real,\n        simulation.busses[1].models[0].e_q_st.real,\n        simulation.busses[1].models[0].e_d_st.real,\n    ]\n    return record_list\n\n# Plot the results\nplt.figure()\nfor i in range(len(recorder[0, 0, :])):\n    plt.subplot(len(recorder[0, 0, :]), 1, i + 1)\n    plt.plot(t, recorder[0, :, i].real)\n    plt.ylabel('Parameter {}'.format(i))\n    plt.xlabel('Time [s]')\nplt.show()\n```\n\n\n\n## Documentation\n\nFor an introductory explanation of how dynamic power system simulations work in principle,\nrefer to the article: [\"Watts Up with Dynamic Power System Simulations\"](https://medium.com/@georg.kordowich/watts-up-with-dynamic-power-system-simulations-c0f16fc99769).\n\n## Directory Structure\n\n- `models`: Contains example models.\n- `optimization_lib`: Includes optimizers and tools for gradient computation.\n- `power_sim_lib`: Core library with various submodules:\n  - `models`: Models for AVRs, governors, stabilizers, etc.\n  - `load_flow`: Tools for load flow analysis.\n  - `simulator`: The core simulation class.\n  - `solvers`: Numerical solvers for integration.\n\n## Contact\n[Contact Information](https://www.ees.tf.fau.de/person/georg-kordowich/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgkordowich%2Fdiffpssi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgkordowich%2Fdiffpssi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgkordowich%2Fdiffpssi/lists"}