Skip to content

Composite operator

Julien Loudet edited this page Jan 3, 2023 · 1 revision

For easy reuse and combination of Operators (and only Operators, for now), Zenoh-Flow supports Composite Operator descriptor. The purpose is to merge several Operators in a single descriptor file, producing a "meta"-Operator that can be used in a data flow descriptor.

For the sake of explanation, let us assume that you already implemented the following two operators:

  1. an operator that receives a float and subtract a constant (configured through its configuration) to it,

    id: subtract
    
    vars:
      BASE_PATH: /home/zenoh/dev/nodes
      LIB_PATH: target/release/lib
      DLL_EXTENSION: so
    
    configuration:
      constant: 0
      
    inputs:
    - id: in
      type: float
    
    outputs:
    - id: out
      type: float
      
    uri: "file://{{ BASE_PATH }}/subtract/{{ LIB_PATH }}subtract.{{ DLL_EXTENSION }}"
  2. an operator that receives a float and divides it by a constant (also configured through its configuration).

    id: divide
    
    vars:
      BASE_PATH: /home/zenoh/dev/nodes
      LIB_PATH: target/release/lib
      DLL_EXTENSION: so
    
    configuration:
      constant: 1
      
    inputs:
    - id: in
      type: float
      
    outputs:
    - id: out
      type: float
      
    uri: "file://{{ BASE_PATH }}/divide/{{ LIB_PATH }}divide.{{ DLL_EXTENSION }}"

Leveraging these two operators, we could easily create an Operator that converts a temperature expressed in Fahrenheit to Celsius:

  1. we first subtract 32,
  2. we then divide the result by 1.8.

Which would give the composite operator:

id: fahrenheit-to-celsius

vars:
  BASE_PATH: /home/zenoh/dev/nodes

inputs:
- id: in-f2c
  node: subtract
  input: in
  
outputs:
- id: out-f2c
  node: divide
  output: out
  
operators:
- id: subtract
  descriptor: "file://{{ BASE_PATH }}/subtract/subtract.yaml"
  configuration:
    constant: 32
- id: divide
  descriptor: "file://{{ BASE_PATH }}/divide/divide.yaml"
  configuration:
    constant: 1.8
  
links:
- from:
    node: subtract
    output: out
  to:
    node: divide
    input: in

As one can see, the descriptor is a mix between that of a data flow and an Operator:

  • like a data flow descriptor, it has an operators and a links section,
  • like an Operator descriptor, it has an inputs and an outputs section.

The inputs and outputs sections differ to regular Nodes in that they must specify an id. These id are the ones that must be use in a data flow (or other composite Operator).

Clone this wiki locally