Conducting experiments
One of the main features of DiscoPygal package it to easily and quickly define and conduct experiments that run and compare different solvers. It can be different solver algorithms, same algorithm but with different parameters or any combination of the two.
- This feature consist of two parts:
scenarios_runner - To use within a python script
run_experiment - To use from CLI
1. Scenarios runner
discopygal.experiments.scenarios_runner
1.1. Scenario
Scenario
1.2. Custom handlers
run_scenarios()
handler
.handler
should be a func that receives the path collection as the first parameter and the solver object as the second- The default results that are calculated for each scenario (and you don’t need to add yourself) are:
total_path_length - The sum of lengths of all the robots’ paths in the solution
makespan - The makespan of the solution (time it takes)
calc_time - The time it took to calculate the solution (the time the planning process took)
1.3. Using scenarios_runner
Scenario
) and invoke the function run_scenarios()
result_root_dir
arg in a dir with the timestamp of the time the experiment began- To summarize, the steps that should be done in your python script are:
Create a list of scenarios you would like to run
Create a dict of custom handlers (optional)
Call:
run_scenarios()
with the desired parameters
1.4. Example
from discopygal.experiments.scenarios_runner import run_scenarios, Scenario
from discopygal.solvers.rrt.drrt_star import dRRT_star
SCENE_PATH = "examples/scenes/2_pocket_maze_tight.json"
scenarios = [Scenario(dRRT_star, SCENE_PATH, {"prm_num_landmarks": 200, "num_expands": 40}),
Scenario(dRRT_star, SCENE_PATH, {"prm_num_landmarks": 2000}),
Scenario(dRRT_star, SCENE_PATH, repetitions=5),
Scenario(dRRT_star, SCENE_PATH, {"prm_num_landmarks": 100}, 30, 20)]
extra_handlers = {"size_of_roadmap": lambda _, solver: len(solver.roadmap.edges), # This handler returns the number of edges in roadmap
"num_of_nodes": lambda _, solver: len(solver.roadmap.points)} # This handler returns the number of nodes in roadmap
run_scenarios(scenarios, "results_drrt_star", extra_handlers)
2. Run experiment
A CLI tool that uses scenarios_runner. To use, run in CLI:
scenarios_runner <args...>
scenarios_runner.exe <args...>
From the repo run:
python .\src\discopygal\experiments\run_experiment.py <args...>
2.1. Modes
It has 4 modes:
2.1.1. Full experiment
scenarios_file
in the global list named SCENARIOS
(it must be defined in scenarios_file
).scenarios_file
a global dir named RESULT_HANDLERS
to add your custom result handlers.Command:
scenarios_runner <result_root_dir> <scenarios_file>
- Arg:
result_root_dir - Root dir where the results are created (in dir with the timestamp of the time the experiment began)
scenarios_file - Path to
scenarios_file
as described above
2.1.2. Continue last experiment
scenarios_file
from where the last experiment that ran has stopped (according to the timestamp in dir).scenarios_file
must be the same as the last experiment to continue.Command:
scenarios_runner <result_root_dir> <scenarios_file> resume
- Arg:
result_root_dir - Root dir where the results are created (in dir with the timestamp of the time the last experiment began)
scenarios_file - Path to
scenarios_file
as described in Full experiment
2.1.3. Single Chunk
Command:
scenarios_runner <result_root_dir> <scenarios_file> <number_of_chunks> <chunk_number>
- Arg:
result_root_dir - Root dir where the results are created (in dir “chunk_<chunk_number>/results_<timestamp>” where timestamp is the time the experiment began)
scenarios_file - Path to
scenarios_file
as described in Full experimentnumber_of_chunks - Number of chunks to divide the scenarios list to.
chunk_number - Chunk index to run (zero based). Executes all scenarios in the chunk
2.1.4. Summarize chunks
Command:
scenarios_runner <result_root_dir> <scenarios_file> <number_of_chunks> end
- Arg:
result_root_dir - Root dir where the results are created (in dir “all/results_<timestamp>” where timestamp is the time the experiment began)
scenarios_file - Path to
scenarios_file
as described in Full experimentnumber_of_chunks - Number of chunks to divide the scenarios list to.
2.2. Example of scenarios_file
import itertools
from discopygal.experiments.scenarios_runner import Scenario
from discopygal.solvers.rrt.drrt_star import dRRT_star
random_sample_counter_list = [0, 1, 10, 20, 30, 50, 75, 100, 200, 500]
scenes = ["examples/scenes/tunnels_disc.json",
"examples/scenes/coffee_shop/coffee_shop.json",
"examples/scenes/2_discs_corridor.json",
"examples/scenes/2_pocket_maze_tight.json"]
SCENARIOS = [Scenario(dRRT_star, scene, {"prm_num_landmarks": 1000, "num_landmarks": 100, "random_sample_counter": random_sample_counter})
for random_sample_counter, scene in itertools.product(random_sample_counter_list, scenes)]
RESULT_HANDLERS = {"size_of_roadmap": lambda _, solver: len(solver.roadmap.edges),
"num_of_nodes": lambda _, solver: len(solver.roadmap.points)