releso.spor.SPORObjectCommandLine

class releso.spor.SPORObjectCommandLine(*, 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, execution_command: str, command_options: List[str] = None)

Bases: SPORObjectExecutor

Base definition of a SPORCommandLineObject. Can be instantiated.

Base class for all possible SPOR object classes which use the command line. This class is meant to add some default functionality, so that users do not need to add them themselves. These are:

  1. access to the (MPI) Multi-processors via

    ReLeSO.spor.MultiProcessor

  2. command line command

  3. additional flags

  4. working directory

  5. whether or not to use the

    SPOR Communication Interface

__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 runs the defined command line command.

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

execution_command

Command which calls the program/script for this SPOR step.

command_options

Command line options to add to the execution command.

multi_processor

Definition of the multi-processor.

use_communication_interface

whether or not to use the SPOR communication interface.

add_step_information

interface commandline options including the observations, info, done, reward

working_directory

Path to the directory in which the program should run, helpful for programs using relative paths.

name

name of the SPOR step.

stop_after_error

Whether to stop after this step if this step has thrown an error.

reward_on_error

Reward which is returned if any kind of error is thrown during completing the defined task.

reward_on_completion

Reward which is returned if the task completed with out an error.

run_on_reset

This boolean can disable the running of the task when a reset is performed.

additional_observations

How many additional observations does this object yield.

save_location

Definition of the save location of the logs and validation results.

logger_name

name of the logger.

command_options: List[str]

Command line options to add to the execution command. These do not include those from the communication interface these will be, if applicable, added separately.

execution_command: str

Command which calls the program/script for this SPOR step.

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 runs the defined command line command.

With the defined arguments adding if necessary multi-processing flags and the spor communication interface.

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) – Wanted core_count of the task to run. Defaults to 1.

  • 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