Wrappers

Index

DIAMBRA Arena comes with a large number of ready-to-use wrappers and examples showing how to apply them. They cover a wide spectrum of use cases, and also provide reference templates to develop custom ones. In order to activate wrappers, one has just to add an additional kwargs dictionary, here named wrappers_settings, to the environment creation method, as shown in the next code block. The dictionary has to be populated as described in the next sections.

env = diambra.arena.make("doapp", settings, wrappers_settings)

Implementation examples and templates can be found in the code repository, here.

Use of these functionalities can be found in this and this examples.

Generic Wrappers

NoOp Steps After Reset

KeyTypeDefault Value(s)Value RangeDescription
no_op_maxint0[0, 12]Performs a maximum of value No-Action steps after episode reset
wrappers_settings["no_op_max"] = 0

Observation Wrappers

Frame Warping

DEPRECATED: For speed, consider using the environment setting frame_shape that performs the same operation on the engine side, as described in this section.

KeyTypeDefault Value(s)Value RangeTarget Observation ElementDescription
hwc_obs_resizetuple of three int (H, W, C)(84, 84, 0)H, W: [1, 512]
C: 0, 1 or 3
FrameWarps the frame from original Game resolution to H X W size.
C values:
0 - Deactivated;
1 - Grayscale;
3 - RGB;
Keeps observation element of type Box, changes its shape
wrappers_settings["hwc_obs_resize"] = (128, 128, 1)

Frame Stacking With Optional Dilation

KeyTypeDefault Value(s)Value RangeTarget Observation ElementDescription
frame_stackint1[1, 48]FrameStacks latest value frames together along the third dimension.
Keeps observation element of type Box, changes its shape
dilationint1[1, 48]FrameBuilds frame stacks adding one every value frames.
Keeps observation element of type Box
wrappers_settings["frame_stack"] = 4
wrappers_settings["dilation"] = 1

Action Stacking

KeyTypeDefault Value(s)Value RangeTarget Observation ElementDescription
actions_stackint1[1, 48]Actions-Move,
Actions-Attack
Stacks latest value actions together for both moves and attacks.
Changes observation element type from Discrete to MultiDiscrete, having value elements, each with cardinality equal to the original Discrete one
wrappers_settings["actions_stack"] = 12

Scaling

KeyTypeDefault Value(s)Value RangeTarget Observation ElementDescription
scaleboolFalseTrue / FalseAllActivates observation scaling.
Affects observation elements as follows:
- Box: type kept, changes bounds according to scale_mod setting.
- Discrete (Binary): depends on process_discrete_binary (see below).
- Discrete: changed to MultiBinary through one-hot encoding, size equal to original Discrete cardinality.
- MultiDiscrete: changed to N-MultiBinary through N-times one-hot encoding, N equal to original MultiDiscrete size, encoding size equal to original MultiDiscrete element cardinality
exclude_image_scalingboolFalseTrue / FalseFrameIf True, prevents scaling to be applied on the game frame
process_discrete_binaryboolFalseTrue / FalseDiscrete BinaryControls how Discrete (Binary) observations are treated:
- False: not affected;
- True: changed to MultiBinary through one-hot encoding, size equal to 2
scale_modint0[0, 1]AllDefines the scaling bounds: 0 - [0, 1]; 1 - [-1, 1].
Keeps observation elements of the same type
wrappers_settings["scale"] = True
wrappers_settings["exclude_image_scaling"] = True
wrappers_settings["process_discrete_binary"] = True
wrappers_settings["scale_mod"] = 0

Flattening and Filtering

KeyTypeDefault Value(s)Value RangeTarget Observation ElementDescription
flattenboolFalseTrue / FalseRAM StatesActivates RAM States dictionary flattening, removing nested dictionaries and creating new keys joining original ones using “_” across nesting levels. For example: obs["P1"]["key1"] becomes obs["P1_key1"]
filter_keyslist of strNone-RAM StatesDefines the list of RAM states to keep in the observation space
wrappers_settings["flatten"] = True
wrappers_settings["filter_keys"] = ["stage", "P1_ownHealth", "P1_oppChar"]

Action Wrappers

Actions Sticking

KeyTypeDefault Value(s)Value RangeDescription
sticky_actionsint1[1, 12]Keeps repeating the same action for value environment steps

In order to use this wrapper, the step_ratio generic setting must be set to equal to 1.

wrappers_settings["sticky_actions"] = 1

Reward Wrappers

Reward Normalization

KeyTypeDefault Value(s)Value RangeDescription
reward_normalizationboolFalseTrue / FalseActivates reward normalization. Divides reward value by the product between the reward_normalization_factor (see next row) value and the delta between maximum and minium health bar value for the given game
reward_normalization_factorfloat0.5[-inf, +inf]Defines the normalization factor multiplying the delta between maximum and minium health bar value for the given game
wrappers_settings["reward_normalization"] = True
wrappers_settings["reward_normalization_factor"] = 0.5

Reward Clipping

KeyTypeDefault Value(s)Value RangeDescription
clip_rewardsboolFalseTrue / FalseActivates reward clipping. Applies the sign function to the reward value
wrappers_settings["clip_rewards"] = False