Commit b7b4c693 authored by Samuel GAIST's avatar Samuel GAIST

[algorithms] Add API v1 to v2 migration instructions

parent 5aeb187c
......@@ -151,8 +151,9 @@ from the other groups. This is described in more details in the following
subsections. Finally, the field `description` is optional and gives a short
description of the algorithm.
The web client of the BEAT platform provides a graphical editor for algorithm,
which simplifies its `JSON`_ declaration definition.
The graphical interface of BEAT provides editors for the main components of the
system (for example: algorithms, data formats, etc.), which simplifies their
`JSON`_ declaration definition.
.. _beat-system-algorithms-definition-analyzer:
......@@ -164,11 +165,11 @@ At the end of the processing workflow of an experiment, there is a special
kind of algorithm, which does not yield any output, but in contrast so called
`results`. These algorithms are called **analyzers**.
`Results` of an experiment are reported back to the user. Since the platform
is concerned about data privacy, only a limited number of data formats can be
employed as results in an analyzer, such as boolean, integers, floating point
values, strings (of limited size), as well as plots (such as scatter or bar
plots).
`Results` of an experiment are reported back to the user. Data privacy is very
important in the BEAT framework and therefore only a limited number of data
formats can be employed as results in an analyzer, such as boolean, integers,
floating point values, strings (of limited size), as well as plots (such as
scatter or bar plots).
For example, the following declaration is the one of a simple analyzer, which
generates an ROC curve as well as few other metrics.
......@@ -224,7 +225,7 @@ generates an ROC curve as well as few other metrics.
Source Code
...........
The BEAT platform has been designed to support algorithms written in different
The BEAT system has been designed to support algorithms written in different
programming languages. However, for each language, a corresponding back-end
needs to be implemented, which is in charge of connecting the inputs and
outputs to the algorithm and running its code as expected. In this section,
......@@ -1016,4 +1017,90 @@ the data block on the output.
return True
.. _beat-system-algorithms-api-migration
Migrating from API v1 to API v2
-------------------------------
Algorithm that have been written using BEAT's algorithm v1 can still be run under
v2 execution model. They are now considered legacy algorithm and should be ported
quickly to the API v2.
API v2 provides two different types of algorithms:
- Sequential
- Autonomous
The Sequential type follows the same code execution model as the v1 API, meaning
that the process function is called once for each input item.
The Autonomous type allows the developer to load the input data at will therefor
the process method will only be called once. This allows for example to optimize
loading of data to the GPU memory for faster execution.
The straightforward migration path from v1 to v2 is to make a Sequential algorithm
which will require only a few changes regarding the code.
API V1:
.. code-block:: python
class Algorithm:
def setup(self, parameters):
self.sync = parameters['sync']
return True
def process(self, inputs, outputs):
if inputs[self.sync].isDataUnitDone():
outputs['out'].write({
'value': inputs['in1'].data.value + inputs['in2'].data.value,
})
return True
API V2 sequential:
.. code-block:: python
class Algorithm:
def setup(self, parameters):
self.sync = parameters['sync']
return True
def process(self, inputs, data_loaders, outputs):
if inputs[self.sync].isDataUnitDone():
outputs['out'].write({
'value': inputs['in1'].data.value + inputs['in2'].data.value,
})
return True
API V2 automous:
.. code-block:: python
class Algorithm:
def setup(self, parameters):
self.sync = parameters['sync']
return True
def process(self, data_loaders, outputs):
data_loader = data_loaders.loaderOf('in1')
for i in range(data_loader.count(self.sync)):
view = data_loader.view(self.sync, i)
(data, start, end) = view[view.count() - 1]
outputs['out'].write({
'value': data['in1'].value + data['in2'].value,
},
end
)
return True
.. include:: links.rst
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment