Utils

gym_electric_motor.utils.set_state_array(input_values, state_names)[source]

Setting of the input values to a valid state array with the shape of the physical systems state.

The input values can be passed as dict with state_name: value pairs or as list / ndarray. In the latter case the shape of the list has to fit the state_names shape and the list will just be returned as array. If a float is passed as input value, then this value will be set onto all positions of the state array equally.

Parameters:
  • input_values (dict(float) / list(float) / ndarray(float) / float) – Values to be set onto the state array.

  • state_names (list(str)) – List containing the state names of the physical system.

Returns:

An initialized state array with all values passed in input values set onto the corresponding position in the state_names and zero otherwise.

gym_electric_motor.utils.state_dict_to_state_array(state_dict, state_array, state_names)[source]

Mapping of a passed state dictionary to a fitting state array.

This function is mainly used in the initialization phase to map a dictionary of passed state_name, state_value pairs to a numpy state array with the entries of the state_dict at the corresponding places of the state_names.

Parameters:
  • state_dict (dict) – Dictionary containing pairs of state_name, state_values for the state_array

  • state_array (iterable) – Array into which the state_dict entries shall be passed

  • state_names (list/ndarray(str)) – List of the state names.

gym_electric_motor.utils.update_parameter_dict(source_dict, update_dict, copy=True)[source]

Merges two dictionaries (source and update) together.

It is similar to pythons dict.update() method. Furthermore, it assures that all keys in the update dictionary are already present in the source dictionary. Otherwise a KeyError is thrown.

Parameters:
  • source_dict (dict) – Source dictionary to be updated.

  • update_dict (dict) – The new dictionary with the entries to update the source dict.

  • copy (bool) – Flag, if the source dictionary shall be copied before updating. (Default True)

Returns:

The updated source dictionary.

Return type:

dict

Exceptions:

KeyError: Thrown, if a key in the update dict is not available in the source dict.