Skip to content

Commit da1f5a2

Browse files
Merge remote-tracking branch 'upstream/main' into training_rl_paper
2 parents 196d79d + 83fae93 commit da1f5a2

File tree

137 files changed

+19359
-19151
lines changed

Some content is hidden

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

137 files changed

+19359
-19151
lines changed

.github/workflows/push.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
name: Test package quality
1+
name: Test Package Quality
72

83
on: push
94

@@ -26,6 +21,11 @@ jobs:
2621
- name: Install package
2722
run: |
2823
pip install -e .
24+
- name: Run Linting
25+
run: |
26+
pre-commit install
27+
pre-commit autoupdate
28+
pre-commit run
2929
- name: Unit tests
3030
run: |
3131
python -m pytest tests/

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Install the pre-commit hooks below with
2+
# 'pre-commit install'
3+
4+
# Auto-update the version of the hooks with
5+
# 'pre-commit autoupdate'
6+
7+
# Run the hooks on all files with
8+
# 'pre-commit run --all'
9+
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.5.0
13+
hooks:
14+
- id: check-ast
15+
- id: check-yaml
16+
- id: check-toml
17+
- id: check-added-large-files
18+
args: ['--maxkb=10000']
19+
- id: check-docstring-first
20+
- id: check-executables-have-shebangs
21+
- id: check-shebang-scripts-are-executable
22+
- id: check-merge-conflict
23+
- id: debug-statements
24+
- id: trailing-whitespace
25+
exclude: (^.*.txt)
26+
- id: end-of-file-fixer
27+
exclude: (^.*.txt)
28+
- id: double-quote-string-fixer
29+
30+
- repo: https://github.com/pycqa/isort
31+
rev: 5.12.0
32+
hooks:
33+
- id: isort
34+
name: isort
35+
args: ['--line-length=110']
36+
37+
- repo: https://github.com/pre-commit/mirrors-autopep8
38+
rev: v2.0.4
39+
hooks:
40+
- id: autopep8
41+
name: autopep8-default
42+
args: ['-i', '--ignore=C0301', '--max-line-length=1000']
43+
exclude: (^tests/|^safe_control_gym/math_and_models/transformations.py)
44+
- id: autopep8
45+
name: autopep8-tests
46+
args: ['-i', '--ignore=C0301,E501,E201,E241,E127', '--max-line-length=1000']
47+
files: (^tests/|^safe_control_gym/math_and_models/transformations.py)
48+
49+
- repo: https://github.com/PyCQA/flake8
50+
rev: 6.1.0
51+
hooks:
52+
- id: flake8
53+
name: flake8_default
54+
args: ['--ignore=E501']
55+
exclude: (^safe_control_gym/__init__.py|^tests/|^safe_control_gym/math_and_models/transformations.py)
56+
- id: flake8
57+
name: flake8_tests
58+
args: ['--ignore=E501,E201,E241,E127']
59+
files: (^tests/|^safe_control_gym/math_and_models/transformations.py)
60+
exclude: ^tests/test_build.py

README.md

Lines changed: 86 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ git clone https://github.com/utiasDSL/safe-control-gym.git
4040
cd safe-control-gym
4141
```
4242

43-
### Option A (recommended): using `conda`
43+
### (optional) Create a `conda` environment
4444

4545
Create and access a Python 3.10 environment using
4646
[`conda`](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html)
@@ -50,29 +50,15 @@ conda create -n safe python=3.10
5050
conda activate safe
5151
```
5252

53+
### Install
54+
5355
Install the `safe-control-gym` repository
5456

5557
```bash
5658
pip install --upgrade pip
5759
pip install -e .
5860
```
5961

60-
### Option B: using venv and poetry
61-
62-
Create and access a Python 3.10 virtual environment using
63-
[`pyenv`](https://github.com/pyenv/pyenv) and
64-
[`venv`](https://docs.python.org/3/library/venv.html)
65-
66-
```bash
67-
pyenv install 3.10
68-
pyenv local 3.10
69-
python3 -m venv safe
70-
source safe/bin/activate
71-
pip install --upgrade pip
72-
pip install poetry
73-
poetry install
74-
```
75-
7662
#### Note
7763

7864
You may need to separately install `gmp`, a dependency of `pycddlib`:
@@ -97,6 +83,80 @@ Overview of [`safe-control-gym`](https://arxiv.org/abs/2109.06325)'s API:
9783

9884
<img src="figures/config.png" alt="config" width="800">
9985

86+
## Getting Started
87+
88+
Familiarize with APIs and environments with the scripts in [`examples/`](https://github.com/utiasDSL/safe-control-gym/tree/main/examples)
89+
90+
### 3D Quadrotor Lemniscate Trajectory Tracking with PID
91+
92+
```bash
93+
cd ./examples/ # Navigate to the examples folder
94+
python3 pid/pid_experiment.py \
95+
--algo pid \
96+
--task quadrotor \
97+
--overrides \
98+
./pid/config_overrides/quadrotor_3D/quadrotor_3D_tracking.yaml
99+
```
100+
101+
<img src="figures/systems.png" alt="systems" width="450"> <img src="figures/figure8.gif" alt="trajectory" width="350">
102+
103+
### Cartpole Stabilization with LQR
104+
105+
```bash
106+
cd ./examples/ # Navigate to the examples folder
107+
python3 lqr/lqr_experiment.py \
108+
--algo lqr \
109+
--task cartpole \
110+
--overrides \
111+
./lqr/config_overrides/cartpole/cartpole_stabilization.yaml \
112+
./lqr/config_overrides/cartpole/lqr_cartpole_stabilization.yaml
113+
```
114+
115+
### 2D Quadrotor Trajectory Tracking with PPO
116+
117+
```bash
118+
cd ./examples/rl/ # Navigate to the RL examples folder
119+
python3 rl_experiment.py \
120+
--algo ppo \
121+
--task quadrotor \
122+
--overrides \
123+
./config_overrides/quadrotor_2D/quadrotor_2D_track.yaml \
124+
./config_overrides/quadrotor_2D/ppo_quadrotor_2D.yaml \
125+
--kv_overrides \
126+
algo_config.training=False
127+
```
128+
129+
### Verbose API Example
130+
131+
```bash
132+
cd ./examples/ # Navigate to the examples folder
133+
python3 no_controller/verbose_api.py \
134+
--task cartpole \
135+
--overrides no_controller/verbose_api.yaml
136+
```
137+
138+
<img src="figures/prints.png" al="prints" width="800">
139+
140+
## List of Implemented Controllers
141+
142+
- [PID](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/pid/pid.py)
143+
- [LQR](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/lqr/lqr.py)
144+
- [iLQR](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/lqr/ilqr.py)
145+
- [Linear MPC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/mpc/linear_mpc.py)
146+
- [GP-MPC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/mpc/gp_mpc.py)
147+
- [SAC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/sac/sac.py)
148+
- [PPO](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/ppo/ppo.py)
149+
- [DDPG](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/ddpg/ddpg.py)
150+
- [Safety Layer](https://github.com/utiasDSL/safe-control-gym/tree/main/safe_control_gym/controllers/safe_explorer)
151+
- [RARL](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/rarl/rarl.py)
152+
- [RAP](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/rarl/rap.py)
153+
154+
## List of Implemented Safety Filters
155+
156+
- [MPSC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/mpsc/linear_mpsc.py)
157+
- [CBF](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/cbf/cbf.py)
158+
- [Neural Network CBF](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/cbf/cbf_nn.py)
159+
100160
## Performance
101161

102162
We compare the sample efficiency of `safe-control-gym` with the original [OpenAI Cartpole][001] and [PyBullet Gym's Inverted Pendulum][002], as well as [`gym-pybullet-drones`][003].
@@ -130,43 +190,18 @@ Note that the Bullet engine frequency reported for `safe-control-gym` is typical
130190
[004]: https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/envs/gym_control/cartpole.py
131191
[005]: https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/envs/gym_pybullet_drones/quadrotor.py
132192

133-
## Getting Started
134-
135-
Familiarize with APIs and environments with the scripts in [`examples/`](https://github.com/utiasDSL/safe-control-gym/tree/main/examples)
136-
193+
## Run Tests and Linting
194+
Tests can be run locally by executing:
137195
```bash
138-
cd ./examples/ # Navigate to the examples folder
139-
python3 pid/pid_experiment.py --algo pid --task quadrotor --overrides ./pid/config_overrides/quadrotor_3D/quadrotor_3D_tracking.yaml # PID trajectory tracking with the 3D quadcopter
140-
python3 no_controller/verbose_api.py --task cartpole --overrides no_controller/verbose_api.yaml # Printout of the extended safe-control-gym APIs
196+
python3 -m pytest ./tests/ # Run all tests
141197
```
142198

143-
## Systems Variables and 2D Quadrotor Lemniscate Trajectory Tracking
144-
145-
<img src="figures/systems.png" alt="systems" width="450"> <img src="figures/figure8.gif" alt="trajectory" width="350">
146-
147-
## Verbose API Example
148-
149-
<img src="figures/prints.png" al="prints" width="800">
150-
151-
## List of Implemented Controllers
152-
153-
- [PID](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/pid/pid.py)
154-
- [LQR](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/lqr/lqr.py)
155-
- [iLQR](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/lqr/ilqr.py)
156-
- [Linear MPC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/mpc/linear_mpc.py)
157-
- [GP-MPC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/mpc/gp_mpc.py)
158-
- [SAC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/sac/sac.py)
159-
- [PPO](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/ppo/ppo.py)
160-
- [DDPG](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/ddpg/ddpg.py)
161-
- [Safety Layer](https://github.com/utiasDSL/safe-control-gym/tree/main/safe_control_gym/controllers/safe_explorer)
162-
- [RARL](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/rarl/rarl.py)
163-
- [RAP](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/controllers/rarl/rap.py)
164-
165-
## List of Implemented Safety Filters
166-
167-
- [MPSC](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/mpsc/linear_mpsc.py)
168-
- [CBF](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/cbf/cbf.py)
169-
- [Neural Network CBF](https://github.com/utiasDSL/safe-control-gym/blob/main/safe_control_gym/safety_filters/cbf/cbf_nn.py)
199+
Linting can be run locally with:
200+
```bash
201+
pre-commit install # Install the pre-commit hooks
202+
pre-commit autoupdate # Auto-update the version of the hooks
203+
pre-commit run --all # Run the hooks on all files
204+
```
170205

171206
## References
172207

examples/cbf/cbf_experiment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import shutil
55
from functools import partial
66

7-
import numpy as np
87
import matplotlib.pyplot as plt
8+
import numpy as np
99

1010
from safe_control_gym.experiments.base_experiment import BaseExperiment
11-
from safe_control_gym.utils.registration import make
1211
from safe_control_gym.utils.configuration import ConfigFactory
12+
from safe_control_gym.utils.registration import make
1313

1414

1515
def run(plot=True, training=True, n_episodes=1, n_steps=None, curr_path='.', save_data=False):

examples/lqr/lqr_experiment.py

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

33
import os
44
import pickle
5-
from functools import partial
65
from collections import defaultdict
6+
from functools import partial
77

8-
import numpy as np
98
import matplotlib.pyplot as plt
9+
import numpy as np
1010
from matplotlib.ticker import FormatStrFormatter
1111

12-
from safe_control_gym.experiments.base_experiment import BaseExperiment
1312
from safe_control_gym.envs.benchmark_env import Task
13+
from safe_control_gym.experiments.base_experiment import BaseExperiment
1414
from safe_control_gym.utils.configuration import ConfigFactory
1515
from safe_control_gym.utils.registration import make
1616

examples/mpsc/config_overrides/cartpole/cartpole_stab.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ task_config:
44
ctrl_freq: 15
55
pyb_freq: 750
66
physics: pyb
7-
7+
88
# state initialization
99
init_state:
1010
init_x: 0.1
1111
init_x_dot: -1.5
1212
init_theta: -0.175
13-
init_theta_dot: 0.5
13+
init_theta_dot: 0.5
1414
randomized_init: True
1515
randomized_inertial_prop: False
1616
normalized_rl_action_space: True

examples/mpsc/config_overrides/cartpole/cartpole_track.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ task_config:
44
ctrl_freq: 15
55
pyb_freq: 750
66
physics: pyb
7-
7+
88
# state initialization
99
init_state:
1010
init_x: 0
1111
init_x_dot: 0
1212
init_theta: 0
13-
init_theta_dot: 0
13+
init_theta_dot: 0
1414
randomized_init: True
1515
randomized_inertial_prop: False
1616
normalized_rl_action_space: True

examples/mpsc/config_overrides/cartpole/sac_cartpole.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ algo_config:
2525
save_interval: 1000
2626
num_checkpoints: 100
2727
eval_interval: 1000
28-
eval_save_best: True
28+
eval_save_best: True
2929
tensorboard: True

examples/mpsc/config_overrides/quadrotor_2D/quadrotor_2D_stab.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ task_config:
6060
rew_state_weight: [1, 1, 1, 1, 1, 1]
6161
rew_act_weight: 0.1
6262
rew_exponential: True
63-
63+
6464
constraints:
6565
- constraint_form: default_constraint
6666
constrained_variable: state

examples/mpsc/config_overrides/quadrotor_2D/quadrotor_2D_track.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ task_config:
5252
trajectory_plane: 'xz'
5353
trajectory_position_offset: [0, 1]
5454
trajectory_scale: 1
55-
55+
5656
inertial_prop:
5757
M: 0.027
5858
Iyy: 1.4e-05

0 commit comments

Comments
 (0)