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
48 changes: 26 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,69 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: 3.8
version: "0.5.10"

- name: Set up env
run: python -m pip install -e .[docs,dev]
- name: Install tkinter for GUI
run: sudo apt install python3-tk -y

- name: Run black
run: black --check .
- name: Set up env
run: uv sync --all-extras

- name: Run isort
run: isort .
- name: Run ruff format
run: uv run ruff format

- name: Run pylint for mdp folder
run: pylint src/behavior_generation_lecture_python/mdp --errors-only
- name: Run ruff linter for mdp folder
run: uv run ruff check src/behavior_generation_lecture_python/mdp

- name: Run mypy for mdp folder
run: mypy src/behavior_generation_lecture_python/mdp
run: uv run mypy src/behavior_generation_lecture_python/mdp

- name: Test
run: |
export DISPLAY=:99
Xvfb :99 &
pytest
uv run pytest

- name: Check coverage
run: |
export DISPLAY=:99
Xvfb :99 &
pytest --cov=src --cov-fail-under=85
uv run pytest --cov=src --cov-fail-under=85

- name: Copy notebooks to docs folder
run: cp -r notebooks/* docs/notebooks

- name: Build docs
run: mkdocs build
run: |
uv run ipython kernel install --user --name=behavior_generation_lecture
uv run mkdocs build

deploy-pages:
runs-on: ubuntu-latest
needs: [test]
if: github.ref == 'refs/heads/main'
concurrency: deploy-${{ github.ref }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: 3.8
version: "0.5.10"

- name: Set up env
run: python -m pip install -e .[docs]
run: uv sync --all-extras

- name: Copy notebooks to docs folder
run: cp -r notebooks/* docs/notebooks

- run: mkdocs gh-deploy --force
- run: |
uv run ipython kernel install --user --name=behavior_generation_lecture
uv run mkdocs gh-deploy --force


25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Python Code for the Lecture "Verhaltensgenerierung für Fahrzeuge" (Behavior Generation for Vehicles) at KIT

[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![GitHub CI](https://github.com/KIT-MRT/behavior_generation_lecture_python/actions/workflows/ci.yml/badge.svg)
![License](https://img.shields.io/github/license/kit-mrt/behavior_generation_lecture_python)
![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)

This repository contains the python code for the lecture ["Verhaltensgenerierung für Fahrzeuge" (Behavior Generation for Vehicles)](https://www.mrt.kit.edu/lehre_WS_Verhaltensgenerierung_Fahrzeuge.php) at KIT.
It is targeted towards both, exemplifying the content of the lecture, and giving a brief introduction to software development. (Please bare with us, the code is largely ported from matlab.)
Expand All @@ -11,21 +12,25 @@ An API documentation for new parts of the code and exemplary jupyter notebooks c

## Preparing the environment

We encourage the usage of [conda](https://conda.io/) or [virtualenv](https://virtualenv.pypa.io) instead of installing packages to your system directly.
We use [`uv`](https://docs.astral.sh/uv/) as package and project manager. Having `uv` installed, run

Having activated your environment
```sh
# clone this repo
git clone https://github.com/KIT-MRT/behavior_generation_lecture_python.git

- install this package in editable mode: `pip install --editable .`
# change into the repo folder
cd behavior_generation_lecture_python

# set up a virtual env and install the requirements
uv sync
```

<details>
<summary>Making venv kernels available to jupyter?</summary>
<summary>Making uv kernels available to jupyter?</summary>
<br>
<ul>
<li>from without the venv, install ipykernel <code>pip install --user ipykernel</code></li>
<li>list the current venvs available in jupyter: <code>jupyter kernelspec list</code> (your venv is not yet in there)</li>
<li>activate the venv <code>source activate venv-name</code></li>
<li>add the venv to the kernel list: <code>python -m ipykernel install --user --name=venv-name-for-jupyter</code>, where <code>venv-name-for-jupyter</code> can but must not match the name of the activated venv</li>
<li>check that the venv is in the list: <code>jupyter kernelspec list</code></li>
<li>create a kernel <code>uv run ipython kernel install --user --name=behavior_generation_lecture</code></li>
<li>run jupyter <code>uv run --with jupyter jupyter lab</code> and chose kernel <code>behavior_generation_lecture</code> in the browser
</ul>
</details>

Expand Down
3 changes: 1 addition & 2 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
full_doc_path = Path("reference", doc_path)

parts = tuple(module_path.parts)
if not "mdp" in parts and not "graph_search" in parts:
if "mdp" not in parts and "graph_search" not in parts:
continue # todo: add other modules here once docstrings added

if parts[-1] == "__init__":
Expand All @@ -36,5 +36,4 @@
mkdocs_gen_files.set_edit_path(full_doc_path, path)

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:

nav_file.writelines(nav.build_literate_nav())
10 changes: 6 additions & 4 deletions notebooks/a_star_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b0c1f089",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -15,11 +16,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d2311a94",
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
"\n",
" nodes_list = [\n",
" [\"HH\", 170, 620, [\"H\", \"B\"]],\n",
" [\"H\", 150, 520, [\"B\", \"L\", \"F\", \"HH\"]],\n",
Expand Down Expand Up @@ -48,6 +49,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ef38e2e0",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -57,9 +59,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "behavior_generation_lecture",
"language": "python",
"name": "python3"
"name": "behavior_generation_lecture"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -71,7 +73,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
33 changes: 22 additions & 11 deletions notebooks/compare_models_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f5d345f8",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import behavior_generation_lecture_python.vehicle_models.model_comparison as cm\n",
"from behavior_generation_lecture_python.utils.plot_vehicle import plot_vehicle as pv\n",
"from behavior_generation_lecture_python.utils.vizard import vizard as vz\n",
"\n",
"%matplotlib inline\n",
"# use '%matplotlib notebook' to interact with the vizard"
"\n",
"interactive_widgets = not os.getenv(\"CI\") == \"true\"\n",
"if interactive_widgets:\n",
" # Use widget backend locally, to be able to interact with the plots\n",
" %matplotlib widget\n",
"else:\n",
" # Use inline backend in CI, to render the notebooks for the hosted docs\n",
" %matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed1fe982",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -76,16 +85,17 @@
" (point_r_lin,) = ax2.plot([], [], marker=\"o\", color=\"blue\", ms=3)\n",
"\n",
" def update(i, *fargs):\n",
" slice_ = slice(i + 1, i + 2)\n",
" [l.remove() for l in reversed(ax1.lines)]\n",
" ax1.plot(x[: i + 1], y[: i + 1], \"b-\", linewidth=0.5)\n",
" point1.set_data(x[i + 1], y[i + 1])\n",
" point1.set_data(x[slice_], y[slice_])\n",
" pv.plot_vehicle(ax1, x[i], y[i], psi[i], delta_vals[i])\n",
"\n",
" point_delta.set_data(ti[i + 1], delta_vals[i + 1])\n",
" point_beta.set_data(ti[i + 1], beta[i + 1])\n",
" point_r.set_data(ti[i + 1], r[i + 1])\n",
" point_beta_lin.set_data(ti[i + 1], beta_lin[i + 1])\n",
" point_r_lin.set_data(ti[i + 1], r_lin[i + 1])\n",
" point_delta.set_data(ti[slice_], delta_vals[slice_])\n",
" point_beta.set_data(ti[slice_], beta[slice_])\n",
" point_r.set_data(ti[slice_], r[slice_])\n",
" point_beta_lin.set_data(ti[slice_], beta_lin[slice_])\n",
" point_r_lin.set_data(ti[slice_], r_lin[slice_])\n",
" for farg in fargs:\n",
" print(farg)\n",
"\n",
Expand All @@ -96,6 +106,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d0828333",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -105,9 +116,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "behavior_generation_lecture",
"language": "python",
"name": "python3"
"name": "behavior_generation_lecture"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -119,7 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
25 changes: 16 additions & 9 deletions notebooks/lateral_control_riccati_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cee10281",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
Expand All @@ -17,13 +19,19 @@
" DEFAULT_VEHICLE_PARAMS,\n",
")\n",
"\n",
"%matplotlib inline\n",
"# use '%matplotlib notebook' to interact with the vizard"
"interactive_widgets = not os.getenv(\"CI\") == \"true\"\n",
"if interactive_widgets:\n",
" # Use widget backend locally, to be able to interact with the plots\n",
" %matplotlib widget\n",
"else:\n",
" # Use inline backend in CI, to render the notebooks for the hosted docs\n",
" %matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4813563b",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -66,7 +74,7 @@
" def update(i, *fargs):\n",
" [l.remove() for l in reversed(ax.lines[1:])]\n",
" ax.plot(x[: i + 1], y[: i + 1], \"b-\", linewidth=0.5)\n",
" point1.set_data(x[i], y[i])\n",
" point1.set_data(x[i : i + 1], y[i : i + 1])\n",
" pv.plot_vehicle(ax, x[i], y[i], psi[i], delta[i])\n",
" for farg in fargs:\n",
" print(farg)\n",
Expand All @@ -78,9 +86,8 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"id": "e8e63277",
"metadata": {},
"outputs": [],
"source": [
"main()"
Expand All @@ -89,9 +96,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "behavior_generation_lecture",
"language": "python",
"name": "python3"
"name": "behavior_generation_lecture"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -103,7 +110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
Loading
Loading