Multi-Cartpole

Ver. 1.3.3 (2023-02-22)

This module provides an environment with multivariate state and action spaces based on the OpenAI Gym environment ‘CartPole-v1’.

class mlpro.rl.pool.envs.multicartpole.MultiCartPole(p_num_envs=2, p_reward_type=0, p_visualize: bool = True, p_logging=True)

Bases: Environment

This environment multivariate space and action spaces by duplicating the OpenAI Gym environment ‘CartPole-v1’. The number of internal CartPole sub-enironments can be parameterized.

C_NAME = 'MultiCartPole'
C_LATENCY = datetime.timedelta(seconds=1)
C_INFINITY = 3.4028235e+38
C_PLOT_ACTIVE: bool = True
static load(p_path, p_filename)

Loads content from the given path and file name. If file does not exist, it returns None.

Parameters:
  • file (p_path Path that contains the) –

  • name (p_filename File) –

Returns:

A loaded object, if file content was loaded successfully. None otherwise.

switch_logging(p_logging)

Sets new log level.

Parameters:

p_logging – Log level (constant C_LOG_LEVELS contains valid values)

static setup_spaces()

Static template method to set up and return state and action space of environment.

Returns:

  • state_space (MSpace) – State space object

  • action_space (MSpace) – Action space object

collect_substates() State
get_cycle_limit()

Returns limit of cycles per training episode.

simulate_reaction(p_state: State, p_action: Action) State

Simulates a state transition based on a state and an action. The simulation step itself is carried out either by an internal custom implementation in method _simulate_reaction() or by an embedded external function.

Parameters:
  • p_state (State) – Current state.

  • p_action (Action) – Action.

Returns:

Subsequent state after transition

Return type:

State

compute_success(p_state: State) bool

Assesses the given state whether it is a ‘success’ state. Assessment is carried out either by a custom implementation in method _compute_success() or by an embedded external function.

Parameters:

p_state (State) – State to be assessed.

Returns:

success – True, if the given state is a ‘success’ state. False otherwise.

Return type:

bool

compute_broken(p_state: State) bool

Assesses the given state whether it is a ‘broken’ state. Assessment is carried out either by a custom implementation in method _compute_broken() or by an embedded external function.

Parameters:

p_state (State) – State to be assessed.

Returns:

broken – True, if the given state is a ‘broken’ state. False otherwise.

Return type:

bool

init_plot(p_figure: Figure | None = None, p_plot_settings: list = Ellipsis, p_plot_depth: int = 0, p_detail_level: int = 0, p_step_rate: int = 0, **p_kwargs)

Initializes the plot functionalities of the class.

Parameters:
  • p_figure (Matplotlib.figure.Figure, optional) – Optional MatPlotLib host figure, where the plot shall be embedded. The default is None.

  • p_plot_settings (PlotSettings) – Optional plot settings. If None, the default view is plotted (see attribute C_PLOT_DEFAULT_VIEW).

update_plot(**p_kwargs)

Updates the plot.

Parameters:

**p_kwargs – Implementation-specific plot data and/or parameters.