releso.spor.SPORObjectPythonFunction
- class releso.spor.SPORObjectPythonFunction(*, save_location: Path, logger_name: str | None = None, name: str, stop_after_error: bool = True, reward_on_error: float, reward_on_completion: float | None = None, run_on_reset: bool = True, additional_observations: ObservationDefinition | ObservationDefinitionMulti | List[ObservationDefinition | ObservationDefinitionMulti] | None = None, multi_processor: MultiProcessor | MPIClusterMultiProcessor | None = None, use_communication_interface: bool = False, add_step_information: bool = False, working_directory: str)
Bases:
SPORObjectExecutorBase definition of a SPORObjectPythonFunction. Parent class.
Base class for all possible SPOR python object classes which use internalized python function mechanism. This class is meant to add some default functionality, so that users do not need to add them themselves. These are:
Let an internalized python function be run and save the function data
working directory
- whether or not to use the
- __init__(**data: Any) None
Constructor for the ReLeSO basemodel object.
Methods
convert_to_pathlib_add_datetime(v)Add timestamp to save_location, of applicable.
get_default_observation(observations)Generate default observations if no were returned or step failed.
get_logger()Gets the currently defined environment logger.
get_multiprocessing_prefix(core_count)Add commandline prefix for mpi multiprocessor.
get_observations()Return number of observation the step generates.
run(step_information, environment_id[, ...])This function loads and executes the defined python file.
set_logger_name_recursively(logger_name)Set the logger_name variable for all child elements.
setup_working_directory(environment_id)Set up the working directory for the SPORStep.
spor_com_interface(reset, environment_id, ...)Add spor com interface command line options.
spor_com_interface_add(returned_step_dict, ...)Add returned step information of the spor com interface.
spor_com_interface_read(output, step_dict)Read in return values of the spor com interface.
Attributes
multi_processorDefinition of the multi-processor.
use_communication_interfacewhether or not to use the SPOR communication interface.
add_step_informationinterface commandline options including the observations, info, done, reward
working_directoryPath to the directory in which the program should run, helpful for programs using relative paths.
namename of the SPOR step.
stop_after_errorWhether to stop after this step if this step has thrown an error.
reward_on_errorReward which is returned if any kind of error is thrown during completing the defined task.
reward_on_completionReward which is returned if the task completed with out an error.
run_on_resetThis boolean can disable the running of the task when a reset is performed.
additional_observationsHow many additional observations does this object yield.
save_locationDefinition of the save location of the logs and validation results.
logger_namename of the logger.
- run(step_information: Tuple[ndarray | Dict[str, ndarray] | Tuple[ndarray, ...], float, bool, Dict], environment_id: UUID4, validation_id: int | None = None, core_count: int = 1, reset: bool = False) Tuple[ndarray | Dict[str, ndarray] | Tuple[ndarray, ...], float, bool, Dict]
This function loads and executes the defined python file.
The herein defined python file needs to have a function called main with three parameters.
args: Namespace see SPORCommInterface
logger: logger to be used in the function
func_data: data variable can be used to store persistent data
- Parameters:
step_information (StepReturnType) – Previously collected step values. Should be up-to-date.
environment_id (UUID4) – Environment ID which is used to distinguish different environments which run in parallel.
validation_id (Optional[int], optional) – During validation the validation id signifies the validation episode. If none the current episode is not a validation episode. Defaults to None.
core_count (int, optional) – Can only be one since no multi processing is possible in this case.
reset (bool, optional) – Boolean on whether or not this object is called because of a reset. Defaults to False.
- Returns:
The full compliment of the step information are returned. The include observation, reward, done, info.
- Return type:
StepReturnType