Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# name: test-code-and-build

on:
push:
branches:
- main
- release/*
pull_request:
branches:
- main
- release/*

jobs:
pre-commit-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry==2.1.4
poetry install

- name: Run code checks
run: |
poetry check
poetry run black --diff --check src/diffpssi/ tests/
poetry run isort --check-only src/diffpssi tests
poetry run pydocstyle diffpssi tests

- name: Run tests
run: |
poetry run pytest tests/*

47 changes: 47 additions & 0 deletions .github/workflows/other_branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test Code

on:
push:
branches:
- develop
- project-init
- feature/*
- bugfix/*
- hotfix/*
pull_request:
branches:
- develop

jobs:
pre-commit-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry==2.1.4
poetry install

- name: Run code checks
run: |
poetry check
poetry run black --diff --check src/diffpssi/ tests/
poetry run isort --check-only src/diffpssi tests
poetry run pydocstyle diffpssi tests

- name: Run tests
run: |
poetry run pytest tests/*

13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# General project related exclusions
.DS_Store
.idea
*.pyc
/dist
Expand All @@ -7,3 +9,14 @@
/examples/models/ieee_9bus/data/plots
/examples/models/ibb_model/data/plots
/examples/models/k2a_manual/data/plots

# Any Python virtual environment and developing stuff
.vscode/
.mypy_cache/
.pytest_cache/
__pycache__/
.tox
.venv
venv
env
.github/copilot-instructions.md
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fail_fast: false
repos:
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort
language: system
types: [file, python]
# files: '^(src|test)/'
- id: black
name: black
entry: poetry run black
language: system
types: [file, python]
# files: '^(src|test)/'
- id: pydocstyle
name: pydocstyle
entry: poetry run pydocstyle
language: system
types: [file, python]
# files: '^(src|test)/'
# - id: pylint
# name: pylint
# entry: poetry run pylint
# language: system
# types: [file, python]
# # files: '^(src|test)/'
# - id: mypy
# name: mypy
# entry: poetry run mypy
# language: system
# types: [file, python]
# # files: '^(src|test)/'
Binary file modified examples/models/ibb_manual/data/original_data.npy
Binary file not shown.
136 changes: 96 additions & 40 deletions examples/models/ibb_manual/ibb_manual_sim.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
"""
This example shows how to manually create and simulate the IBB model.
"""
"""This example shows how to manually create and simulate the IBB model."""

import os

import numpy as np
import matplotlib.pyplot as plt
from src.diffpssi.power_sim_lib.simulator import PowerSystemSimulation as Pss
import numpy as np

from src.diffpssi.power_sim_lib.models.synchronous_machine import SynchMachine
from src.diffpssi.power_sim_lib.models.static_models import *
from src.diffpssi.power_sim_lib.models.synchronous_machine import SynchMachine
from src.diffpssi.power_sim_lib.simulator import PowerSystemSimulation as Pss


def record_desired_parameters(simulation):
"""
Records the desired parameters of the simulation.
Args:
simulation: The simulation to record the parameters from.
"""Record desired parameters from the simulation.

Returns: A list of the recorded parameters.
Args:
simulation: The simulation object.

Returns:
list: Recorded parameters.
"""
# Record the desired parameters
record_list = [
Expand All @@ -30,37 +29,94 @@ def record_desired_parameters(simulation):


def main():
"""
This function simulates the IBB model.
"""
"""Simulate das IBB-Modell und plotte die Ergebnisse."""
parallel_sims = 1

sim = Pss(parallel_sims=parallel_sims,
sim_time=10,
time_step=0.005,
solver='heun',
)
sim = Pss(
parallel_sims=parallel_sims,
sim_time=10,
time_step=0.005,
solver="heun",
)

sim.fn = 60
sim.base_mva = 2200
sim.base_voltage = 24

sim.add_bus(Bus(name='Bus 0', v_n=24))
sim.add_bus(Bus(name='Bus 1', v_n=24))

sim.add_line(Line(name='L1', from_bus='Bus 0', to_bus='Bus 1', length=1, s_n=2200, v_n=24, unit='p.u.',
r=0, x=0.65, b=0, s_n_sys=2200, v_n_sys=24))

sim.add_generator(SynchMachine(name='IBB', bus='Bus 0', s_n=22000, v_n=24, p=-1998, v=0.995, h=3.5e7, d=0,
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,
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))
sim.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,
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,
t_d0_st=0.03, t_q0_st=0.07, f_n_sys=60, s_n_sys=2200, v_n_sys=24))

sim.set_slack_bus('Bus 0')

sim.add_sc_event(1, 1.05, 'Bus 1')
sim.add_bus(Bus(name="Bus 0", v_n=24))
sim.add_bus(Bus(name="Bus 1", v_n=24))

sim.add_line(
Line(
name="L1",
from_bus="Bus 0",
to_bus="Bus 1",
length=1,
s_n=2200,
v_n=24,
unit="p.u.",
r=0,
x=0.65,
b=0,
s_n_sys=2200,
v_n_sys=24,
)
)

sim.add_generator(
SynchMachine(
name="IBB",
bus="Bus 0",
s_n=22000,
v_n=24,
p=-1998,
v=0.995,
h=3.5e7,
d=0,
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,
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,
)
)
sim.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,
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,
t_d0_st=0.03,
t_q0_st=0.07,
f_n_sys=60,
s_n_sys=2200,
v_n_sys=24,
)
)

sim.set_slack_bus("Bus 0")

sim.add_sc_event(1, 1.05, "Bus 1")
sim.set_record_function(record_desired_parameters)

# Run the simulation. Recorder format shall be [batch, timestep, value]
Expand All @@ -71,13 +127,13 @@ def main():
for i in range(len(recorder[0, 0, :])):
plt.subplot(len(recorder[0, 0, :]), 1, i + 1)
plt.plot(t, recorder[0, :, i].real)
plt.ylabel('Parameter {}'.format(i))
plt.xlabel('Time [s]')
plt.ylabel("Parameter {}".format(i))
plt.xlabel("Time [s]")
plt.show()

if os.environ.get('DIFFPSSI_TESTING') == 'True':
np.save('./data/original_data.npy', recorder[0].real)
if os.environ.get("DIFFPSSI_TESTING") == "True":
np.save("./data/original_data.npy", recorder[0].real)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Binary file modified examples/models/ibb_model/data/original_data.npy
Binary file not shown.
Loading