multirotor.optimize¶
Module Contents¶
Functions¶
|
Create an optuna.Study set to maximize reward. |
|
Run a single episode, where the environment is controlled by the Controller |
|
Create a multirotor.controller.Controller object with default values. |
|
Makes a dictionary of parameters which can be used with the Controller.set_params() |
|
Make the environment instance to be used by objective(), and set default |
|
Make the function that optuna will use to optimize. |
|
Search over parameter space to optimize controller parameters in make_controller_from_trial(). |
|
Apply parameters from an optuna.Study to a Controller. Converts the dictionary |
Attributes¶
- multirotor.optimize.DEFAULTS¶
- multirotor.optimize.get_study(study_name: str = None, seed: int = 0) optuna.Study¶
Create an optuna.Study set to maximize reward.
Parameters¶
- study_namestr, optional
If name is given, a study is created in ./studies/study_name.db, by default None
- seedint, optional
The random seed to use for parameter sampling, by default 0
Returns¶
- optuna.Study
The study object. Best params can be accessed via study.best_params.
- multirotor.optimize.run_sim(env, traj: multirotor.trajectories.Trajectory, ctrl: multirotor.controller.Controller) multirotor.helpers.DataLog¶
Run a single episode, where the environment is controlled by the Controller object. The env object must be reset() before calling.
Parameters¶
- envDynamicsMultirotorEnv
The environment to run
- trajTrajectory
The waypoints to follow.
- ctrlController
The controller which outputs dynamics to be fed to the environment.
Returns¶
- DataLog
A log containing state measurements for each step.
- multirotor.optimize.get_controller(m: multirotor.simulation.Multirotor, scurve=False, args: argparse.Namespace = DEFAULTS) multirotor.controller.Controller¶
Create a multirotor.controller.Controller object with default values.
Note: max_acceleration, max_velocity, max_error_i etc are important parameters that are set as defaults.
Parameters¶
- mMultirotor
The vehicle to control.
- scurvebool, optional
Whether to use an SCurve trajectory planning approach, by default False
- argsNamespace, optional
The default settings, by default DEFAULTS
Returns¶
Controller
- multirotor.optimize.make_controller_from_trial(trial: optuna.Trial, args: argparse.Namespace = DEFAULTS, prefix='') dict¶
Makes a dictionary of parameters which can be used with the Controller.set_params()
Parameters¶
- trialoptuna.Trial
The trail with the suggest parameters.
- argsNamespace, optional
Namespace of optimization arguments, by default DEFAULTS
- prefixstr, optional
_description_, by default ‘’
Returns¶
- Dict
A dictionary of parameters to be used by Controller.set_params(**dict)
- multirotor.optimize.make_env(vp: multirotor.vehicle.VehicleParams, sp: multirotor.vehicle.SimulationParams, args: argparse.Namespace = DEFAULTS) multirotor.env.DynamicsMultirotorEnv¶
Make the environment instance to be used by objective(), and set default env parameters.
Parameters¶
vp : VehicleParams sp : SimulationParams args : Namespace, optional
Optimization params, by default DEFAULTS
Returns¶
DynamicsMultirotorEnv
- multirotor.optimize.make_objective(vp: multirotor.vehicle.VehicleParams, sp: multirotor.vehicle.SimulationParams, ctrl: multirotor.controller.Controller = None, args: argparse.Namespace = DEFAULTS) Callable¶
Make the function that optuna will use to optimize.
Parameters¶
vp : VehicleParams sp : SimulationParams ctrl: Controller, optional
The controller class to use. If not provided, get_controller is used with DEFAULTS to make a controller instance.
- argsNamespace, optional
Optimization params, by default DEFAULTS
- multirotor.optimize.optimize(vp: multirotor.vehicle.VehicleParams, sp: multirotor.vehicle.SimulationParams, ctrl: multirotor.controller.Controller = None, ntrials: int = 1000, args: argparse.Namespace = DEFAULTS, seed: int = 0, study_name: str = None, n_jobs: int = 1, timeout: float = None, verbosity=optuna.logging.WARNING) optuna.Study¶
Search over parameter space to optimize controller parameters in make_controller_from_trial().
Parameters¶
vp : VehicleParams sp : SimulationParams ctrl: Controller, optional
The controller class to use. If not provided, get_controller is used with DEFAULTS to make a controller instance.
- ntrialsint, optional
Number of trials, by default 1000
- argsNamespace, optional
Optimization params, by default DEFAULTS
- seedint, optional
Optimization seed, by default 0
- study_namestr, optional
Name of study to be saved in studies/study_name.db, by default None
- n_jobs: int, optional
Number of parallel optimization jobs to run. If -1, sets to number of processors. By default 1
- timeout: float, optional
Number of seconds to run the study for. By default, run until n_trials reached
- verbosity_type_, optional
Logging level of optuna.optimize(), by default optuna.logging.WARNING
Returns¶
- optuna.Study
The completed Study object with study.best_params which can be used by apply_params(Controller, **best_params) to get the optimized controller.
- multirotor.optimize.apply_params(ctrl: multirotor.controller.Controller, params: dict) Dict[str, Dict[str, numpy.ndarray]]¶
Apply parameters from an optuna.Study to a Controller. Converts the dictionary of best_params in the format accepted by controller.set_params()
Parameters¶
- ctrlController
The controller to which to apply the parameters. If None, just return the dictionary of parameters which Controller.set_params() can use.
- paramsdict[str, np.ndarray]
The dictionary of parameters returned by optuna.Study
Returns¶
- Dict[str, Dict[str, np.ndarray]]
A nested dictionary for Controller.set_params()
- multirotor.optimize.parser¶