From 6aaf47b7317b382816c2c3bb1d0e9edae6908093 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Mon, 26 Jun 2023 12:04:11 +0200 Subject: [PATCH 1/3] chore: remove models and model from input and output identifier Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- tests/data_factory.py | 10 ++++----- tests/fl_interface.py | 38 +++++++++++++++++------------------ tests/sdk/local/test_debug.py | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/data_factory.py b/tests/data_factory.py index 8868b7c2..f01a307e 100644 --- a/tests/data_factory.py +++ b/tests/data_factory.py @@ -79,7 +79,7 @@ def _get_predictions(path): def train(inputs, outputs, task_properties): X = inputs['{InputIdentifiers.datasamples}'][0] y = inputs['{InputIdentifiers.datasamples}'][1] - models_path = inputs.get('{InputIdentifiers.models}', []) + models_path = inputs.get('{InputIdentifiers.shared}', []) models = [_load_model(model_path) for model_path in models_path] print(f'Train, get X: {{X}}, y: {{y}}, models: {{models}}') @@ -95,12 +95,12 @@ def train(inputs, outputs, task_properties): res = dict(value=avg + err) print(f'Train, return {{res}}') - _save_model(res, outputs['{OutputIdentifiers.model}']) + _save_model(res, outputs['{OutputIdentifiers.shared}']) @tools.register def predict(inputs, outputs, task_properties): X = inputs['{InputIdentifiers.datasamples}'][0] - model = _load_model(inputs['{InputIdentifiers.model}']) + model = _load_model(inputs['{InputIdentifiers.shared}']) res = [x * model['value'] for x in X] print(f'Predict, get X: {{X}}, model: {{model}}, return {{res}}') @@ -129,14 +129,14 @@ def _save_predictions(y_pred, path): @tools.register def aggregate(inputs, outputs, task_properties): - models_path = inputs.get('{InputIdentifiers.models}', []) + models_path = inputs.get('{InputIdentifiers.shared}', []) models = [_load_model(model_path) for model_path in models_path] print(f'Aggregate models: {{models}}') values = [m['value'] for m in models] avg = sum(values) / len(values) res = dict(value=avg) print(f'Aggregate result: {{res}}') - _save_model(res, outputs['{OutputIdentifiers.model}']) + _save_model(res, outputs['{OutputIdentifiers.shared}']) @tools.register def predict(inputs, outputs, task_properties): diff --git a/tests/fl_interface.py b/tests/fl_interface.py index bc1a39b6..26f9ef5b 100644 --- a/tests/fl_interface.py +++ b/tests/fl_interface.py @@ -45,7 +45,7 @@ class FLFunctionInputs(list, Enum): """Substra function inputs by function category based on the InputIdentifiers""" FUNCTION_AGGREGATE = [ - FunctionInputSpec(identifier=InputIdentifiers.models, kind=AssetKind.model.value, optional=False, multiple=True) + FunctionInputSpec(identifier=InputIdentifiers.shared, kind=AssetKind.model.value, optional=False, multiple=True) ] FUNCTION_SIMPLE = [ FunctionInputSpec( @@ -57,7 +57,7 @@ class FLFunctionInputs(list, Enum): FunctionInputSpec( identifier=InputIdentifiers.opener, kind=AssetKind.data_manager.value, optional=False, multiple=False ), - FunctionInputSpec(identifier=InputIdentifiers.models, kind=AssetKind.model.value, optional=True, multiple=True), + FunctionInputSpec(identifier=InputIdentifiers.shared, kind=AssetKind.model.value, optional=True, multiple=True), ] FUNCTION_COMPOSITE = [ FunctionInputSpec( @@ -85,7 +85,7 @@ class FLFunctionInputs(list, Enum): identifier=InputIdentifiers.opener, kind=AssetKind.data_manager.value, optional=False, multiple=False ), FunctionInputSpec( - identifier=InputIdentifiers.model, kind=AssetKind.model.value, optional=False, multiple=False + identifier=InputIdentifiers.shared, kind=AssetKind.model.value, optional=False, multiple=False ), ] FUNCTION_PREDICT_COMPOSITE = [ @@ -125,10 +125,10 @@ class FLFunctionOutputs(list, Enum): """Substra function outputs by function category based on the OutputIdentifiers""" FUNCTION_AGGREGATE = [ - FunctionOutputSpec(identifier=OutputIdentifiers.model, kind=AssetKind.model.value, multiple=False) + FunctionOutputSpec(identifier=OutputIdentifiers.shared, kind=AssetKind.model.value, multiple=False) ] FUNCTION_SIMPLE = [ - FunctionOutputSpec(identifier=OutputIdentifiers.model, kind=AssetKind.model.value, multiple=False) + FunctionOutputSpec(identifier=OutputIdentifiers.shared, kind=AssetKind.model.value, multiple=False) ] FUNCTION_COMPOSITE = [ FunctionOutputSpec(identifier=OutputIdentifiers.local, kind=AssetKind.model.value, multiple=False), @@ -168,9 +168,9 @@ def task(opener_key, data_sample_keys): def trains_to_train(model_keys): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, - parent_task_output_identifier=OutputIdentifiers.model, + parent_task_output_identifier=OutputIdentifiers.shared, ) for model_key in model_keys ] @@ -179,9 +179,9 @@ def trains_to_train(model_keys): def trains_to_aggregate(model_keys): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, - parent_task_output_identifier=OutputIdentifiers.model, + parent_task_output_identifier=OutputIdentifiers.shared, ) for model_key in model_keys ] @@ -190,9 +190,9 @@ def trains_to_aggregate(model_keys): def train_to_predict(model_key): return [ InputRef( - identifier=InputIdentifiers.model, + identifier=InputIdentifiers.shared, parent_task_key=model_key, - parent_task_output_identifier=OutputIdentifiers.model, + parent_task_output_identifier=OutputIdentifiers.shared, ) ] @@ -252,7 +252,7 @@ def aggregate_to_shared(model_key): InputRef( identifier=InputIdentifiers.shared, parent_task_key=model_key, - parent_task_output_identifier=OutputIdentifiers.model, + parent_task_output_identifier=OutputIdentifiers.shared, ) ] @@ -260,7 +260,7 @@ def aggregate_to_shared(model_key): def composites_to_aggregate(model_keys): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, parent_task_output_identifier=OutputIdentifiers.shared, ) @@ -271,9 +271,9 @@ def composites_to_aggregate(model_keys): def aggregate_to_predict(model_key): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, - parent_task_output_identifier=OutputIdentifiers.model, + parent_task_output_identifier=OutputIdentifiers.shared, ) ] @@ -281,7 +281,7 @@ def aggregate_to_predict(model_key): def local_to_aggregate(model_key): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, parent_task_output_identifier=OutputIdentifiers.local, ) @@ -291,7 +291,7 @@ def local_to_aggregate(model_key): def shared_to_aggregate(model_key): return [ InputRef( - identifier=InputIdentifiers.models, + identifier=InputIdentifiers.shared, parent_task_key=model_key, parent_task_output_identifier=OutputIdentifiers.shared, ) @@ -310,11 +310,11 @@ class FLTaskOutputGenerator: @staticmethod def traintask(authorized_ids=None): - return {OutputIdentifiers.model: ComputeTaskOutputSpec(permissions=_permission_from_ids(authorized_ids))} + return {OutputIdentifiers.shared: ComputeTaskOutputSpec(permissions=_permission_from_ids(authorized_ids))} @staticmethod def aggregatetask(authorized_ids=None): - return {OutputIdentifiers.model: ComputeTaskOutputSpec(permissions=_permission_from_ids(authorized_ids))} + return {OutputIdentifiers.shared: ComputeTaskOutputSpec(permissions=_permission_from_ids(authorized_ids))} @staticmethod def predicttask(authorized_ids=None): diff --git a/tests/sdk/local/test_debug.py b/tests/sdk/local/test_debug.py index d0bc38ac..b28235e5 100644 --- a/tests/sdk/local/test_debug.py +++ b/tests/sdk/local/test_debug.py @@ -204,7 +204,7 @@ def test_tasks_extra_fields(self, asset_factory, clients): assert len(predicttask.inputs) == 3 # data sample + opener + input task - model_ref = [x for x in predicttask.inputs if x.identifier == InputIdentifiers.model] + model_ref = [x for x in predicttask.inputs if x.identifier == InputIdentifiers.shared] assert len(model_ref) == 1 assert model_ref[0].parent_task_key == traintask_key From e96b78442a05ae388493c6dab199a8a9407498f4 Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Mon, 26 Jun 2023 12:04:33 +0200 Subject: [PATCH 2/3] chore: remove models and model from input and output identifier Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- tests/fl_interface.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/fl_interface.py b/tests/fl_interface.py index 26f9ef5b..41c5bcec 100644 --- a/tests/fl_interface.py +++ b/tests/fl_interface.py @@ -25,8 +25,6 @@ class FunctionCategory(str, Enum): class InputIdentifiers(str, Enum): local = "local" shared = "shared" - model = "model" - models = "models" predictions = "predictions" performance = "performance" opener = "opener" @@ -36,7 +34,6 @@ class InputIdentifiers(str, Enum): class OutputIdentifiers(str, Enum): local = "local" shared = "shared" - model = "model" predictions = "predictions" performance = "performance" From ae46a9bbd3189a3d07ee257c125e4b92cc94226f Mon Sep 17 00:00:00 2001 From: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:54:13 +0200 Subject: [PATCH 3/3] chore: changelog Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f086500..820f55a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Remove `model` and `models` for input and output identifiers in tests. Replace by `shared` instead. ([#367](https://github.com/Substra/substra/pull/367)) + ## [0.45.0](https://github.com/Substra/substra/releases/tag/0.45.0) - 2023-06-12 ### Added