diff --git a/beat/core/prototypes/algorithm.json b/beat/core/prototypes/algorithm.json index 0f7a1d9e4c4106a1c96261d5b32da69fdd1d537c..ecf2d472803ddd7c3ea80628f977c9c5e26ffe12 100644 --- a/beat/core/prototypes/algorithm.json +++ b/beat/core/prototypes/algorithm.json @@ -1,4 +1,5 @@ { + "schema_version": 2, "language": "unknown", "api_version": 2, "type": "sequential", diff --git a/beat/core/schema/algorithm/1.json b/beat/core/schema/algorithm/1.json index 4fb10263345142a49314750a2ee573f0f1c119c1..097882b8bce163203446fbbbd58a9529b3624876 100644 --- a/beat/core/schema/algorithm/1.json +++ b/beat/core/schema/algorithm/1.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Algorithm descriptor", + "title": "Algorithm v1 descriptor", "description": "This schema defines the properties of an algorithm", "oneOf": [ @@ -10,130 +10,6 @@ "definitions": { - "endpoints": { - "type": "object", - "patternProperties": { - "^[a-zA-Z_][a-zA-Z0-9_-]*$": { - "type": "object", - "properties": { - "type": { "$ref": "../common/1.json#/definitions/reference" }, - "description": { "type": "string" } - }, - "required": [ - "type" - ], - "additionalProperties": false - } - }, - "uniqueItems": true, - "additionalProperties": false - }, - - "io_group": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "inputs": { "$ref": "#/definitions/endpoints" }, - "outputs": { "$ref": "#/definitions/endpoints" } - }, - "required": [ - "inputs", - "outputs" - ], - "additionalProperties": false - }, - - "input_group": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "inputs": { "$ref": "#/definitions/endpoints" } - }, - "required": [ - "inputs" - ], - "additionalProperties": false - }, - - "block_groups": { - "type": "array", - "items": [ - { "$ref": "#/definitions/io_group" } - ], - "additionalItems": { "$ref": "#/definitions/input_group" }, - "minItems": 1 - }, - - "range": { - "type": "array", - "items": { "$ref": "../common/1.json#/definitions/value" }, - "minItems": 2, - "maxItems": 2 - }, - - "choice": { - "type": "array", - "items": { "$ref": "../common/1.json#/definitions/value" }, - "minItems": 3 - }, - - "parameter": { - "type": "object", - "properties": { - "type": { "$ref": "../common/1.json#/definitions/basetype" }, - "default": { "$ref": "../common/1.json#/definitions/value" }, - "description": { "type": "string" } - }, - "required": [ - "type" - ] - }, - - "range_parameter": { - "allOf": [ - { "$ref": "#/definitions/parameter" }, - { - "properties": { - "range": { "$ref": "#/definitions/range" } - }, - "required": [ - "range" - ] - } - ], - "additionalProperties": false - }, - - "choice_parameter": { - "allOf": [ - { "$ref": "#/definitions/parameter" }, - { - "properties": { - "range": { "$ref": "#/definitions/choice" } - }, - "required": [ - "choice" - ] - } - ], - "additionalProperties": false - }, - - "parameters": { - "type": "object", - "patternProperties": { - "^[a-zA-Z_][a-zA-Z0-9_-]*$": { - "oneOf": [ - { "$ref": "#/definitions/parameter" }, - { "$ref": "#/definitions/range_parameter" }, - { "$ref": "#/definitions/choice_parameter" } - ] - } - }, - "uniqueItems": true, - "additionalProperties": false - }, - "block": { "type": "object", @@ -141,13 +17,10 @@ "properties": { "language": { "$ref": "../common/1.json#/definitions/language" }, "description": { "$ref": "../common/1.json#/definitions/description" }, - "groups": { "$ref": "#/definitions/block_groups" }, - "parameters": { "$ref": "#/definitions/parameters" }, + "groups": { "$ref": "common.json#/definitions/block_groups" }, + "parameters": { "$ref": "common.json#/definitions/parameters" }, "splittable": { "type": "boolean" }, - "uses": { "$ref": "../common/1.json#/definitions/uses" }, - "schema_version": { "$ref": "../common/1.json#/definitions/version" }, - "api_version": { "$ref": "../common/1.json#/definitions/version" }, - "type": { "type": "string", "enum": [ "legacy", "sequential", "autonomous" ] } + "uses": { "$ref": "../common/1.json#/definitions/uses" } }, "required": [ @@ -160,44 +33,6 @@ }, - "analyzer_groups": { - "type": "array", - "items": { "$ref": "#/definitions/input_group" }, - "minItems": 1 - }, - - "resulttype": { - "oneOf": [ - { "type": "string", "enum": [ "int32", "float32", "bool", "string" ] }, - { "type": "string", "pattern": "^system/[a-zA-Z0-9_-]+/[0-9]+$" }, - { "type": "string", "pattern": "^plot/[a-zA-Z0-9_-]+/[0-9]+$" } - ] - }, - - "result": { - "type": "object", - "properties": { - "type": { "$ref": "#/definitions/resulttype" }, - "display": { "type": "boolean" }, - "description": { "type": "string" } - }, - "required": [ - "type" - ], - "additionalProperties": false - }, - - "results": { - "type": "object", - "patternProperties": { - "^[a-zA-Z_][a-zA-Z0-9_-]*$": { - "$ref": "#/definitions/result" - } - }, - "uniqueItems": true, - "additionalProperties": false - }, - "analyzer": { "type": "object", @@ -205,11 +40,10 @@ "properties": { "language": { "$ref": "../common/1.json#/definitions/language" }, "description": { "$ref": "../common/1.json#/definitions/description" }, - "groups": { "$ref": "#/definitions/analyzer_groups" }, - "parameters": { "$ref": "#/definitions/parameters" }, - "results": { "$ref": "#/definitions/results" }, - "uses": { "$ref": "../common/1.json#/definitions/uses" }, - "schema_version": { "$ref": "../common/1.json#/definitions/version" } + "groups": { "$ref": "common.json#/definitions/analyzer_groups" }, + "parameters": { "$ref": "common.json#/definitions/parameters" }, + "results": { "$ref": "common.json#/definitions/results" }, + "uses": { "$ref": "../common/1.json#/definitions/uses" } }, "required": [ diff --git a/beat/core/schema/algorithm/2.json b/beat/core/schema/algorithm/2.json index 992befa791827a52c203af7bf2a7802cfe744682..2dbb3c9d318fd963acb9a7868f11f71b38d6ad63 100644 --- a/beat/core/schema/algorithm/2.json +++ b/beat/core/schema/algorithm/2.json @@ -1,28 +1,79 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Algorithm descriptor v2", + "title": "Algorithm v2 descriptor", "description": "This schema defines the properties of a v2 algorithm", - "allOf": [ - { "$ref": "1.json"} + "oneOf": [ + { "$ref": "#/definitions/block" }, + { "$ref": "#/definitions/analyzer" } ], "definitions": { + "type": { + "type": "string", + "enum": [ "legacy", "sequential", "autonomous" ] + }, - "api_version": { - "type": "number", - "exclusiveMinimum": 0 + "block": { + + "type": "object", + + "properties": { + "language": { "$ref": "../common/1.json#/definitions/language" }, + "description": { "$ref": "../common/1.json#/definitions/description" }, + "groups": { "$ref": "common.json#/definitions/block_groups" }, + "parameters": { "$ref": "common.json#/definitions/parameters" }, + "splittable": { "type": "boolean" }, + "uses": { "$ref": "../common/1.json#/definitions/uses" }, + "schema_version": { "$ref": "common.json#/definitions/schema_version" }, + "api_version": { "$ref": "common.json#/definitions/api_version" }, + "type": { "$ref": "#/definitions/type" } + }, + + "required": [ + "language", + "groups", + "splittable" + ], + + "additionalProperties": false + + }, + "analyzer": { + + "type": "object", + + "properties": { + "language": { "$ref": "../common/1.json#/definitions/language" }, + "description": { "$ref": "../common/1.json#/definitions/description" }, + "groups": { "$ref": "common.json#/definitions/analyzer_groups" }, + "parameters": { "$ref": "common.json#/definitions/parameters" }, + "results": { "$ref": "common.json#/definitions/results" }, + "uses": { "$ref": "../common/1.json#/definitions/uses" }, + "schema_version": { "$ref": "common.json#/definitions/schema_version" }, + "api_version": { "$ref": "common.json#/definitions/api_version" }, + "type": { "$ref": "#/definitions/type" } + }, + + "required": [ + "language", + "groups", + "results" + ], + + "additionalProperties": false + } }, - "required": ["type", "api_version"] + "required": ["type", "api_version", "schema_version"] } \ No newline at end of file diff --git a/beat/core/schema/algorithm/common.json b/beat/core/schema/algorithm/common.json new file mode 100644 index 0000000000000000000000000000000000000000..b3c927c0c30beb86aff52244d697f23852922c0d --- /dev/null +++ b/beat/core/schema/algorithm/common.json @@ -0,0 +1,173 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Algorithm common components descriptor", + "description": "This schema defines the components used in one or more versions of the Algorithm", + +"definitions": { + + "endpoints": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_-]*$": { + "type": "object", + "properties": { + "type": { "$ref": "../common/1.json#/definitions/reference" }, + "description": { "type": "string" } + }, + "required": [ + "type" + ], + "additionalProperties": false + } + }, + "uniqueItems": true, + "additionalProperties": false + }, + + "io_group": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "inputs": { "$ref": "#/definitions/endpoints" }, + "outputs": { "$ref": "#/definitions/endpoints" } + }, + "required": [ + "inputs", + "outputs" + ], + "additionalProperties": false + }, + + "input_group": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "inputs": { "$ref": "#/definitions/endpoints" } + }, + "required": [ + "inputs" + ], + "additionalProperties": false + }, + + "block_groups": { + "type": "array", + "items": [ + { "$ref": "#/definitions/io_group" } + ], + "additionalItems": { "$ref": "#/definitions/input_group" }, + "minItems": 1 + }, + + "range": { + "type": "array", + "items": { "$ref": "../common/1.json#/definitions/value" }, + "minItems": 2, + "maxItems": 2 + }, + + "choice": { + "type": "array", + "items": { "$ref": "../common/1.json#/definitions/value" }, + "minItems": 3 + }, + + "parameter": { + "type": "object", + "properties": { + "type": { "$ref": "../common/1.json#/definitions/basetype" }, + "default": { "$ref": "../common/1.json#/definitions/value" }, + "description": { "type": "string" } + }, + "required": [ + "type" + ] + }, + + "range_parameter": { + "allOf": [ + { "$ref": "#/definitions/parameter" }, + { + "properties": { + "range": { "$ref": "#/definitions/range" } + }, + "required": [ + "range" + ] + } + ], + "additionalProperties": false + }, + + "choice_parameter": { + "allOf": [ + { "$ref": "#/definitions/parameter" }, + { + "properties": { + "range": { "$ref": "#/definitions/choice" } + }, + "required": [ + "choice" + ] + } + ], + "additionalProperties": false + }, + + "parameters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_-]*$": { + "oneOf": [ + { "$ref": "#/definitions/parameter" }, + { "$ref": "#/definitions/range_parameter" }, + { "$ref": "#/definitions/choice_parameter" } + ] + } + }, + "uniqueItems": true, + "additionalProperties": false + }, + + "analyzer_groups": { + "type": "array", + "items": { "$ref": "#/definitions/input_group" }, + "minItems": 1 + }, + + "resulttype": { + "oneOf": [ + { "type": "string", "enum": [ "int32", "float32", "bool", "string" ] }, + { "type": "string", "pattern": "^system/[a-zA-Z0-9_-]+/[0-9]+$" }, + { "type": "string", "pattern": "^plot/[a-zA-Z0-9_-]+/[0-9]+$" } + ] + }, + + "result": { + "type": "object", + "properties": { + "type": { "$ref": "#/definitions/resulttype" }, + "display": { "type": "boolean" }, + "description": { "type": "string" } + }, + "required": [ + "type" + ], + "additionalProperties": false + }, + + "results": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_-]*$": { + "$ref": "#/definitions/result" + } + }, + "uniqueItems": true, + "additionalProperties": false + }, + + "schema_version": { "$ref": "../common/1.json#/definitions/version" }, + "api_version": { "$ref": "../common/1.json#/definitions/version" } + } +} \ No newline at end of file diff --git a/beat/core/schema/plotter/1.json b/beat/core/schema/plotter/1.json index 90ad2c2b9bcdfd1394dcffb200200ee1e05185c0..a402f9bda1a7c7cb6d50b5756abab4fc33bad306 100644 --- a/beat/core/schema/plotter/1.json +++ b/beat/core/schema/plotter/1.json @@ -8,7 +8,7 @@ "properties": { "language": { "$ref": "../common/1.json#/definitions/language" }, "description": { "$ref": "../common/1.json#/definitions/description" }, - "parameters": { "$ref": "../algorithm/1.json#/definitions/parameters" }, + "parameters": { "$ref": "../algorithm/common.json#/definitions/parameters" }, "dataformat": { "type": "string", "pattern": "^plot/[a-zA-Z0-9_-]+/[0-9]+$" diff --git a/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.json b/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.json new file mode 100644 index 0000000000000000000000000000000000000000..8cd6c9406d256cd95a454f06cf5cfc0fb98d7573 --- /dev/null +++ b/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.json @@ -0,0 +1,22 @@ +{ + "schema_version": 2, + "language": "python", + "api_version": 2, + "type": "autonomous", + "groups": [ + { + "name": "main", + "inputs": { + "in_data": { + "type": "user/single_integer/1" + } + } + } + ], + "results": { + "out_data": { + "type": "int32", + "display": false + } + } +} diff --git a/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.py b/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.py new file mode 100644 index 0000000000000000000000000000000000000000..5c961d3456adf6e98a516835b96bc622ab1d218f --- /dev/null +++ b/beat/core/test/prefix/algorithms/user/integers_echo_analyzer_v2/1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.core module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +class Algorithm: + + def process(self, inputs, data_loaders, output): + output.write({'out_data': inputs['in_data'].data.value}) + return True diff --git a/beat/core/test/prefix/algorithms/user/prepare_error/1.json b/beat/core/test/prefix/algorithms/user/prepare_error/1.json index b4f5527da441890635f92e5b39a82c11f55e2d1d..da0f7c985a0a9f34137d90ffe85a2addf8564553 100644 --- a/beat/core/test/prefix/algorithms/user/prepare_error/1.json +++ b/beat/core/test/prefix/algorithms/user/prepare_error/1.json @@ -1,5 +1,7 @@ { + "schema_version": 2, "language": "python", + "type": "sequential", "splittable": true, "api_version": 2, "groups": [ diff --git a/beat/core/test/prefix/algorithms/user/prepare_error/1.py b/beat/core/test/prefix/algorithms/user/prepare_error/1.py index 88ed15d52419726221e9d6f32d942420cc9aab44..bcee88cf30507267557b8bf01230dc362f4d8aae 100644 --- a/beat/core/test/prefix/algorithms/user/prepare_error/1.py +++ b/beat/core/test/prefix/algorithms/user/prepare_error/1.py @@ -30,6 +30,6 @@ class Algorithm: def prepare(self, data_loaders): return False - def process(self, inputs, outputs): + def process(self, inputs, data_loaders, outputs): outputs['out_data'].write(inputs['in_data'].data) return True diff --git a/beat/core/test/prefix/algorithms/user/prepare_success/1.json b/beat/core/test/prefix/algorithms/user/prepare_success/1.json index b4f5527da441890635f92e5b39a82c11f55e2d1d..da0f7c985a0a9f34137d90ffe85a2addf8564553 100644 --- a/beat/core/test/prefix/algorithms/user/prepare_success/1.json +++ b/beat/core/test/prefix/algorithms/user/prepare_success/1.json @@ -1,5 +1,7 @@ { + "schema_version": 2, "language": "python", + "type": "sequential", "splittable": true, "api_version": 2, "groups": [ diff --git a/beat/core/test/prefix/algorithms/user/setup_error/1.json b/beat/core/test/prefix/algorithms/user/setup_error/1.json index b4f5527da441890635f92e5b39a82c11f55e2d1d..da0f7c985a0a9f34137d90ffe85a2addf8564553 100644 --- a/beat/core/test/prefix/algorithms/user/setup_error/1.json +++ b/beat/core/test/prefix/algorithms/user/setup_error/1.json @@ -1,5 +1,7 @@ { + "schema_version": 2, "language": "python", + "type": "sequential", "splittable": true, "api_version": 2, "groups": [ diff --git a/beat/core/test/prefix/algorithms/user/setup_error/1.py b/beat/core/test/prefix/algorithms/user/setup_error/1.py index 3bf9c125494c242a8d69622c1fd29031c2dccfda..cf5a2056bc2c55f2df7797c2eb034808d896e77a 100644 --- a/beat/core/test/prefix/algorithms/user/setup_error/1.py +++ b/beat/core/test/prefix/algorithms/user/setup_error/1.py @@ -30,6 +30,6 @@ class Algorithm: def setup(self, parameters): return False - def process(self, inputs, outputs): + def process(self, inputs, data_loaders, outputs): outputs['out_data'].write(inputs['in_data'].data) return True diff --git a/beat/core/test/test_algorithm_loading.py b/beat/core/test/test_algorithm_loading.py index 95736cd1d93c8fb7d3c6b87b20a83681584eba9a..ddf733167df5312832af8ea20bf318e4ea914121 100644 --- a/beat/core/test/test_algorithm_loading.py +++ b/beat/core/test/test_algorithm_loading.py @@ -73,6 +73,12 @@ def test_v2(): assert algorithm.valid, '\n * %s' % '\n * '.join(algorithm.errors) +def test_analyzer_v2(): + + algorithm = Algorithm(prefix, 'user/integers_echo_analyzer_v2/1') + assert algorithm.valid, '\n * %s' % '\n * '.join(algorithm.errors) + + #----------------------------------------------------------