Skip to content

Composite operator

Julien Loudet edited this page Jan 22, 2025 · 2 revisions

To facilitate the reuse and combination of Operators (and only Operators), 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 subtracts a constant to it:

    description: subtract a configurable constant
    
    vars:
      BASE_PATH: file:///home/zenoh-flow/nodes
      DLL_EXTENSION: so
    
    configuration:
      constant: 0
      
    inputs:
    - in
    
    outputs:
    - out
      
    library: "{{ BASE_PATH }}/subtract/libsubtract.{{ DLL_EXTENSION }}"
  2. An operator that receives a float and divides it by a constant:

    description: divide by a configurable constant
    
    vars:
      BASE_PATH: file:///home/zenoh-flow/nodes
      DLL_EXTENSION: so
    
    configuration:
      constant: 1
      
    inputs:
    - in
      
    outputs:
    - out
      
    library: "{{ BASE_PATH }}/divide/libdivide.{{ 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:

description: fahrenheit-to-celsius conversion combining the subtract and divide Operators

vars:
  BASE_PATH: file:///home/zenoh-flow/nodes

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

- id: divide
  descriptor: "{{ BASE_PATH }}/divide/divide.yaml"
  configuration:
    constant: 1.8

# Inline declaration of Operators are also supported:
# - id: inline
#   configuration:
#     foo: 42
#   library: "{{ BASE_PATH }}/inline/libinline.{{ DLL_EXTENSION }}"
#   inputs:
#     - in
#   outputs:
#     - out
  
links:
- from:
    node: subtract
    output: out
  to:
    node: divide
    input: in

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

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

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