Backend

class eagerx.core.entities.Backend(ns, backend_type, entity_id, log_level, main=False, sync=None, real_time_factor=None, simulate_delays=None, **kwargs)[source]

Baseclass for backends.

Use this baseclass to implement backends that implement the communication.

Users must use make() to make the registered subclass’ specification.

Subclasses must implement the following methods:

Subclasses must set the following static class properties:

abstract Publisher(address, dtype)[source]

Creates a publisher.

Parameters
  • address (str) – Topic name.

  • dtype (str) – Dtype of message in string format (e.g. float32).

Return type

Publisher

abstract Subscriber(address, dtype, callback, header=False, callback_args=())[source]

Creates a subscriber.

Parameters
  • address (str) – Topic name.

  • dtype (str) – Dtype of message in string format (e.g. float32).

  • callback – Function to call ( fn(data)) when data is received. If callback_args is set, the function must accept the callback_args as positional args, i.e. fn(data, header, *callback_args).

  • header (bool) – Set to True if the callback accepts the header as the second positional argument.

  • callback_args (Optional[Tuple]) – Additional arguments to pass to the callback.

Return type

Subscriber

abstract delete_param(param, level=1)[source]

Deletes params from the parameter server.

Parameters
  • param (str) – Parameter name.

  • level (int) –

    Determines what to do when the param does not exist:

    • 0=error: Raises a BackendException.

    • 1=warn: logs a warning and returns None.

    • 2=pass: passes silently and returns None.

Return type

None

static deserialize_time(secs, nsecs)[source]

Convert a secs and nsecs time instance into float time in seconds .

Should be used when manually setting secs/nsecs slot values for deserialization.

Return type

float

abstract get_param(name, default=<eagerx.core.constants.Unspecified object>)[source]

Retrieve a parameter from the param server

Parameters
  • name (str) – Parameter name.

  • default (Any) – Default value to return.

Return type

Union[Dict, List, bool, float, int, str]

classmethod info(method=None)

A helper method to get info on a method of the specified subclass.

Parameters

method (Union[List[str], str, None]) – The registered method we would like to receive info on. If no method is specified, it provides info on the class itself.

Return type

str

Returns

Info on the subclass’ method.

abstract initialize(spec)[source]

An abstract method to initialize the backend.

Parameters

spec (BackendSpec) – Specification of the node/engine.

Return type

None

abstract classmethod make(*args, **kwargs)

An abstract method that makes the specification (also referred to as spec) of this entity.

Parameters
  • args (Any) – Arguments to the subclass’ make function.

  • kwargs (Any) – Optional Arguments to the subclass’ make function.

Returns

A (mutable) spec that can be used to build and subsequently initialize the entity (e.g. node, engine, …).

now()[source]

Get the current times according to the simulated and wall clock

Return type

Tuple[float, float]

abstract register_environment(name, force_start, fn)[source]

Checks if environment already exists and shuts it down if force_restart is set. Then, it registers the remote shutdown procedure for the newly created environment.

Parameters
  • name (str) – Environment name (i.e. namespace of the environment).

  • force_start (bool) – Whether to shutdown any environment with the same name if it already exists.

  • fn (Callable) – Function with zero args to be called on remote shutdown.

Return type

ShutdownService

static serialize_time(t)[source]

Convert a float time instance (in seconds) into secs and nsecs.

Should be used when manually setting secs/nsecs slot values for serialization.

Return type

Tuple[int, int]

shutdown()[source]

Shuts down the backend

Return type

None

abstract spin()[source]

Blocks until node is shutdown. Yields activity to other threads.

Return type

None

abstract upload_params(ns, values, verbose=False)[source]

Upload params to the parameter server.

Parameters
  • ns (str) – Namespace to load parameters into, str.

  • values (Dict[str, Union[Dict, List, bool, float, int, str]]) – Key/value dictionary, where keys are parameter names and values are parameter values, dict.

  • verbose (bool) – Verbosity level.

Return type

None

abstract property BACKEND: str

Backend name in string format.

Return type

str

abstract property COLAB_SUPPORT: bool

Whether the backend supports running on Google colab.

Return type

bool

abstract property DISTRIBUTED_SUPPORT: bool

Whether nodes can be launched on external platforms (i.e. distributed communication).

Return type

bool

abstract property MULTIPROCESSING_SUPPORT: bool

Whether nodes can be launched as separate processes.

Return type

bool

backend_type: str

The class definition of the subclass. Follows naming convention <module>/<BackendClassName>. Cannot be modified.

entity_id: str

A unique entity_id with the structure <module>/<classname>.

log_level: int

Specifies the effective log level: {0: SILENT, 10: DEBUG, 20: INFO, 30: WARN, 40: ERROR, 50: FATAL}. Can be set in the subclass’ spec().

main: bool

If True, the backend is the ‘main` backend that corresponds to the environment process.

ns: str

Namespace of the environment. Can be set with the name argument to BaseEnv.

real_time_factor: float

A specified upper bound on the real_time factor. Wall-clock rate=real_time_factor*rate. If real_time_factor < 1 the simulation is slower than real time.

simulate_delays: bool

Flag that specifies whether input delays are simulated. You probably want to set this to False when running in the real-world.

sync: bool

Flag that specifies whether we run synchronous or asynchronous.