Commit 2c015839 authored by Samuel GAIST's avatar Samuel GAIST

[test][prefix] Add two_loops test

This test implements a more complex toolchain
and experiment that will check that loop blocks
are working in more involved setups.
parent 49126cb4
Pipeline #32006 passed with stage
in 16 minutes and 41 seconds
{
"schema_version": 3,
"language": "python",
"api_version": 2,
"type": "loop",
"groups": [
{
"inputs": {
"in_loop": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out_loop": {
"type": "user/single_integer/1"
}
},
"loop": {
"request": {
"type": "user/1d_array_of_integers/1"
},
"answer": {
"type": "user/single_float/1"
}
}
}
],
"parameters": {
"threshold": {
"default": 9,
"type": "int8",
"description": "Value that will change loop result"
}
}
}
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
import numpy as np
class Algorithm:
def __init__(self):
self.output = None
def validate(self, result):
print("We are validating")
value = result.value[0]
self.output = value
return (True, {"value": np.float32(value)})
def write(self, outputs, end_data_index):
print("block input loop writing", outputs, end_data_index)
outputs["out_loop"].write({"value": np.int32(self.output)}, end_data_index)
print("block input loop writing done")
{
"schema_version": 3,
"language": "python",
"api_version": 2,
"type": "autonomous_loop_user",
"splittable": false,
"groups": [
{
"inputs": {
"in": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out": {
"type": "user/single_integer/1"
}
},
"loop": {
"request": {
"type": "user/1d_array_of_integers/1"
},
"answer": {
"type": "user/single_float/1"
}
}
}
]
}
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
import numpy as np
class Algorithm:
def process(self, data_loaders, outputs, loop_channel):
data_loader = data_loaders.loaderOf("in")
for i in range(data_loader.count()):
view = data_loader.view("in", i)
(data, _, end) = view[view.count() - 1]
value = data["in"].value
_, validated = loop_channel.validate({"value": np.full(10, 12)})
new_value = value + validated.value
print("BLOCK INPUT LOOP USER VALUE IS", value)
print("BLOCK INPUT LOOP USER WRITING NEW VALUE", new_value)
outputs["out"].write({"value": np.int32(new_value)}, end)
print("BLOCK INPUT LOOP USER WRITING DONE")
return True
{
"schema_version": 2,
"blocks": {
"echo_for_loop_user": {
"algorithm": "v1/integers_echo/1",
"parameters": {
},
"inputs": {
"in_data": "in"
},
"outputs": {
"out_data": "out"
}
},
"echo_for_loop": {
"algorithm": "v1/integers_echo/1",
"parameters": {
},
"inputs": {
"in_data": "in"
},
"outputs": {
"out_data": "out"
}
}
},
"loops": {
"loop_super_block": {
"algorithm": "user/db_input_loop_user/1",
"parameters": {
},
"inputs": {
"in": "in"
},
"outputs": {
"out": "out"
},
"loop_algorithm": "user/db_input_loop/1",
"loop_parameters": {
"threshold": 1
},
"loop_inputs": {
"in_loop": "in_loop"
},
"loop_outputs": {
"out_loop": "out_loop"
}
},
"echo_loop_block": {
"algorithm": "user/block_input_loop_user/1",
"parameters": {
},
"inputs": {
"in": "in"
},
"outputs": {
"out": "out"
},
"loop_algorithm": "user/block_input_loop/1",
"loop_parameters": {
"threshold": 1
},
"loop_inputs": {
"in_loop": "in_loop"
},
"loop_outputs": {
"out_loop": "out_loop"
}
}
},
"analyzers": {
"analysis": {
"algorithm": "v1/integers_analysis/1",
"parameters": {
},
"inputs": {
"input": "input"
}
},
"loop_analysis": {
"algorithm": "v1/integers_analysis/1",
"parameters": {
},
"inputs": {
"input": "input"
}
}
},
"datasets": {
"integers": {
"database": "integers_db/1",
"protocol": "double",
"set": "double"
},
"integers2": {
"database": "simple/1",
"protocol": "protocol2",
"set": "set"
}
},
"globals": {
"environment": {
"name": "Python 2.7",
"version": "1.3.0"
},
"queue": "queue",
"user/db_input_loop/1" : {
"threshold": 9
}
}
}
This experiment goal is to ensure that the loop blocks are working in usual
cases.
The flow is following:
- Two databases as inputs of a loop super block
- Outputs connect to standard blocks
- Outputs for standard blocks connected to another loop super block
- Outputs of that second super block connected to analyzers
{
"schema_version": 2,
"connections": [
{
"from": "integers.a",
"to": "loop_super_block.in",
"channel": "integers"
},
{
"from": "integers2.out",
"to": "loop_super_block.in_loop",
"channel": "integers"
},
{
"from": "loop_super_block.out",
"to": "echo_for_loop_user.in",
"channel": "integers"
},
{
"from": "loop_super_block.out_loop",
"to": "echo_for_loop.in",
"channel": "integers"
},
{
"from": "echo_for_loop_user.out",
"to": "echo_loop_block.in",
"channel": "integers"
},
{
"from": "echo_for_loop.out",
"to": "echo_loop_block.in_loop",
"channel": "integers"
},
{
"from": "echo_loop_block.out",
"to": "analysis.input",
"channel": "integers"
},
{
"from": "echo_loop_block.out_loop",
"to": "loop_analysis.input",
"channel": "integers"
}
],
"datasets": [
{
"outputs": [
"a",
"b"
],
"name": "integers"
},
{
"outputs": [
"out"
],
"name": "integers2"
}
],
"loops": [
{
"name": "loop_super_block",
"synchronized_channel": "integers",
"inputs": [
"in"
],
"outputs": [
"out"
],
"loop_inputs": [
"in_loop"
],
"loop_outputs": [
"out_loop"
]
},
{
"name": "echo_loop_block",
"synchronized_channel": "integers",
"inputs": [
"in"
],
"outputs": [
"out"
],
"loop_inputs": [
"in_loop"
],
"loop_outputs": [
"out_loop"
]
}
],
"blocks": [
{
"name": "echo_for_loop_user",
"synchronized_channel": "integers",
"inputs": [
"in"
],
"outputs": [
"out"
]
},
{
"name": "echo_for_loop",
"synchronized_channel": "integers",
"inputs": [
"in"
],
"outputs": [
"out"
]
}
],
"analyzers": [
{
"inputs": [
"input"
],
"synchronized_channel": "integers",
"name": "analysis"
},
{
"inputs": [
"input"
],
"synchronized_channel": "integers",
"name": "loop_analysis"
}
],
"representation": {
"connections": {
},
"blocks": {
},
"loops": {
},
"channel_colors": {
"integers": "#5555ff"
}
}
}
......@@ -353,6 +353,15 @@ class BaseExecutionMixIn(object):
)
)
@slow
def test_two_loops_1(self):
nose.tools.assert_is_none(
self.execute(
"user/user/two_loops/1/two_loops",
[{"sum": 612, "nb": 9}, {"sum": 108, "nb": 9}],
)
)
# For benchmark purposes
# @slow
# def test_double_1_large(self):
......
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