Skip to content

Commit 0c84745

Browse files
ct2034sea-bass
andauthored
Updates on slides (#26)
Signed-off-by: Christian Henkel <christian.henkel2@de.bosch.com> Co-authored-by: Sebastian Castro <sebas.a.castro@gmail.com>
1 parent bc36f19 commit 0c84745

11 files changed

Lines changed: 322 additions & 159 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,36 @@ jobs:
7070
uses: actions/checkout@v4
7171
- name: Copy slides to main directory
7272
run: cp -r slides/* .
73-
- name: Set up pandoc
74-
uses: maxheld83/pandoc@v2.1.0
73+
- name: Run pandoc
74+
uses: docker://pandoc/latex:3.7
7575
with:
76-
args: "-t beamer main.md -o slides.pdf --listings"
76+
args: "-t beamer main.md -o slides.pdf --listings --slide-level=2"
7777
- name: Upload slides
7878
uses: actions/upload-artifact@main
7979
with:
8080
name: slides.pdf
8181
path: slides.pdf
82-
- name: Slides as release
82+
- name: Non-latest slides as release
8383
uses: ncipollo/release-action@v1
8484
with:
8585
artifacts: 'slides.pdf'
8686
token: ${{ secrets.GITHUB_TOKEN }}
8787
commit: ${{ github.sha }}
8888
allowUpdates: true
8989
name: Workshop Slides
90-
tag: slides
90+
tag: slides-pr${{ github.event.pull_request.number }}
91+
prerelease: true
92+
if: github.event_name == 'pull_request'
93+
- name: Latest slides as release
94+
uses: ncipollo/release-action@v1
95+
with:
96+
artifacts: 'slides.pdf'
97+
token: ${{ secrets.GITHUB_TOKEN }}
98+
commit: ${{ github.sha }}
99+
allowUpdates: true
100+
name: Workshop Slides
101+
tag: slides-latest
102+
makeLatest: true
91103
if: github.ref == 'refs/heads/main'
92104
pytest:
93105
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ repos:
2626
- id: requirements-txt-fixer
2727
- id: sort-simple-yaml
2828
- id: trailing-whitespace
29+
exclude: slides/main.md$
2930

3031
# Autoformats Python code.
3132
- repo: https://github.com/psf/black.git

pyrobosim_ros_gym/envs/greenhouse.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ def dense_reward(env, action):
375375
terminated = all(env.watered.values())
376376
if terminated:
377377
print(f"💧 Watered all good plants! Succeeded in {env.step_number} steps.")
378-
reward += 8.0
379378
return reward, terminated
380379

381380

pyrobosim_ros_gym/eval.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,29 @@
1111
import argparse
1212

1313
import rclpy
14-
from rclpy.node import Node
1514
from gymnasium.spaces import Discrete
15+
from rclpy.node import Node
1616
from stable_baselines3.common.base_class import BaseAlgorithm
1717

1818
from pyrobosim_ros_gym import get_config
1919
from pyrobosim_ros_gym.envs import available_envs_w_subtype, get_env_by_name
2020
from pyrobosim_ros_gym.policies import ManualPolicy, model_and_env_type_from_path
2121

22+
MANUAL_STR = "manual"
23+
2224

2325
def get_args() -> argparse.Namespace:
2426
"""Helper function to parse the command-line arguments."""
2527
parser = argparse.ArgumentParser()
2628
parser.add_argument(
2729
"--model",
2830
type=str,
29-
help="The name of the model to evaluate. Can be 'manual' for manual control.",
31+
help=f"The path of the model to evaluate. Can be '{MANUAL_STR}' for manual control.",
3032
)
3133
parser.add_argument(
3234
"--env",
3335
type=str,
34-
help="The name of the environment to use if '--model manual' is selected.",
36+
help=f"The name of the environment to use if '--model {MANUAL_STR}' is selected.",
3537
choices=available_envs_w_subtype(),
3638
)
3739
parser.add_argument(
@@ -50,6 +52,13 @@ def get_args() -> argparse.Namespace:
5052
"--realtime", action="store_true", help="If true, slows down to real time."
5153
)
5254
args = parser.parse_args()
55+
56+
# Ensure '--env' is provided if '--model' is 'manual'
57+
if args.model == MANUAL_STR and not args.env:
58+
parser.error(f"--env must be specified when --model is '{MANUAL_STR}'.")
59+
if args.env and args.model is None:
60+
print("--env is specified but --model is not. Defaulting to manual control.")
61+
args.model = MANUAL_STR
5362
return args
5463

5564

@@ -62,7 +71,7 @@ def get_args() -> argparse.Namespace:
6271

6372
# Load the model and environment
6473
model: BaseAlgorithm | ManualPolicy
65-
if args.model == "manual":
74+
if args.model == MANUAL_STR:
6675
env = get_env_by_name(
6776
args.env,
6877
node,

pyrobosim_ros_gym/policies/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from stable_baselines3.common.base_class import BaseAlgorithm
1414

1515

16+
AVAILABLE_POLICIES = {alg.__name__: alg for alg in (DQN, PPO, SAC, A2C)}
17+
18+
1619
class ManualPolicy:
1720
"""A policy that allows manual keyboard control of the robot."""
1821

@@ -53,14 +56,9 @@ def model_and_env_type_from_path(model_path: str) -> tuple[BaseAlgorithm, str]:
5356
algorithm = model_name_parts[1]
5457

5558
# Load the model
56-
if algorithm == "DQN":
57-
model: BaseAlgorithm = DQN.load(model_path, env=None)
58-
elif algorithm == "PPO":
59-
model = PPO.load(model_path, env=None)
60-
elif algorithm == "SAC":
61-
model = SAC.load(model_path, env=None)
62-
elif algorithm == "A2C":
63-
model = A2C.load(model_path, env=None)
59+
if algorithm in AVAILABLE_POLICIES:
60+
model_class = AVAILABLE_POLICIES[algorithm]
61+
model = model_class.load(model_path)
6462
else:
6563
raise RuntimeError(f"Invalid algorithm type: {algorithm}")
6664

pyrobosim_ros_gym/policy_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, args: argparse.Namespace, executor):
4848
cancel_callback=self.cancel_policy,
4949
)
5050

51-
self.get_logger().info(f"Started policy node with model '{self.model}'.")
51+
self.get_logger().info(f"Started policy node with model '{args.model}'.")
5252

5353
def cancel_policy(self, goal_handle):
5454
self.get_logger().info("Canceling policy execution...")

slides/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The accompanying slides are built with [Pandoc](https://pandoc.org/) and `pdflatex`.
44

5+
Refer to <https://pandoc.org/MANUAL.html#variables-for-beamer-slides> for useful information.
6+
7+
## Running pandoc natively
8+
59
You must first install these tools:
610

711
```bash
@@ -11,7 +15,18 @@ sudo apt install pandoc texlive-latex-base texlive-latex-extra
1115
Then, to build the slides:
1216

1317
```bash
14-
pandoc -t beamer main.md -o slides.pdf --listings
18+
pandoc -t beamer main.md -o slides.pdf --listings --slide-level=2
1519
```
1620

17-
Refer to https://pandoc.org/MANUAL.html#variables-for-beamer-slides for useful information.
21+
## Running pandoc with Docker (recommended)
22+
23+
Or use the docker image that is also used in CI:
24+
(Run this command from the `slides/` directory)
25+
26+
```bash
27+
docker run \
28+
--rm \
29+
--volume "$(pwd):/data" \
30+
--user $(id -u):$(id -g) \
31+
pandoc/latex:3.7 -t beamer main.md -o slides.pdf --listings --slide-level=2
32+
```

0 commit comments

Comments
 (0)