Functional

bsk_rl.utils.functional: General utility functions.

valid_func_name(name: str) str[source]

Convert a string into a valid function name.

Parameters:

name (str) – Desired function name.

Returns:

Sanitized function name.

Return type:

str

safe_dict_merge(updates: dict, base: dict) dict[source]

Merge a dict with another dict, warning for conflicts.

>>> safe_dict_merge(dict(a=1, b=2), dict(b=2, c=3))
{'a': 1, 'b': 2, 'c': 3}

>>> safe_dict_merge(dict(a=1, b=4), dict(b=2, c=3))
Warning: Conflicting values for b: overwriting 2 with 4
{'a': 1, 'b': 4, 'c': 3}
Parameters:
  • updates (dict) – Dictionary to be added to base.

  • base (dict) – Base dictionary to be modified.

Returns:

Updated copy of base.

Return type:

dict

default_args(**defaults) Callable[source]

Decorate function to enumerate default arguments for collection.

Return type:

Callable

collect_default_args(object: object) dict[str, Any][source]

Collect all function default_args in an object.

Parameters:

object (object) – Object with default_args-decorated functions.

Returns:

Dict of keyword-value pairs of default arguments.

Return type:

dict

vectorize_nested_dict(dictionary: dict) tuple[list[str], ndarray][source]

Flattens a dictionary of dictionaries, arrays, and scalars into a vector.

Parameters:

dictionary (dict)

Return type:

tuple[list[str], ndarray]

aliveness_checker(func: Callable[[...], bool]) Callable[[...], bool][source]

Decorate function to evaluate when checking for satellite aliveness.

Parameters:

func (Callable[[...], bool])

Return type:

Callable[[…], bool]

check_aliveness_checkers(model: Any, log_failure=False) bool[source]

Evaluate all functions with @aliveness_checker in a model.

Parameters:
  • model (Any) – Model to search for checkers in.

  • log_failure – Whether to log to the logger on checker failure.

Returns:

Model aliveness status.

Return type:

bool

is_property(obj: Any, attr_name: str) bool[source]

Check if obj has an @property called attr_name without calling it.

Parameters:
  • obj (Any)

  • attr_name (str)

Return type:

bool

class AbstractClassProperty[source]

Bases: object

Assign a class property to act like an abstract field.

class Resetable[source]

Bases: object

Base class for resetable objects.

This class is used to define objects that are reset at the beginning of each episode. These include Scenario, GlobalReward, CommunicationMethod, and Satellite.

The reset method takes the following steps:

  1. reset_overwrite_previous - Overwrite attributes from previous episode.

  2. reset_pre_sim_init - Reset before simulator initialization.

  3. Initialize a new Basilisk simulator.

  4. reset_post_sim_init - Reset after simulator initialization.

reset_overwrite_previous() None[source]

Overwrite attributes from previous episode.

Return type:

None

reset_pre_sim_init() None[source]

Reset before simulator initialization.

Return type:

None

reset_post_sim_init() None[source]

Reset after simulator initialization.

Return type:

None