Component definition

AI SDK Operation Manual

Portfolio
Industrial AI
Product
AI Software Development Kit
Software version
v2.4
Edition
04/2025
Language
English

In this context, a component means a pipeline step that consumes input data, processes that data by using a model, and produces the output data. The model can mean, in a narrower sense, an ML model such as a neural network or the random forest algorithm, or simply an aggregator or other pre- or postprocessing logic. In every case, a Python script, hereinafter referred to as the 'entrypoint', establishes the connection between the model and the AI Inference Server. The server needs to receive information about what Python environment is required to execute the code, including the required Python packages or file resources.

Essential information for the execution of the code

The most essential information for the execution of the code is:

  • The Python script that receives the input data

  • The Python version required to run the Python script

  • The input and output variables of the component

Example

The following code shows how to define component settings. The created configuration can be checked in the pipeline-config.yml which can be found in the Examples (Page 43) section. Please note that this code is only used to create the pipeline configuration package, but it is not contained in the package itself.

create_pipeline_config_package.py
from simaticai import deployment

# defining basic properties of the pipeline component
# AI Inference Server version 2.3 supports both Python 3.10 and 3.11
component = deployment.PythonComponent(name='classifier', version='1.0.0', python_version='3.10')

 defining entrypoint Python script
component.add_resources("../src", "entrypoint.py")
component.set_entrypoint('entrypoint.py')

 defining input variable of component
component.add_input(name='input_1', _type='Double')
component.add_input(name='input_2', _type='Double')

 defining output variable of component
component.add_output(name='class_label', _type='Integer')
component.add_output(name='confidence', _type='Double')

In this example, the code uses a pre-trained scikit-learn model that is stored in a joblib file. The file acts as a resource file in this model. For more details about resource files, see the File Resources section. The code also uses external Python modules (Page 32) that must be deployed and installed on the AI Inference Server.

 adding stored scikit-learn model as a resource file
component.add_resources('..', 'models/classifier-model.joblib')

 adding python dependency scikit-learn with version==1.0.1
component.add_dependencies([('scikit-learn', '1.0.1')])

With this configuration, the AI Inference Server collects data for input_1 and input_2. When the data is available, the server wraps it into a data payload and calls the process_input() function in entrypoint.py. Once the data is processed and the class_label and confidence results are calculated, the function generates a return value.

Batch input processing

To make input processing faster, batch input processing can be enabled on a component. In this case the entrypoint's process_data(data) method will receive a list of dictionaries instead of a single dictionary. The dictionaries contain a single datapoint with the declared component inputs as keys. The items in the list can be processed by the Python script within a loop. Without batch input processing a global variable is required which stores the previous input values until a certain windows size is reached. With batch input this global variable can be avoided, making it more memory efficient.

Between components, batch inputs and outputs can be used, but the last component of the pipeline must return a single dictionary, therefore batch output must be disabled for it.

If the input of the pipeline is configured for batch processing, it is recommended not to configure timeshifting, as the list will have the same timestamp for all elements, potentially resulting in data loss.

Example usage:

# Enabling batch input on a component:
component.batch.inputBatch = True

# Enabling batch input between components:
component1.batch.inputBatch = True
component1.batch.outputBatch = True

component2.batch.inputBatch = True
component2.batch.outputBatch = False