Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix env init #240

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f9bffcd
formated with python ruff
devarndt Nov 10, 2023
92b1c46
Refactored test dc motor
devarndt Nov 10, 2023
5369a37
starting viz refactor
devarndt Nov 10, 2023
757d8a5
proxy object for motor dashboard
devarndt Nov 10, 2023
9105bc5
removed callback
devarndt Nov 17, 2023
0d83e72
move figure saving into motor_dashboard
devarndt Nov 24, 2023
62f0abf
change plot files folder
devarndt Dec 4, 2023
44093b9
add plot folder
devarndt Dec 4, 2023
bec5156
added callbacks back
devarndt Dec 11, 2023
3893168
helper enums for render mode and motor id
devarndt Dec 15, 2023
87a1ba9
moved dashboard configuration out of core.py
devarndt Dec 18, 2023
d0158eb
Reorganized new Motor and RenderMode helpers
devarndt Jan 8, 2024
09e3eb8
changed acadamic mode handling
devarndt Jan 15, 2024
581ccbb
added gem_controllers
devarndt Jan 15, 2024
dc59237
default for scale plots
devarndt Jan 22, 2024
c7610a2
fixing test with newest numpy version
devarndt Jan 22, 2024
e203255
WIP
devarndt Jan 29, 2024
dfe181c
Moved to src directory and reformated all files with ruff
devarndt Feb 4, 2024
b4848f5
ruff check --fix
devarndt Feb 4, 2024
19db5e4
working test
devarndt Feb 4, 2024
5c86546
removed class init hack
devarndt Feb 4, 2024
94585a0
changed one env to pythonic init, but not worth to do it for all envs
devarndt Feb 4, 2024
3451a38
removed some unused util testing code
devarndt Feb 5, 2024
f12593d
ruff format
devarndt Feb 5, 2024
282b53d
removed gem-control
devarndt Feb 5, 2024
3b975c9
packaging for pypi added
devarndt Feb 5, 2024
848cd46
added requirements.txt
devarndt Feb 12, 2024
3fa9a23
WIP Observer Pattern
devarndt Feb 12, 2024
ba71716
fix typo
devarndt Feb 12, 2024
e1c69a8
Revert changes because constructor of __init__ args are getting calle…
devarndt Feb 12, 2024
6d06863
added state oberserver
devarndt Mar 1, 2024
0484d99
enable env checker
devarndt Mar 1, 2024
96dc713
fix test
devarndt Mar 1, 2024
df6b27e
Working tests with env checker. See warnings for further refactoring
devarndt Mar 7, 2024
540b0ad
Changes for release 2.0.1
devarndt Mar 7, 2024
40c3367
introduce transfer ratio k between rotor and stator windings
max-schenke Apr 23, 2024
1389548
(Hopefully) fixed a bug where the Sphinx build failed due to an old v…
XyDrKRulof Apr 25, 2024
d566f70
Merge pull request #237 from upb-lea/SphinxFix
bhk11 Apr 25, 2024
5f52f8d
fixed gui pop up in tests
devarndt May 6, 2024
62b0dd2
Potential fix to the Sphinx Doc disappearence error
XyDrKRulof May 10, 2024
fab1223
Merge pull request #238 from upb-lea/SphinxFix
bhk11 May 10, 2024
3977a58
remove magic number
max-schenke May 13, 2024
4e69051
python 3.8 deprecated, added python 3.11
devarndt May 13, 2024
d22d30b
manual formatting for some matrices
devarndt May 14, 2024
652a84a
fixed unwrapped warning in tests
devarndt May 14, 2024
a672310
fixed state space warnings
devarndt May 14, 2024
d936980
fixed integration test on windows
devarndt May 14, 2024
8839c22
added python 3.11 in changelog
devarndt May 14, 2024
2e0703b
fixed formatting
devarndt May 14, 2024
24e3d82
Merge pull request #229 from upb-lea/refactoring
max-schenke May 14, 2024
124b7b6
fixes to EESM ODE and jacobian
max-schenke May 15, 2024
e363003
merge with current nightly
max-schenke May 15, 2024
54f8bab
update python version support from >=3.8 to >=3.9 in pyproject.toml
max-schenke May 16, 2024
eb00223
update python version requirement to >=3.9
max-schenke May 16, 2024
e7406f6
Merge branch 'nightly' into EESM_transformations
XyDrKRulof May 16, 2024
4ee85c4
Merge pull request #234 from upb-lea/EESM_transformations
max-schenke May 17, 2024
4ffb096
Dont raise exception on dict input
devarndt May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10"]
python-version: [3.9, "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Build Sphinx documentation
uses: ammaraskar/sphinx-action@master
with:
pre-build-command: "python -m pip install sphinx m2r2 sphinx_rtd_theme && python -m pip install -r requirements.txt & python -m pip install ."
pre-build-command: "python -m pip install sphinx m2r2 sphinx_rtd_theme==1.3.0 && python -m pip install -r requirements.txt & python -m pip install ."
docs-folder: "docs/"
# Publish built docs to gh-pages branch.
# ===============================
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ examples/logs/
/my_examples/
.vscode/settings.json
.vscode/launch.json
plots/
plots/
saved_plots/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Changed
## Fixed

## [2.0.1] - Unreleased
## Added
- Support for Python 3.11
- Ruff: Python linter & formatter (see [DEVELOPMENT.md](DEVELOPMENT.md))
- StateObserver: An easy way to get state values with error checking [example](examples/observers/state_observer_example.py)
- Integrated gem_controls repository into gem. classic_controllers will be removed in further version
- Using pyproject.toml, dropping deprecated setup.py
- Enabled Gymnasium env checker [see here](https://gymnasium.farama.org/api/experimental/wrappers/#gymnasium.experimental.wrappers.PassiveEnvCheckerV0)
## Changed
- Linted and formatted all files
- Changed max. steps in some test files to improve test speed by 30%
## Fixed

## [2.0.0] - 2023-08-15
## Added
- Support for Python 3.10
Expand Down
41 changes: 41 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Packaging
Update build tool: `python -m pip install --upgrade build`

Build: `python -m build`

# Testing
Run: `pytest --sw`
> --sw, --stepwise Exit on test failure and continue from last failing test next time

Warning as error:
> python -W error -m pytest --sw -v

# Linter and Formater
Ruff: https://docs.astral.sh/ruff/installation/

Use `ruff check src/` for linting
or `ruff format src/` for formatting


# Install package for local development
Run: `pip install -e .`
> -e, --editable <path/url> Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url

Check correct package install directory with python interpreter
Run: `python`

```
>>> import gym_electric_motor as gem
>>> gem
<module 'gym_electric_motor' from '/home/***/gym-electric-motor/src/gym_electric_motor/__init__.py'>
```

# Sidenotes
```
python -V
Python 3.10.13
```


## No poetry
Some complex dependency systems don't work good with poetry (e.g. pytorch) (https://python-poetry.org/)
620 changes: 349 additions & 271 deletions examples/classic_controllers/classic_controllers.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from classic_controllers import Controller
from externally_referenced_state_plot import ExternallyReferencedStatePlot

import gym_electric_motor as gem
from gym_electric_motor.visualization import MotorDashboard
from gym_electric_motor.visualization.render_modes import RenderMode

if __name__ == '__main__':

if __name__ == "__main__":
"""
motor type: 'PermExDc' Permanently Excited DC Motor
'ExtExDc' Externally Excited MC Motor
Expand All @@ -19,26 +20,30 @@
'Finite' Discrete Action Space
"""

motor_type = 'PermExDc'
control_type = 'TC'
action_type = 'Cont'
motor_type = "PermExDc"
control_type = "TC"
action_type = "Cont"

motor = action_type + '-' + control_type + '-' + motor_type + '-v0'
motor = action_type + "-" + control_type + "-" + motor_type + "-v0"

if motor_type in ['PermExDc', 'SeriesDc']:
states = ['omega', 'torque', 'i', 'u']
elif motor_type == 'ShuntDc':
states = ['omega', 'torque', 'i_a', 'i_e', 'u']
elif motor_type == 'ExtExDc':
states = ['omega', 'torque', 'i_a', 'i_e', 'u_a', 'u_e']
if motor_type in ["PermExDc", "SeriesDc"]:
states = ["omega", "torque", "i", "u"]
elif motor_type == "ShuntDc":
states = ["omega", "torque", "i_a", "i_e", "u"]
elif motor_type == "ExtExDc":
states = ["omega", "torque", "i_a", "i_e", "u_a", "u_e"]
else:
raise KeyError(motor_type + ' is not available')
raise KeyError(motor_type + " is not available")

# definition of the plotted variables
external_ref_plots = [ExternallyReferencedStatePlot(state) for state in states]

motor_dashboard = MotorDashboard(additional_plots=external_ref_plots, render_mode=RenderMode.Figure)
# initialize the gym-electric-motor environment
env = gem.make(motor, visualization=MotorDashboard(additional_plots=external_ref_plots), render_mode="figure_once")
env = gem.make(
motor,
visualization=motor_dashboard,
)
"""
initialize the controller

Expand All @@ -50,10 +55,10 @@
a (optional) tuning parameter of the symmetrical optimum (default: 4)

"""
visualization = MotorDashboard(additional_plots=external_ref_plots)

controller = Controller.make(env, external_ref_plots=external_ref_plots)

(state, reference), _ = env.reset(seed = None)
(state, reference), _ = env.reset(seed=None)
# simulate the environment
for i in range(10001):
action = controller.control(state, reference)
Expand All @@ -62,4 +67,5 @@
env.reset()
controller.reset()

motor_dashboard.show_and_hold()
env.close()
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from gym_electric_motor.physical_system_wrappers import FluxObserver
import numpy as np

if __name__ == '__main__':

if __name__ == "__main__":
"""
motor type: 'SCIM' Squirrel Cage Induction Motor

Expand All @@ -18,21 +17,27 @@
action_type: 'AbcCont' Continuous Action Space
"""

motor_type = 'SCIM'
control_type = 'TC'
action_type = 'Cont'
motor_type = "SCIM"
control_type = "TC"
action_type = "Cont"

env_id = action_type + '-' + control_type + '-' + motor_type + '-v0'
env_id = action_type + "-" + control_type + "-" + motor_type + "-v0"

# definition of the plotted variables
states = ['omega', 'torque', 'i_sd', 'i_sq', 'u_sd', 'u_sq']
states = ["omega", "torque", "i_sd", "i_sq", "u_sd", "u_sq"]
external_ref_plots = [ExternallyReferencedStatePlot(state) for state in states]
external_plot = [ExternalPlot(referenced=control_type != 'CC'), ExternalPlot(min=-np.pi, max=np.pi)]
external_plot = [
ExternalPlot(referenced=control_type != "CC"),
ExternalPlot(min=-np.pi, max=np.pi),
]
external_ref_plots += external_plot

# initialize the gym-electric-motor environment
env = gem.make(env_id, physical_system_wrappers=(FluxObserver(),),
visualization=MotorDashboard(state_plots=('omega', 'psi_abs', 'psi_angle')))
env = gem.make(
env_id,
physical_system_wrappers=(FluxObserver(),),
visualization=MotorDashboard(state_plots=("omega", "psi_abs", "psi_angle")),
)

"""
initialize the controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from gym_electric_motor.visualization import MotorDashboard


if __name__ == '__main__':

if __name__ == "__main__":
"""
motor type: 'PMSM' Permanent Magnet Synchronous Motor
'SynRM' Synchronous Reluctance Motor
Expand All @@ -18,18 +17,22 @@
'Finite' Discrete Action Space
"""

motor_type = 'PMSM'
control_type = 'TC'
action_type = 'Cont'

env_id = action_type + '-' + control_type + '-' + motor_type + '-v0'
motor_type = "PMSM"
control_type = "TC"
action_type = "Cont"

env_id = action_type + "-" + control_type + "-" + motor_type + "-v0"

# definition of the plotted variables
external_ref_plots = [ExternallyReferencedStatePlot(state) for state in ['omega', 'torque', 'i_sd', 'i_sq', 'u_sd', 'u_sq']]
external_ref_plots = [
ExternallyReferencedStatePlot(state)
for state in ["omega", "torque", "i_sd", "i_sq", "u_sd", "u_sq"]
]

# initialize the gym-electric-motor environment
env = gem.make(env_id, visualization=MotorDashboard(additional_plots=external_ref_plots))
env = gem.make(
env_id, visualization=MotorDashboard(additional_plots=external_ref_plots)
)

"""
initialize the controller
Expand All @@ -48,7 +51,9 @@

"""

controller = Controller.make(env, external_ref_plots=external_ref_plots, torque_control='analytical')
controller = Controller.make(
env, external_ref_plots=external_ref_plots, torque_control="analytical"
)

(state, reference), _ = env.reset()

Expand Down
Loading
Loading