Skip to content

Commit b6d8365

Browse files
authored
Chore - Pre-commit (#164)
* chore: add pre-commit * chore: run pre-commit * chore: add pre-commit gh action to ci
1 parent b7efd63 commit b6d8365

File tree

85 files changed

+631
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+631
-556
lines changed

.github/workflows/pre-commit.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Pre-commit
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
pre-commit:
8+
name: Run pre-commit
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- uses: pre-commit/action@v3.0.1
16+
with:
17+
extra_args: --all-files

.github/workflows/pull_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ jobs:
1717
with:
1818
name: DocumentationHTML
1919
path: docs/_build
20-

.pre-commit-config.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
repos:
2+
3+
# Pip Audit
4+
- repo: https://github.com/pypa/pip-audit
5+
rev: v2.7.3
6+
hooks:
7+
- id: pip-audit
8+
name: pip-audit
9+
description: "Audits Python environments and dependency trees for known vulnerabilities"
10+
entry: pip-audit
11+
pass_filenames: false
12+
language: python
13+
14+
# Generic
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v4.6.0
17+
hooks:
18+
- id: end-of-file-fixer
19+
name: fix end of files
20+
description: "Ensures that a file is either empty, or ends with one newline"
21+
entry: end-of-file-fixer
22+
types: [ text ]
23+
stages: [ commit, push, manual ]
24+
language: python
25+
26+
- id: trailing-whitespace
27+
name: trim trailing whitespace
28+
description: "Trims trailing whitespace"
29+
entry: trailing-whitespace-fixer
30+
types: [ text ]
31+
stages: [ commit ]
32+
language: python
33+
34+
# TOML
35+
- repo: https://github.com/pre-commit/pre-commit-hooks
36+
rev: v4.6.0
37+
hooks:
38+
- id: check-toml
39+
name: check toml
40+
description: "Checks .toml files for parseable syntax"
41+
entry: check-toml
42+
types: [toml]
43+
language: python
44+
45+
# YAML
46+
- repo: https://github.com/pre-commit/pre-commit-hooks
47+
rev: v4.6.0
48+
hooks:
49+
- id: check-yaml
50+
name: check yaml
51+
description: "Checks .yaml files for parseable syntax"
52+
entry: check-yaml
53+
types: [ yaml ]
54+
language: python
55+
56+
# YAPF
57+
- repo: https://github.com/google/yapf
58+
rev: v0.40.2
59+
hooks:
60+
- id: yapf
61+
name: yapf
62+
description: "A formatter for Python files"
63+
entry: yapf
64+
args: [ -i ] # inplace
65+
language: python
66+
types: [ python ]
67+
additional_dependencies: [ toml ]

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"eeyore.yapf",
66
"streetsidesoftware.code-spell-checker",
77
]
8-
}
8+
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"docs/*"
1717
],
1818
"esbonio.sphinx.confDir": "${workspaceFolder}/docs/source"
19-
}
19+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
Introduction
99
------------
10-
This open-source software includes simulation models and controllers for electric machine drives and grid converter systems. The machine models include an induction machine, a synchronous reluctance machine, and a permanent-magnet synchronous machine. Various subsystem models are provided for modeling grid converter systems, such as an LCL filter connected to an inductive-resistive grid.
10+
This open-source software includes simulation models and controllers for electric machine drives and grid converter systems. The machine models include an induction machine, a synchronous reluctance machine, and a permanent-magnet synchronous machine. Various subsystem models are provided for modeling grid converter systems, such as an LCL filter connected to an inductive-resistive grid.
1111

1212
The system models are simulated in the continuous-time domain while the control algorithms run in discrete time. The default solver is the explicit Runge-Kutta method of order 5(4) from scipy.integrate.solve_ivp. Various control algorithms are provided as examples. The documentation is available here:
1313

1414
https://aalto-electric-drives.github.io/motulator/
1515

1616
Installation
1717
------------
18-
This software can be installed using pip:
18+
This software can be installed using pip:
1919

2020
```bash
2121
pip install motulator

docs/.nojekyll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

docs/source/contributing.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Contributing
44
Style Guide
55
-----------
66

7-
We follow the `Style Guide for Python Code PEP8 <https://peps.python.org/pep-0008/>`_. Furthermore, we use the `YAPF Python code formatter <https://github.com/google/yapf>`_, configured based on the PEP8 conventions in the ``pyproject.toml`` file. Public methods and classes should have proper `docstrings <https://peps.python.org/pep-0257/>`_, formatted according to the `NumPy docstring guide <https://numpydoc.readthedocs.io/en/latest/format.html>`_.
7+
We follow the `Style Guide for Python Code PEP8 <https://peps.python.org/pep-0008/>`_. Furthermore, we use the `YAPF Python code formatter <https://github.com/google/yapf>`_, configured based on the PEP8 conventions in the ``pyproject.toml`` file. Public methods and classes should have proper `docstrings <https://peps.python.org/pep-0257/>`_, formatted according to the `NumPy docstring guide <https://numpydoc.readthedocs.io/en/latest/format.html>`_.
88

9-
`Sphinx <https://www.sphinx-doc.org>`_ is used to auto-generate documentation. We use `Sphinx-Gallery <https://sphinx-gallery.github.io/stable/index.html>`_ to automatically generate the `examples <https://aalto-electric-drives.github.io/motulator/drive_examples/index.html>`_ from the scripts in the ``examples`` folder. The format of the example scripts is essential for their proper rendering in the documentation (see the existing example scripts).
9+
`Sphinx <https://www.sphinx-doc.org>`_ is used to auto-generate documentation. We use `Sphinx-Gallery <https://sphinx-gallery.github.io/stable/index.html>`_ to automatically generate the `examples <https://aalto-electric-drives.github.io/motulator/drive_examples/index.html>`_ from the scripts in the ``examples`` folder. The format of the example scripts is essential for their proper rendering in the documentation (see the existing example scripts).
1010

1111
Install Optional Dependencies
1212
-----------------------------
1313

1414
We recommend to install the ``dev`` dependencies (see also :doc:`/installation`). To enable YAPF in VS Code, you can install the `YAPF extension <https://marketplace.visualstudio.com/items?itemName=eeyore.yapf>`_. This extension will automatically format the code according when you save the file.
1515

16-
If you aim to work with the documentation, install also the ``doc`` dependencies. For previewing the documentation in VS Code, you can install the `Esbonio extension <https://marketplace.visualstudio.com/items?itemName=swyddfa.esbonio>`_. Alternatively, you can build the documentation locally using the command ``make html`` in the ``docs`` directory. The documentation will be built in the ``docs/build`` directory.
16+
If you aim to work with the documentation, install also the ``doc`` dependencies. For previewing the documentation in VS Code, you can install the `Esbonio extension <https://marketplace.visualstudio.com/items?itemName=swyddfa.esbonio>`_. Alternatively, you can build the documentation locally using the command ``make html`` in the ``docs`` directory. The documentation will be built in the ``docs/build`` directory.
1717

1818

1919
Submitting a Bug Report or a Feature Request
@@ -23,7 +23,7 @@ If you have found bugs or have feature requests, please submit them to the `issu
2323

2424
- Name and version of your operating system.
2525
- Any relevant details about your local setup, such as the Python interpreter version and installed libraries.
26-
- A short reproducible code snippet, so that anyone can reproduce the bug easily.
26+
- A short reproducible code snippet, so that anyone can reproduce the bug easily.
2727
- Try to be specific about what functions are involved and the shape of the data, especially when including a code snippet is not feasible.
2828
- Provide the full traceback to any exceptions that were raised.
2929

@@ -39,4 +39,4 @@ When contributing code, please follow this workflow:
3939

4040
Once a pull request has been created, it will be reviewed, and changes might be suggested, which you can make by simply adding new commits to your branch. After the successful review, we will merge your changes into the main repository.
4141

42-
We aim to keep the codebase clean and maintainable. Therefore, we may not be able to accept all contributions (even if they are well-written and feasible). For this reason, it is advisable to discuss possible contributions beforehand in an issue.
42+
We aim to keep the codebase clean and maintainable. Therefore, we may not be able to accept all contributions (even if they are well-written and feasible). For this reason, it is advisable to discuss possible contributions beforehand in an issue.

docs/source/control/control_system.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ Common
44
Data Flow
55
---------
66

7-
The two figures below show the structure and data flow in a typical simulation model as well as an example of the internal structure of a discrete-time control system. The text in italics refers to the default object names used in the software. In discrete-time control systems, the signals are collected into the following :class:`types.SimpleNamespace` objects:
7+
The two figures below show the structure and data flow in a typical simulation model as well as an example of the internal structure of a discrete-time control system. The text in italics refers to the default object names used in the software. In discrete-time control systems, the signals are collected into the following :class:`types.SimpleNamespace` objects:
88

9-
- The object `fbk` contains feedback signals for the controllers. These signals can be measured quantities (such as the measured DC-bus voltage `fbk.u_dc`) as well as estimated quantities (such as the estimated stator flux linkage `fbk.psi_s`).
9+
- The object `fbk` contains feedback signals for the controllers. These signals can be measured quantities (such as the measured DC-bus voltage `fbk.u_dc`) as well as estimated quantities (such as the estimated stator flux linkage `fbk.psi_s`).
1010

11-
- The object `ref` contains the reference signals, both externally provided (such as `ref.w_m` for the angular speed reference) and internally generated (such as `ref.d_c_abc` for the duty ratios).
11+
- The object `ref` contains the reference signals, both externally provided (such as `ref.w_m` for the angular speed reference) and internally generated (such as `ref.d_c_abc` for the duty ratios).
1212

1313
These objects `fbk` and `ref` may propagate through several blocks (implemented as classes in the software), which may add new signals or modify the existing one. At the end of their propagation chain, both objects `fbk` and `ref` are saved to the lists. Therefore, the most relevant internal signals of the control system are directly accessible after the simulation. Furthermore, the states and inputs of the continuous-time system model are also saved. In the post-processing stage, the saved data is converted to the NumPy arrays.
1414

1515
.. figure:: figs/overall_system.svg
1616
:width: 100%
1717
:align: center
1818
:alt: Block diagram of the control system.
19-
20-
Block diagram illustrating the structure and data flow in a typical simulation model. The lower part of the figure illustrates how the data is saved. The post-processing is done after the simulation. The internal structure of a typical control system is exemplified in the figure below.
19+
20+
Block diagram illustrating the structure and data flow in a typical simulation model. The lower part of the figure illustrates how the data is saved. The post-processing is done after the simulation. The internal structure of a typical control system is exemplified in the figure below.
2121

2222
.. figure:: figs/discrete_control_system.svg
2323
:width: 100%
2424
:align: center
2525
:alt: Block diagram of the control system.
26-
27-
Block diagram exemplifying the internal structure of a typical cascade control system. The object `ref` at the control system output should contain the sampling period `T_s` and the converter duty ratios `d_c_abc` for the carrier comparison. The observer does not necessarily exist in all control systems (or it can be replaced with, e.g., a phase-locked loop).
26+
27+
Block diagram exemplifying the internal structure of a typical cascade control system. The object `ref` at the control system output should contain the sampling period `T_s` and the converter duty ratios `d_c_abc` for the carrier comparison. The observer does not necessarily exist in all control systems (or it can be replaced with, e.g., a phase-locked loop).
2828

2929
Main Control Loop
3030
-----------------
3131

3232
A template for the main control loop is available in the base class for discrete-time control systems in :class:`motulator.common.control.ControlSystem`. The main control loop in this template has the following steps:
3333

34-
1. Get the feedback signals `fbk` for the controllers from the outputs of the continuous-time system model `mdl`. This step may contain first getting the measurements and then optionally computing the observer outputs (or otherwise manipulating the measured signals).
34+
1. Get the feedback signals `fbk` for the controllers from the outputs of the continuous-time system model `mdl`. This step may contain first getting the measurements and then optionally computing the observer outputs (or otherwise manipulating the measured signals).
3535
2. Get the reference signals `ref` and compute the controller outputs based on the feedback signals `fbk`. Cascade control systems may contain multiple controllers, where the output of the outer controller is the reference signal for the inner controller.
3636
3. Update the states of the control system for the next sampling instant.
3737
4. Save the feedback signals `fbk` and the reference signals `ref` so they can be accessed after the simulation.
@@ -54,14 +54,14 @@ The figure below shows a 2DOF PI controller with an optional feedforward term. I
5454
u &= k_\mathrm{t}r - k_\mathrm{p}y + u_\mathrm{i} + u_\mathrm{ff}
5555
:label: 2dof_pi
5656
57-
where :math:`r` is the reference signal, :math:`y` is the measured (or estimated) feedback signal, :math:`u_\mathrm{i}` is the the integral state, and :math:`u_\mathrm{ff}` is the optional feedforward signal. Furthermore, :math:`k_\mathrm{t}` is the reference-feedforward gain, :math:`k_\mathrm{p}` is the proportional gain, and :math:`k_\mathrm{i}` is the integral gain. Setting :math:`k_\mathrm{t} = k_\mathrm{p}` and :math:`u_\mathrm{ff} = 0` results in the standard PI controller. This 2DOF PI controller can also be understood as a state-feedback controller with integral action and reference feedforward [#Fra1997]_.
57+
where :math:`r` is the reference signal, :math:`y` is the measured (or estimated) feedback signal, :math:`u_\mathrm{i}` is the the integral state, and :math:`u_\mathrm{ff}` is the optional feedforward signal. Furthermore, :math:`k_\mathrm{t}` is the reference-feedforward gain, :math:`k_\mathrm{p}` is the proportional gain, and :math:`k_\mathrm{i}` is the integral gain. Setting :math:`k_\mathrm{t} = k_\mathrm{p}` and :math:`u_\mathrm{ff} = 0` results in the standard PI controller. This 2DOF PI controller can also be understood as a state-feedback controller with integral action and reference feedforward [#Fra1997]_.
5858

5959
.. figure:: figs/2dof_pi.svg
6060
:width: 100%
6161
:align: center
6262
:alt: 2DOF PI controller.
6363

64-
2DOF PI controller with an optional feedforward term. The operator :math:`1/s` refers to integration. A discrete-time variant of this controller with the integrator anti-windup is implemented in the :class:`motulator.common.control.PIController` class.
64+
2DOF PI controller with an optional feedforward term. The operator :math:`1/s` refers to integration. A discrete-time variant of this controller with the integrator anti-windup is implemented in the :class:`motulator.common.control.PIController` class.
6565

6666
Disturbance-Observer Structure
6767
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,7 +71,7 @@ The controller :eq:`2dof_pi` can be equally represented using the disturbance-ob
7171
.. math::
7272
\frac{\mathrm{d} u_\mathrm{i}}{\mathrm{d} t} &= \alpha_\mathrm{i}\left(u - \hat v\right) \\
7373
\hat v &= u_\mathrm{i} - (k_\mathrm{p} - k_\mathrm{t})y + u_\mathrm{ff} \\
74-
u &= k_\mathrm{t}\left(r - y\right) + \hat v
74+
u &= k_\mathrm{t}\left(r - y\right) + \hat v
7575
:label: 2dof_pi_disturbance_observer
7676
7777
where :math:`\alpha_\mathrm{i} = k_\mathrm{i}/k_\mathrm{t}` is the redefined integral gain and :math:`\hat v` is the input-equivalent disturbance estimate. This structure is convenient to prevent the integral windup that originates from the actuator saturation [#Fra1997]_. The actuator output is limited in practice due to physical constraints. Consequently, the realized actuator output is
@@ -85,7 +85,7 @@ where :math:`\mathrm{sat}(\cdot)` is the saturation function. If this saturation
8585
\frac{\mathrm{d} u_\mathrm{i}}{\mathrm{d} t} = \alpha_\mathrm{i}\left(\bar{u} - \hat v \right)
8686
:label: anti_windup
8787
88-
The other parts of the above controller are not affected by the saturation.
88+
The other parts of the above controller are not affected by the saturation.
8989

9090
Discrete-Time Algorithm
9191
^^^^^^^^^^^^^^^^^^^^^^^
@@ -99,7 +99,7 @@ The discrete-time variant of the controller :eq:`2dof_pi_disturbance_observer` w
9999
\bar{u}(k) &= \mathrm{sat}[u(k)]
100100
:label: discrete_2dof_pi
101101
102-
where :math:`T_\mathrm{s}` is the sampling period and :math:`k` is the discrete-time index. This algorithm corresponds to the actual implementation in the :class:`motulator.common.control.PIController` class.
102+
where :math:`T_\mathrm{s}` is the sampling period and :math:`k` is the discrete-time index. This algorithm corresponds to the actual implementation in the :class:`motulator.common.control.PIController` class.
103103

104104
.. _complex-vector-2dof-pi-controller:
105105

@@ -113,7 +113,7 @@ As shown in the figure below, the 2DOF PI controller presented above can be exte
113113
\boldsymbol{u} &= \boldsymbol{k}_\mathrm{t}\boldsymbol{r} - \boldsymbol{k}_\mathrm{p}\boldsymbol{y} + \boldsymbol{u}_\mathrm{i} + \boldsymbol{u}_\mathrm{ff}
114114
:label: complex_vector_2dof_pi
115115
116-
where :math:`\boldsymbol{u}` is the output of the controller, :math:`\boldsymbol{r}` is the reference signal, :math:`\boldsymbol{u}_\mathrm{i}` is the the integral state, and :math:`\boldsymbol{u}_\mathrm{ff}` is the optional feedforward signal. Furthermore, :math:`\boldsymbol{k}_\mathrm{t}` is the reference-feedforward gain, :math:`\boldsymbol{k}_\mathrm{p}` is the proportional gain, and :math:`\boldsymbol{k}_\mathrm{i}` is the integral gain.
116+
where :math:`\boldsymbol{u}` is the output of the controller, :math:`\boldsymbol{r}` is the reference signal, :math:`\boldsymbol{u}_\mathrm{i}` is the the integral state, and :math:`\boldsymbol{u}_\mathrm{ff}` is the optional feedforward signal. Furthermore, :math:`\boldsymbol{k}_\mathrm{t}` is the reference-feedforward gain, :math:`\boldsymbol{k}_\mathrm{p}` is the proportional gain, and :math:`\boldsymbol{k}_\mathrm{i}` is the integral gain.
117117

118118
.. figure:: figs/complex_vector_2dof_pi.svg
119119
:width: 100%
@@ -131,5 +131,3 @@ The discrete-time implementation of :eq:`complex_vector_2dof_pi` with the anti-w
131131
.. [#Fra1997] Franklin, Powell, Workman, "Digital Control of Dynamic Systems," 3rd ed., Menlo Park, CA: Addison-Wesley, 1997
132132
133133
.. [#Bri1999] Briz del Blanco, Degner, Lorenz, “Dynamic analysis of current regulators for AC motors using complex vectors,” IEEE Trans.Ind. Appl., 1999, https://doi.org/10.1109/28.806058
134-
135-

0 commit comments

Comments
 (0)