Motor Dashboard
Usage Guide
To use the dashboard, you have to import the class, define the plots, instantiate the dashboard and pass it to the environment.
The most common plots can be quickly selected directly in the constructor of the dashboard. Further plots like a MeanEpisodeRewardPlot or self-defined ones have to be instantiated and passed to the dashboard.
import gym_electric_motor as gem
from gym_electric_motor.visualization import MotorDashboard
from gym_electric_motor.visualization.motor_dashboard_plots import MeanEpisodeRewardPlot
# create the dashboard and define the plots
dashboard = MotorDashboard(
state_plots = ['omega', 'i'], # Pass a list of state names or 'all' for all states to plot
reward_plot = True, # True / False (False default)
action_plots = [0] # 'all' plots all actions (if multiple are applied)
additional_plots=[MeanEpisodeRewardPlot()] # Add all further plots here
)
# pass it to the environment
env = gem.make('my-env-id-v0', visualization=dashboard)
Motor Dashboard API
- class gym_electric_motor.visualization.motor_dashboard.MotorDashboard(render_mode=None, *args, **kwargs)[source]
- Parameters:
state_plots ('all'/iterable(str)) – An iterable of state names to be shown. If ‘all’ all states will be shown. Default: () (no plotted states)
action_plots ('all'/iterable(int)) – If action_plots=’all’, all actions will be plotted. If more than one action can be applied on the environment it can be selected by its index. Default: () (no plotted actions).
reward_plot (boolean) – Select if the current reward is to be plotted. Default: False
additional_plots (iterable((TimePlot/EpisodePlot/StepPlot))) – Additional already instantiated plots to be shown on the dashboard
update_interval (int > 0) – Amount of steps after which the plots are updated. Updating each step reduces the performance drastically. Default: 1000
time_plot_width (int > 0) – Width of the step plots in steps. Default: 10000 steps (1 second for continuously controlled environments / 0.1 second for discretely controlled environments)
style (string) – Select one of the matplotlib-styles. e.g. “dark-background”. Default: None (the already selected style)
- initialize()
Called with first render() call to setup the figures and plots.
- on_reset_begin()
Called before the environment is reset. All subplots are reset.
- on_reset_end(state, reference)
Called after the environment is reset. The initial data is passed.
- Parameters:
state (array(float)) – The initial state \(s_0\).
reference (array(float)) – The initial reference for the first time step \(s^*_0\).
- on_step_begin(k, action)
The information about the last environmental step is passed.
- Parameters:
k (int) – The current episode step.
action (ndarray(float) / int) – The taken action \(a_k\).
- on_step_end(k, state, reference, reward, terminated)[source]
The information after the step is passed
- Parameters:
k (int) – The current episode step
state (array(float)) – The state of the env after the step \(s_k\).
reference (array(float)) – The reference corresponding to the state \(s^*_k\).
reward (float) – The reward that has been received for the last action that lead to the current state \(r_{k}\).
terminated (bool) – Flag, that indicates, if the last action lead to a terminal state \(t_{k}\).
- render()
Updates the plots every update cycle calls of this method.
- reset_figures()
Method to reset the figures to the initial state.
This method can be called, when the plots shall be reset after the training and before the test, for example. Another use case, that requires the call of this method by the user, is when the dashboard is executed within a jupyter notebook and the figures shall be plotted below a new cell.
- set_env(env)[source]
Called during initialization of the environment to interconnect all modules. State names, references,… might be saved here for later processing
- Parameters:
env (ElectricMotorEnvironment) – The environment.
- property update_interval
Number of steps until the visualization is updated