palaestrai.util package#

Submodules#

palaestrai.util.dynaloader module#

exception palaestrai.util.dynaloader.ErrorDuringImport(filename, exc_info)[source]#

Bases: Exception

Errors that occurred while trying to import something

palaestrai.util.dynaloader.load_with_params(module_path, params)[source]#

Load a class from module_path and pass params.

palaestrai.util.dynaloader.locate(path, forceload=0)[source]#

Locate an object by name or dotted path, importing as necessary.

palaestrai.util.dynaloader.safeimport(path, forceload=0, cache=None)[source]#

Import a module; handle errors; return None if the module isn’t found.

If the module is found but an exception occurs, it’s wrapped in an ErrorDuringImport exception and reraised. Unlike __import__, if a package path is specified, the module at the end of the path is returned, not the package at the beginning. If the optional ‘forceload’ argument is 1, we reload the module from disk (unless it’s a dynamic extension).

palaestrai.util.exception module#

exception palaestrai.util.exception.AgentConductorFailedError[source]#

Bases: Exception

Raised when an error during the execution of an agent conductor occurs.

exception palaestrai.util.exception.BrainMuscleConnectionFailedError[source]#

Bases: Exception

This error is raised if the palaestrai.agent.Brain is unable to connect to the given port, because the port is already used by another process.

exception palaestrai.util.exception.DeadChildrenRisingAsZombiesError[source]#

Bases: Exception

Raised when childrens died and starting to become zombies.

exception palaestrai.util.exception.EnvConductorFailedError[source]#

Bases: Exception

Raised when an error during the execution of an environment conductor occurs.

exception palaestrai.util.exception.EnvironmentHasNoUIDError[source]#

Bases: Exception

At least one environment in a multi-environment setup has no UID.

exception palaestrai.util.exception.ExperimentAlreadyRunningError[source]#

Bases: Exception

Raised during experiment start if experiment is already running.

exception palaestrai.util.exception.ExperimentSetupFailedError[source]#

Bases: Exception

Raised when the experiment setup failed.

exception palaestrai.util.exception.InitializationFailedError[source]#

Bases: Exception

Raised when initialization of an experiment failed.

exception palaestrai.util.exception.InvalidRequestError(expected, got)[source]#

Bases: Exception

Raised when a wrong request was received.

exception palaestrai.util.exception.InvalidResponseError(expected, got)[source]#

Bases: Exception

Raised when a wrong response was received.

exception palaestrai.util.exception.NoneInputError[source]#

Bases: Exception

None as Input

exception palaestrai.util.exception.OutOfActionSpaceError[source]#

Bases: Exception

This error is raised if an ActuatorInformation receives a value that is not contained in the action space of that actuator.

exception palaestrai.util.exception.OutOfObservationSpaceError[source]#

Bases: Exception

This error is raised if a SensorInformation is created with a value that is not contained in the observation space of that sensor.

exception palaestrai.util.exception.PrematureTaskDeathError[source]#

Bases: Exception

Raised when a tasks died before its time.

exception palaestrai.util.exception.ReplyIsNoneError[source]#

Bases: Exception

Raised when a reply is None.

exception palaestrai.util.exception.RequestIsNoneError[source]#

Bases: Exception

Raised when a request is None.

exception palaestrai.util.exception.SignalInterruptError[source]#

Bases: Exception

Raised when a signal was received.

exception palaestrai.util.exception.SimControllerFailedError[source]#

Bases: Exception

Raised when a simulation controller could not be started.

exception palaestrai.util.exception.SimulationSetupError(experiment_run_id, message)[source]#

Bases: RuntimeError

exception palaestrai.util.exception.TasksNotFinishedError[source]#

Bases: Exception

Raised when neither the signal_monitor_task nor the transceive_task returned.

exception palaestrai.util.exception.UnknownModeError[source]#

Bases: Exception

This error is raised if a palaestrai.agent.Muscle is receiving an unknown Mode.

palaestrai.util.logserver module#

A simple, built-in logging server

class palaestrai.util.logserver.LogServer(listen_host: str, listen_port: int)[source]#

Bases: object

A simple, internal logging server that reinjects remote log messages

Each submodule of palaestrAI that gets spawned lives in a separate process. As the ::~spawn_wrapper takes care of reinitializing the logger, it replaces all defined log handlers with a logging.SocketHandler. This log server is ran by the ::Executor and receives all those messages. They are re-injected in the main process’ logging system and treated according to the original logging configuration.

async start()[source]#
async stop()[source]#

palaestrai.util.seeding module#

palaestrai.util.seeding.create_seed(a: int | str | None = None, max_bytes: int = 8) int[source]#

Create a strong random seed. Otherwise, Python 2 would seed using the system time, which might be non-robust especially in the presence of concurrency.

Parameters:
  • a (Union[int, str, None]) – None seeds from an operating system specific randomness source.

  • max_bytes – Maximum number of bytes to use in the seed.

palaestrai.util.seeding.hash_seed(seed: int | None = None, max_bytes: int = 8) int[source]#

Any given evaluation is likely to have many PRNG’s active at once. (Most commonly, because the environment is running in multiple processes.) There’s literature indicating that having linear correlations between seeds of multiple PRNG’s can correlate the outputs:

http://blogs.unity3d.com/2015/01/07/a-primer-on-repeatable-random-numbers/ http://stackoverflow.com/questions/1554958/how-different-do-random-seeds-need-to-be http://dl.acm.org/citation.cfm?id=1276928

Thus, for sanity we hash the seeds before using them. (This scheme is likely not crypto-strength, but it should be good enough to get rid of simple correlations.)

Parameters:
  • seed (Optional[int]) – None seeds from an operating system specific randomness source.

  • max_bytes – Maximum number of bytes to use in the hashed seed.

palaestrai.util.seeding.int_to_seed(a: int, max_bytes: int) int[source]#

Turns integer into a seed.

Parameters:
  • point (a Seed starting) –

  • seed (max_bytes Maximum number of bytes to use in the) –

Return type:

a Seed

palaestrai.util.seeding.np_random(seed: int | None = None) Tuple[RandomState, int][source]#

palaestrai.util.spawn module#

async palaestrai.util.spawn.spawn_wrapper(name: str, runtime_config: dict, callee: Callable, args: list | None = None, kwargs: dict | None = None) Any[source]#

Wraps a target for fork/spawn and takes care of initialization.

Whenever a new subprocess is created (regardless of whether spawn, fork, or forkserver is used), some caretaking needs to be done:

  • The runtime configuration needs to be transferred, and the

    ::RuntimeConfig properly reinitialized

  • Logging is reinitialized/rewired to send messages to the parent process

  • A proctitle is set

Parameters:
  • name (*) – Name of the process; will lead to a proctitle in the form of palaestrai[%s]

  • runtime_config (*) – Runtime configuration dict, normally obtained from ::RuntimeConfig.to_dict

  • callee (*) – The target method

  • args (*) – Positional arguments of ::callee.

  • kwargs (*) – Keyword arguments of ::callee

Returns:

Whatever the target function returns.

Return type:

Any

Module contents#