stable_gym.common.utils
Utility functions that are used in multiple Stable Gym gymnasium environments.
Functions
|
Colorize a string. |
|
Retrieves all the values that are present in a nested dictionary and appends them |
|
Retrieves all the keys that are present in a nested dictionary and appends them |
|
Creates unique abbreviations for a string or list of strings. |
|
Retrieves the lowest next integer that is not present in a string or float list. |
|
Transforms a list to a human friendly format (separated by commas and ampersand). |
|
Strips leading and/or trailing underscores from a string. |
|
Injects a value into a list or dictionary if it is not yet present. |
Verify parameter is a single number and cast to a float. |
|
|
This function can be called during a reset() to customize the sampling |
|
Changes the key of a dictionary. |
|
Converts a gym box space to a gymnasium box space. |
|
Changes the precision of a value. |
Module Contents
- stable_gym.common.utils.colorize(string, color, bold=False, highlight=False)[source]
Colorize a string.
See also
This function wraps the
gym.utils.colorize()
function to make sure that it also works with empty color strings.- Parameters:
- Returns:
Colorized string.
- Return type:
- stable_gym.common.utils.get_flattened_values(input_obj)[source]
Retrieves all the values that are present in a nested dictionary and appends them to a list. Its like a recursive version of the
dict.values()
method.
- stable_gym.common.utils.get_flattened_keys(input_obj, include_root=False)[source]
Retrieves all the keys that are present in a nested dictionary and appends them to a list. Its like a recursive version of the
dict.keys()
method.
- stable_gym.common.utils.abbreviate(input_item, length=1, max_length=4, capitalize=True)[source]
Creates unique abbreviations for a string or list of strings.
- Parameters:
input_item (union[str, list]) – The string of list of strings which you want to abbreviate.
length (int, optional) – The desired length of the abbreviation. Defaults to
1
.max_length (int, optional) – The maximum length of the abbreviation. Defaults to 4.
capitalize (bool, optional) – Whether the abbrevaitions should be capitalized. Defaults to True.
- Returns:
List with abbreviations.
- Return type:
- stable_gym.common.utils.get_lowest_next_int(input_item)[source]
Retrieves the lowest next integer that is not present in a string or float list.
- stable_gym.common.utils.friendly_list(input_list, apostrophes=False)[source]
Transforms a list to a human friendly format (separated by commas and ampersand).
- stable_gym.common.utils.strip_underscores(text, position='all')[source]
Strips leading and/or trailing underscores from a string.
- stable_gym.common.utils.inject_value(input_item, value, round_accuracy=2, order=False, axis=0)[source]
Injects a value into a list or dictionary if it is not yet present.
- Parameters:
input_item (union[list,dict]) – The input list or dictionary.
value (float) – The value you want to inject.
round_accuracy (int, optional) – The accuracy used for checking whether a value is present. Defaults to 2.
order (bool, optional) – Whether the list should be ordered when returned. Defaults to
false
.axis (int, optional) – The axis along which you want to inject the value. Only used when the input is a numpy array. Defaults to
0
.
- Returns:
The list or dictionary that contains the value.
- Return type:
- stable_gym.common.utils.verify_number_and_cast(x)[source]
Verify parameter is a single number and cast to a float.
- stable_gym.common.utils.maybe_parse_reset_bounds(options, default_low, default_high)[source]
This function can be called during a reset() to customize the sampling ranges for setting the initial state distributions.
- Parameters:
options – Options passed in to reset().
default_low – Default lower limit to use, if none specified in options.
default_high – Default upper limit to use, if none specified in options.
- Returns:
a tuple containing:
low (
np.ndarray
): Lower limit for each dimension.high ():obj:np.ndarray): Upper limit for each dimension.
- Return type:
(tuple)
- stable_gym.common.utils.change_dict_key(d, old_key, new_key, default_value=None)[source]
Changes the key of a dictionary.
- stable_gym.common.utils.convert_gym_box_to_gymnasium_box(gym_box_space, **kwargs)[source]
Converts a gym box space to a gymnasium box space.
- Parameters:
gym_box_space (gym.spaces.Box) – The gym box space.
**kwargs – Additional keyword arguments that are passed to the gymnasium box space.
- Returns:
The gymnasium box space.
- Return type:
gymnasium.spaces.Box