stable_learning_control.disturbers

Contains the disturbers that are available in the SLC package.

Note

These disturbers are implemented as gymnasium:gymnasium wrappers <api/wrappers/>. Because of this, they can be used with any gymnasium environment. If you want to add a new disturber, you only have to ensure that it is a Python class that inherits from the gym.Wrapper class.

Submodules

Classes

ActionImpulseDisturber

A gymnasium wrapper that can be used to disturb the action of a gymnasium

ActionRandomNoiseDisturber

A gymnasium wrapper that can be used to disturb the action of a gymnasium

EnvAttributesDisturber

A gymnasium wrapper that can be used to disturb a physics parameter of a

ObservationRandomNoiseDisturber

A gymnasium wrapper that can be used to disturb the observation of a gymnasium

Package Contents

class stable_learning_control.disturbers.ActionImpulseDisturber(env, magnitude, time)[source]

Bases: gymnasium.ActionWrapper

A gymnasium wrapper that can be used to disturb the action of a gymnasium environment with a impulse applied at a certain time step.

impulse_magnitude

The magnitude of the impulse.

Type:

float

impulse_time

The time (s) at which to apply the impulse.

Type:

float

Initialise the ActionImpulseDisturber object.

Parameters:
  • env (gym.Env) – The gymnasium environment.

  • magnitude (float) – The impulse magnitude to apply.

  • time (float) – The time (s) at which to apply the impulse.

time_warning = False
time_step_warning = False
_track_time = False
_time_step_attr = None
_time_attr = None
magnitude
impulse_time
max_episode_steps
track_time()[source]

Track the time of the environment.

action(action)[source]

Add a impulse to the action.

Parameters:

action (np.ndarray) – The action.

Returns:

The action with added impulse.

Return type:

np.ndarray

class stable_learning_control.disturbers.ActionRandomNoiseDisturber(env, mean, std)[source]

Bases: gymnasium.ActionWrapper

A gymnasium wrapper that can be used to disturb the action of a gymnasium environment with normally distributed random noise.

mean

The mean of the noise normal distribution.

Type:

float

std

The standard deviation of the noise normal distribution.

Type:

float

Initialise the ActionRandomNoiseDisturber object.

Parameters:
  • env (gym.Env) – The gymnasium environment.

  • mean (float) – The mean of the noise normal distribution.

  • std (float) – The standard deviation of the noise normal distribution.

mean
std
action(action)[source]

Add normally distributed random noise to the action.

Parameters:

action (np.ndarray) – The action.

Returns:

The action with added noise.

Return type:

np.ndarray

class stable_learning_control.disturbers.EnvAttributesDisturber(env, attributes, values)[source]

Bases: gymnasium.Wrapper

A gymnasium wrapper that can be used to disturb a physics parameter of a gymnasium environment.

disturbance_label

A label for the disturbance that can be used for logging or plotting. Used in the eval_robustness utility.

Type:

str

Initialise the EnvAttributesDisturber object.

Parameters:
  • env (gym.Env) – The gymnasium environment.

  • attributes (list) – A list of attributes to disturb.

  • values (list) – A list of values to set the parameters to.

Raises:
  • ValueError – The number of parameters and values must be the same.

  • AttributeError – The parameter does not exist in the environment.

attributes
values
class stable_learning_control.disturbers.ObservationRandomNoiseDisturber(env, mean, std)[source]

Bases: gymnasium.ObservationWrapper

A gymnasium wrapper that can be used to disturb the observation of a gymnasium environment with normally distributed random noise.

mean

The mean of the noise normal distribution.

Type:

float

std

The standard deviation of the noise normal distribution.

Type:

float

Initialise the ObservationRandomNoiseDisturber object.

Parameters:
  • env (gym.Env) – The gymnasium environment.

  • mean (float) – The mean of the noise normal distribution.

  • std (float) – The standard deviation of the noise normal distribution.

mean
std
observation(observation)[source]

Add normally distributed random noise to the observation.

Parameters:

observation (np.ndarray) – The observation.

Returns:

The observation with added noise.

Return type:

np.ndarray