This versatile Python-based engine is well suited for integrating components with a Python API, and in particular, in the cases where efficient data transmission is required. To this end, this engine employs protobuf messages over GRPC as a communication mechanism. The engine server is defined as a Python class based on GrpcEngineScript (as in the example listed below).
For a complete example of an nrp-core experiment using the Python GRPC Engine see examples/tf_exchange/simulation_config_grpc.json.
GrpcEngineScript
provides a base class from which custom Engines must inherit. The derived class must implement methods:
initialize()
: initialize the engine and registers required DataPacks with a protobuf message type.runLoop(timestep_ns)
: advance required simulation and communicate with other engines via TransceiverFunctions.shutdown()
: executed when the engine is requested to shutdown.Besides, GrpcEngineScript
provides the following ready-to-use methods and properties to handle datapack communication:
_time_ns
: returns the internal simulation time of the Engine in nanoseconds._registerDataPack(datapack_name, protobuf_type)
: registers a datapack to the engine with the name datapack_name
. Registered datapacks are stored in a python dictionary and can be accessed with _setDataPack
and _getDataPack
. protobuf_type must a Python Protobuf message type and is the expected type of the data stored in this datapack. The stored data will be updated, under the hood, from datapacks returned by TransceiverFunctions at every loop._getDataPack(datapack_name)
: returns "datapack_name" datapack data, as a protobuf message._setDataPack(datapack_name, data)
: sets "datapack_name" datapack data. "data" is always protobuf a message of type the registered for "datapack_name".Below is an example of a class inheriting from GrpcEngineScript
. The example is taken from the examples/tf_exchange
experiment.
The Python GRPC engine supports Protobuf DataPacks, which can be used to transfer information between the engine and TFs.
Any of the Protobuf message definitions compiled with nrp-core can be used in the Python GRPC Engine. These can be found in the folder nrp-core-msgs/protobuf/engine_proto_defs. Also it is possible to compile your own Protobuf message definitions from .proto files and use them with this Engine. See here for a full example showing how to compile .proto files and using the new message types in an NRPCore experiment including a Python GRPC Engine.
This engined is based on EngineBase and EngineGRPC schemas.
Name | Description | Type | Default | Required | Array |
---|---|---|---|---|---|
EngineName | Name of the engine | string | X | ||
EngineType | Engine type. Used by EngineLauncherManager to select the correct engine launcher | string | X | ||
EngineProcCmd | Engine Process Launch command | string | |||
EngineProcStartParams | Engine Process Start Parameters | string | [] | X | |
EngineEnvParams | Engine Process Environment Parameters | string | [] | X | |
EngineLaunchCommand | LaunchCommand with parameters that will be used to launch the engine process | object | {"LaunchType":"BasicFork"} | ||
EngineTimestep | Engine Timestep in seconds | number | 0.01 | ||
EngineCommandTimeout | Engine Timeout (in seconds). It tells how long to wait for the completion of the engine runStep. 0 or negative values are interpreted as no timeout | number | 0.0 |
Name | Description | Type | Default | Required | Array |
---|---|---|---|---|---|
ServerAddress | gRPC Server address. Should this address already be in use, simulation initialization will fail | string | localhost:9004 | ||
ProtobufPluginsPath | Path were to search for specified ProtobufPlugin libraries | string | |||
ProtobufPackages | Protobuf Packages containing protobuf msg types that will be exchanged by this Engine. It is assumed that these packages have been compiled with NRPCore | string | [] | X |
Name | Description | Type | Default | Required | Array |
---|---|---|---|---|---|
PythonFileName | Path to the Python script containing the engine definition | string | X |
As explained above, the schema used by the PythonGrpc engine inherits from EngineBase and EngineGRPC schemas. A complete schema for the configuration of this engine is given below: