-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
6,380 additions
and
1,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,8 @@ | |
**.egg-info/ | ||
**/__pycache__/ | ||
submission.csv | ||
logs | ||
logs | ||
secrets | ||
**/*.secret | ||
saves | ||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# .readthedocs.yaml | ||
# Read the Docs configuration file | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
# Required | ||
version: 2 | ||
|
||
build: | ||
os: ubuntu-20.04 | ||
tools: | ||
python: "3.11" | ||
|
||
sphinx: | ||
configuration: docs/conf.py | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Benchmarks | ||
|
||
These benchmarks are intended to test the performance of the implementation, i.e. speed and memory consumption. They are not meant to benchmark different approaches, algorithms or agents in the race task! | ||
|
||
## Profiling | ||
To profile the simulation, use [pyinstrument](https://github.com/joerick/pyinstrument) and run | ||
|
||
>: pyinstrument -r html profile.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
[sim] | ||
physics = "pyb" # pyb: PyBullet, dyn: Mathematical dynamics model, TODO: Complete the list | ||
camera_view = [5.0, -40.0, -40.0, 0.5, -1.0, 0.5] | ||
sim_freq = 500 # Simulation frequency, in Hz | ||
ctrl_freq = 500 # Controller frequency, in Hz. This frequency is used to simulate the onboard controller, NOT for the environment's step function | ||
gui = false # Enable/disable PyBullet's GUI | ||
|
||
[sim.disturbances.action] | ||
type = "GaussianNoise" | ||
std = 0.001 | ||
|
||
[sim.disturbances.dynamics] | ||
type = "UniformNoise" | ||
low = [-0.1, -0.1, -0.1] | ||
high = [0.1, 0.1, 0.1] | ||
|
||
[env] | ||
reseed = false # Whether to re-seed the random number generator between episodes | ||
seed = 1337 # Random seed | ||
freq = 30 # Frequency of the environment's step function, in Hz | ||
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false. | ||
|
||
[env.track] | ||
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the | ||
# center of the gate. | ||
[[env.track.gates]] | ||
pos = [0.45, -1.0, 0.525] | ||
rpy = [0.0, 0.0, 2.35] | ||
[[env.track.gates]] | ||
pos = [1.0, -1.55, 1.0] | ||
rpy = [0.0, 0.0, -0.78] | ||
[[env.track.gates]] | ||
pos = [0.0, 0.5, 0.525] | ||
rpy = [0.0, 0.0, 0.0] | ||
[[env.track.gates]] | ||
pos = [-0.5, -0.5, 1.0] | ||
rpy = [0.0, 0.0, 3.14] | ||
|
||
# Obstacle height: 1.05m. Height is measured from the ground to the top of the obstacle. | ||
[[env.track.obstacles]] | ||
pos = [1.0, -0.5, 1.05] | ||
[[env.track.obstacles]] | ||
pos = [0.5, -1.5, 1.05] | ||
[[env.track.obstacles]] | ||
pos = [-0.5, 0.0, 1.05] | ||
[[env.track.obstacles]] | ||
pos = [0.0, 1.0, 1.05] | ||
|
||
[env.track.drone] | ||
pos = [1.0, 1.0, 0.05] | ||
rpy = [0, 0, 0] | ||
vel = [0, 0, 0] | ||
ang_vel = [0, 0, 0] | ||
|
||
[env.randomization.drone_pos] | ||
type = "uniform" # Everything that can be used as a distribution in numpy.random | ||
# Kwargs that are permissable in the np random function | ||
low = [-0.1, -0.1, 0.0] | ||
high = [0.1, 0.1, 0.02] | ||
|
||
[env.randomization.drone_rpy] | ||
type = "uniform" | ||
low = [-0.1, -0.1, -0.1] | ||
high = [0.1, 0.1, 0.1] | ||
|
||
[env.randomization.drone_mass] | ||
type = "uniform" | ||
low = -0.01 | ||
high = 0.01 | ||
|
||
[env.randomization.drone_inertia] | ||
type = "uniform" | ||
low = [-0.000001, -0.000001, -0.000001] | ||
high = [0.000001, 0.000001, 0.000001] | ||
|
||
[env.randomization.gate_pos] | ||
type = "uniform" | ||
low = [-0.1, -0.1, 0.0] | ||
high = [0.1, 0.1, 0.0] | ||
|
||
[env.randomization.gate_rpy] | ||
type = "uniform" | ||
low = [0.0, 0.0, -0.1] | ||
high = [0.0, 0.0, 0.1] | ||
|
||
[env.randomization.obstacle_pos] | ||
type = "uniform" | ||
low = [-0.1, -0.1, 0.0] | ||
high = [0.1, 0.1, 0.0] | ||
|
||
[[env.constraints]] | ||
type = "DefaultConstraint" | ||
ctype = "input" | ||
[[env.constraints]] | ||
type = "BoundedConstraint" | ||
ctype = "state" | ||
active_dims = [0, 2, 4] | ||
upper_bounds = [3, 3, 2] | ||
lower_bounds = [-3.0, -3.0, -0.1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
from sim import time_sim_reset, time_sim_step | ||
|
||
|
||
def print_benchmark_results(name: str, timings: list[float]): | ||
print(f"\nResults for {name}:") | ||
print(f"Mean/std: {np.mean(timings):.2e}s +- {np.std(timings):.2e}s") | ||
print(f"Min time: {np.min(timings):.2e}s") | ||
print(f"Max time: {np.max(timings):.2e}s") | ||
|
||
|
||
if __name__ == "__main__": | ||
timings = time_sim_reset(n_tests=10) | ||
print_benchmark_results(name="Sim reset", timings=timings) | ||
sim_steps = 10 | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps) | ||
print_benchmark_results(name="Sim steps", timings=timings / sim_steps) | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps, physics_mode="dyn") | ||
print_benchmark_results(name="Sim steps (dyn backend)", timings=timings / sim_steps) | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps, physics_mode="pyb_gnd") | ||
print_benchmark_results(name="Sim steps (pyb_gnd backend)", timings=timings / sim_steps) | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps, physics_mode="pyb_drag") | ||
print_benchmark_results(name="Sim steps (pyb_drag backend)", timings=timings / sim_steps) | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps, physics_mode="pyb_dw") | ||
print_benchmark_results(name="Sim steps (pyb_dw backend)", timings=timings / sim_steps) | ||
timings = time_sim_step(n_tests=10, sim_steps=sim_steps, physics_mode="pyb_gnd_drag_dw") | ||
print_benchmark_results(name="Sim steps (pyb_gnd_drag_dw backend)", timings=timings / sim_steps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
import gymnasium | ||
|
||
import lsy_drone_racing # noqa: F401, required for gymnasium.make | ||
from lsy_drone_racing.utils import load_config | ||
|
||
|
||
def main(): | ||
config = load_config(Path(__file__).parent / "config/test.toml") | ||
env = gymnasium.make("DroneRacing-v0", config=config) | ||
env.reset() | ||
for _ in range(1000): | ||
env.step(env.action_space.sample()) | ||
# 0.455 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
import timeit | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
if TYPE_CHECKING: | ||
import numpy.typing as npt | ||
|
||
load_config_code = f""" | ||
from pathlib import Path | ||
from lsy_drone_racing.utils import load_config | ||
config = load_config(Path('{Path(__file__).parent / "config/test.toml"}')) | ||
""" | ||
env_setup_code = """ | ||
import gymnasium | ||
import lsy_drone_racing | ||
env = gymnasium.make('DroneRacing-v0', config=config) | ||
""" | ||
|
||
|
||
def time_sim_reset(n_tests: int = 10) -> npt.NDArray[np.floating]: | ||
setup = load_config_code + env_setup_code | ||
stmt = """env.reset()""" | ||
return np.array(timeit.repeat(stmt=stmt, setup=setup, number=1, repeat=n_tests)) | ||
|
||
|
||
def time_sim_step( | ||
n_tests: int = 10, sim_steps: int = 100, physics_mode: str = "pyb" | ||
) -> npt.NDArray[np.floating]: | ||
modify_config_code = f"""config.sim.physics = '{physics_mode}'\n""" | ||
setup = load_config_code + modify_config_code + env_setup_code + "\nenv.reset()" | ||
stmt = f""" | ||
for _ in range({sim_steps}): | ||
env.step(env.action_space.sample())""" | ||
return np.array(timeit.repeat(stmt=stmt, setup=setup, number=1, repeat=n_tests)) |
Oops, something went wrong.