releso.spor.SPORObjectInternalPythonFunction

class releso.spor.SPORObjectInternalPythonFunction(*, 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, function_name: Literal['xns_cnn'])

Bases: SPORObjectPythonFunction

This class will load SPOR functions provided by this package.

Currently available functions are the following:

  • xns_cnn: This function will use the result of the xns solver and

    create an image of the solution. The image is created via contourf.

__init__(**kwargs)

Internalized python function init function.

Initializes the function and adds the observation data.

Raises:

ValueError – Requested function not found.

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

function_name

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.

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.

  1. args: Namespace see SPORCommInterface

  2. logger: logger to be used in the function

  3. 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