diff --git a/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py b/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py index 12f4ec7f5801f97ef3f5025d7160bce6bb4e7249..1a0d69f4dfac77602a1f2c179c8a9063aed68229 100644 --- a/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py +++ b/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py @@ -22,7 +22,7 @@ from mindspore.ops import operations as P from ..mindspore_test import mindspore_test from ..pipeline.gradient.compare_gradient import pipeline_for_compare_inputs_grad_with_npy_for_case_by_case_config -# from ...vm_impl import * +from ...vm_impl import * verification_set = [ ('MatMul', { diff --git a/tests/mindspore_test_framework/components/executor/check_exceptions.py b/tests/mindspore_test_framework/components/executor/check_exceptions.py index a4eb1cd8a04a15939b8da31ab039e3b09a5986e6..15ac5911d21db10f18e9179b193303af02bbe2f7 100644 --- a/tests/mindspore_test_framework/components/executor/check_exceptions.py +++ b/tests/mindspore_test_framework/components/executor/check_exceptions.py @@ -32,11 +32,11 @@ class CheckExceptionsEC(IExectorComponent): 'error_keywords': ['TensorAdd', 'shape'] } """ - def run_function(self, function, inputs, verification_set): - f = function[keyword.block] - args = inputs[keyword.desc_inputs] - e = function.get(keyword.exception, Exception) - error_kws = function.get(keyword.error_keywords, None) + def __call__(self): + f = self.function[keyword.block] + args = self.inputs[keyword.desc_inputs] + e = self.function.get(keyword.exception, Exception) + error_kws = self.function.get(keyword.error_keywords, None) try: with pytest.raises(e) as exec_info: f(*args) diff --git a/tests/mindspore_test_framework/components/executor/check_gradient_for_scalar_func.py b/tests/mindspore_test_framework/components/executor/check_gradient_for_scalar_func.py index 5435f4322b45669d8233d9db033ecd2a768c96fd..fd18aef3efbef41960d2f346d889b8585dbdf3a1 100644 --- a/tests/mindspore_test_framework/components/executor/check_gradient_for_scalar_func.py +++ b/tests/mindspore_test_framework/components/executor/check_gradient_for_scalar_func.py @@ -26,8 +26,8 @@ class CheckGradientForScalarFunctionEC(IExectorComponent): Examples: 'block': scalar_function """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, sampling_times, _ = \ - get_grad_checking_options(function, inputs) + get_grad_checking_options(self.function, self.inputs) check_gradient(f, *args, delta=delta, max_error=max_error, grad_checker_class=ScalarGradChecker, input_selector=input_selector, output_selector=output_selector, sampling_times=sampling_times) diff --git a/tests/mindspore_test_framework/components/executor/check_gradient_wrt_inputs.py b/tests/mindspore_test_framework/components/executor/check_gradient_wrt_inputs.py index 99cb0f8da88f1e68a997f0ac9b4ae485f5d47e12..05839d0595bf5d88db0c573c69d54c302f6d36f4 100644 --- a/tests/mindspore_test_framework/components/executor/check_gradient_wrt_inputs.py +++ b/tests/mindspore_test_framework/components/executor/check_gradient_wrt_inputs.py @@ -35,9 +35,9 @@ class CheckGradientWrtInputsEC(IExectorComponent): key_act=None, initializer_range=0.02) """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, \ - sampling_times, reduce_output = get_grad_checking_options(function, inputs) + sampling_times, reduce_output = get_grad_checking_options(self.function, self.inputs) check_gradient(f, *args, delta=delta, max_error=max_error, grad_checker_class=OperationGradChecker, input_selector=input_selector, output_selector=output_selector, sampling_times=sampling_times, reduce_output=reduce_output) diff --git a/tests/mindspore_test_framework/components/executor/check_gradient_wrt_params.py b/tests/mindspore_test_framework/components/executor/check_gradient_wrt_params.py index c0f3b4e23e7efa2d0e7f1af2e0eb5e8077aad0b8..509b73d3e1b7f9a5da78ccea563be990a14eaab8 100644 --- a/tests/mindspore_test_framework/components/executor/check_gradient_wrt_params.py +++ b/tests/mindspore_test_framework/components/executor/check_gradient_wrt_params.py @@ -35,9 +35,9 @@ class CheckGradientWrtParamsEC(IExectorComponent): key_act=None, initializer_range=0.02) """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, \ - sampling_times, reduce_output = get_grad_checking_options(function, inputs) + sampling_times, reduce_output = get_grad_checking_options(self.function, self.inputs) check_gradient(f, *args, delta=delta, max_error=max_error, grad_checker_class=NNGradChecker, input_selector=input_selector, output_selector=output_selector, sampling_times=sampling_times, reduce_output=reduce_output) diff --git a/tests/mindspore_test_framework/components/executor/check_jacobian_for_scalar_func.py b/tests/mindspore_test_framework/components/executor/check_jacobian_for_scalar_func.py index c06d07b446b90010c51c3c8bbb847486eeb4ef72..8239eaf2978ed50a1152436d6d8b014d18279203 100644 --- a/tests/mindspore_test_framework/components/executor/check_jacobian_for_scalar_func.py +++ b/tests/mindspore_test_framework/components/executor/check_jacobian_for_scalar_func.py @@ -26,8 +26,8 @@ class CheckJacobianForScalarFunctionEC(IExectorComponent): Examples: 'block': scalar_function """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, _, _ = \ - get_grad_checking_options(function, inputs) + get_grad_checking_options(self.function, self.inputs) check_jacobian(f, *args, delta=delta, max_error=max_error, grad_checker_class=ScalarGradChecker, input_selector=input_selector, output_selector=output_selector) diff --git a/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_inputs.py b/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_inputs.py index 9ba0d4a33afeb77d408ef6c0b6bd4727c0f2e620..fa0d1b4ce174c018d347d2369f01d7f0dfefdb53 100644 --- a/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_inputs.py +++ b/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_inputs.py @@ -35,8 +35,8 @@ class CheckJacobianWrtInputsEC(IExectorComponent): key_act=None, initializer_range=0.02) """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, _, _ = \ - get_grad_checking_options(function, inputs) + get_grad_checking_options(self.function, self.inputs) check_jacobian(f, *args, delta=delta, max_error=max_error, grad_checker_class=OperationGradChecker, input_selector=input_selector, output_selector=output_selector) diff --git a/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_params.py b/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_params.py index 4db117da77c394ccb0c1f5c76a5cf20a9bb62ada..c3a01c886de2e6b85944f0f8fd23301598d198d0 100644 --- a/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_params.py +++ b/tests/mindspore_test_framework/components/executor/check_jacobian_wrt_params.py @@ -35,8 +35,8 @@ class CheckJacobianWrtParamsEC(IExectorComponent): key_act=None, initializer_range=0.02) """ - def run_function(self, function, inputs, verification_set): + def __call__(self): f, args, delta, max_error, input_selector, output_selector, _, _ = \ - get_grad_checking_options(function, inputs) + get_grad_checking_options(self.function, self.inputs) check_jacobian(f, *args, delta=delta, max_error=max_error, grad_checker_class=NNGradChecker, input_selector=input_selector, output_selector=output_selector) diff --git a/tests/mindspore_test_framework/components/executor/exec_and_verify_model_loss.py b/tests/mindspore_test_framework/components/executor/exec_and_verify_model_loss.py index 86de8c43db97d420a39d1304f32c09f07b492ba0..10ae33e17a1b2e1e087c2e70220c4f23b0db1d51 100644 --- a/tests/mindspore_test_framework/components/executor/exec_and_verify_model_loss.py +++ b/tests/mindspore_test_framework/components/executor/exec_and_verify_model_loss.py @@ -32,13 +32,13 @@ class LossVerifierEC(IExectorComponent): 'loss_upper_bound': 0.03, } """ - def run_function(self, function, inputs, verification_set): - model = function[keyword.block][keyword.model] - loss = function[keyword.block][keyword.loss] - opt = function[keyword.block][keyword.opt] - num_epochs = function[keyword.block][keyword.num_epochs] - loss_upper_bound = function[keyword.block][keyword.loss_upper_bound] - train_dataset = inputs[keyword.desc_inputs] + def __call__(self): + model = self.function[keyword.block][keyword.model] + loss = self.function[keyword.block][keyword.loss] + opt = self.function[keyword.block][keyword.opt] + num_epochs = self.function[keyword.block][keyword.num_epochs] + loss_upper_bound = self.function[keyword.block][keyword.loss_upper_bound] + train_dataset = self.inputs[keyword.desc_inputs] model = Model(model, loss, opt) loss = model.train(num_epochs, train_dataset) assert loss.asnumpy().mean() <= loss_upper_bound diff --git a/tests/mindspore_test_framework/components/executor/exec_forward.py b/tests/mindspore_test_framework/components/executor/exec_forward.py index f397a9fc48abef263baf9176ecc4425eee3b82ba..45c8f697553df3be116bbb2914e345c9b9b94fe7 100644 --- a/tests/mindspore_test_framework/components/executor/exec_forward.py +++ b/tests/mindspore_test_framework/components/executor/exec_forward.py @@ -22,12 +22,12 @@ class IdentityEC(IExectorComponent): """ Execute function/inputs. """ - def run_function(self, function, inputs, verification_set): - result_id = function[keyword.id] + '-' + inputs[keyword.id] - group = function[keyword.group] + '-' + inputs[keyword.group] + def __call__(self): + result_id = self.function[keyword.id] + '-' + self.inputs[keyword.id] + group = self.function[keyword.group] + '-' + self.inputs[keyword.group] return { keyword.id: result_id, keyword.group: group, - keyword.desc_inputs: inputs[keyword.desc_inputs], - keyword.result: function[keyword.block](*inputs[keyword.desc_inputs]) + keyword.desc_inputs: self.inputs[keyword.desc_inputs], + keyword.result: self.function[keyword.block](*self.inputs[keyword.desc_inputs]) } diff --git a/tests/mindspore_test_framework/components/executor/exec_gradient.py b/tests/mindspore_test_framework/components/executor/exec_gradient.py index 33fd6cee0c2d3395e24c334c6085b6f65debb84b..27061aec25dbc464d6ab0053441092ec94a577c3 100644 --- a/tests/mindspore_test_framework/components/executor/exec_gradient.py +++ b/tests/mindspore_test_framework/components/executor/exec_gradient.py @@ -22,15 +22,15 @@ class IdentityBackwardEC(IExectorComponent): """ Execute function/inputs, with all bprops attached, the bprop function created by BC should handle these bprops. """ - def run_function(self, function, inputs, verification_set): - result_id = function[keyword.id] + '-' + inputs[keyword.id] - group = function[keyword.group] + '-' + inputs[keyword.group] + def __call__(self): + result_id = self.function[keyword.id] + '-' + self.inputs[keyword.id] + group = self.function[keyword.group] + '-' + self.inputs[keyword.group] i = [] - i.extend(inputs[keyword.desc_inputs]) - i.extend(inputs[keyword.desc_bprop]) + i.extend(self.inputs[keyword.desc_inputs]) + i.extend(self.inputs[keyword.desc_bprop]) return { keyword.id: result_id, keyword.group: group, keyword.desc_inputs: i, - keyword.result: function[keyword.block](*i) + keyword.result: self.function[keyword.block](*i) } diff --git a/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_group_for_expect_result.py b/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_group_for_expect_result.py index cf2f2e86b1aa64f3a2c94ff1524a4fcae9f664bb..c5535370c1fe621cd009b28bd0eff5d58384eb53 100644 --- a/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_group_for_expect_result.py +++ b/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_group_for_expect_result.py @@ -22,6 +22,6 @@ class GroupCartesianProductERPC(IERPolicyComponent): """ Combine expect/result by do cartesian product on group. """ - def combine(self, expect, result, verification_set): - ret = [(s1, s2) for s1 in expect for s2 in result if s1[keyword.group] == s2[keyword.group]] + def __call__(self): + ret = [(s1, s2) for s1 in self.expect for s2 in self.result if s1[keyword.group] == s2[keyword.group]] return ret diff --git a/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_id_for_expect_result.py b/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_id_for_expect_result.py index c1d5b84963319d61722b097fc2fcae66f2ca0c42..1f44b7015e599dbeecf5027932a5a304ec1bf897 100644 --- a/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_id_for_expect_result.py +++ b/tests/mindspore_test_framework/components/expect_result_policy/cartesian_product_on_id_for_expect_result.py @@ -22,6 +22,6 @@ class IdCartesianProductERPC(IERPolicyComponent): """ Combine expect/result by do cartesian product on id. """ - def combine(self, expect, result, verification_set): - ret = [(s1, s2) for s1 in expect for s2 in result if s1[keyword.id] == s2[keyword.id]] + def __call__(self): + ret = [(s1, s2) for s1 in self.expect for s2 in self.result if s1[keyword.id] == s2[keyword.id]] return ret diff --git a/tests/mindspore_test_framework/components/facade/me_facade.py b/tests/mindspore_test_framework/components/facade/me_facade.py index e94487582c8cb940b7314afe93cc05d90baa645c..3abde60c6bd960759fbe99d0da88dba66a01e295 100644 --- a/tests/mindspore_test_framework/components/facade/me_facade.py +++ b/tests/mindspore_test_framework/components/facade/me_facade.py @@ -47,9 +47,9 @@ class MeFacadeFC(IFacadeComponent): } }) """ - def adapt(self, verification_set): + def __call__(self): ret = get_block_config() - for config in verification_set: + for config in self.verification_set: tid = config[0] group = 'default' m = config[1] diff --git a/tests/mindspore_test_framework/components/function/compile_block.py b/tests/mindspore_test_framework/components/function/compile_block.py index 586ec02ba2058e5e6fa20a73843d1ce9cd3b29c7..8c226c619832302af1558ce6940f6eddd094a1d2 100644 --- a/tests/mindspore_test_framework/components/function/compile_block.py +++ b/tests/mindspore_test_framework/components/function/compile_block.py @@ -42,5 +42,5 @@ class CompileBlockBC(IBuilderComponent): dtype=mstype.float32, compute_type=mstype.float32) """ - def build_sut(self, verification_set): - return create_funcs(verification_set, gen_net, compile_block) + def __call__(self): + return create_funcs(self.verification_set, gen_net, compile_block) diff --git a/tests/mindspore_test_framework/components/function/compile_gradient_wrt_inputs.py b/tests/mindspore_test_framework/components/function/compile_gradient_wrt_inputs.py index cf9a2d43da1f677ae33d34face1c1fa374770220..829141c2f1da281143d1709292de159b6da31f2f 100644 --- a/tests/mindspore_test_framework/components/function/compile_gradient_wrt_inputs.py +++ b/tests/mindspore_test_framework/components/function/compile_gradient_wrt_inputs.py @@ -43,6 +43,6 @@ class CompileBackwardBlockWrtInputsBC(IBuilderComponent): dtype=mstype.float32, compute_type=mstype.float32) """ - def build_sut(self, verification_set): + def __call__(self): grad_op = GradOperation('grad', get_all=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, compile_block, grad_op) + return create_funcs(self.verification_set, gen_grad_net, compile_block, grad_op) diff --git a/tests/mindspore_test_framework/components/function/compile_gradient_wrt_params.py b/tests/mindspore_test_framework/components/function/compile_gradient_wrt_params.py index 96d28e342a20341f3533064cf77bc86db01154a5..7f9ac3e05e02bf7fa245c790371ee9b8d8892d73 100644 --- a/tests/mindspore_test_framework/components/function/compile_gradient_wrt_params.py +++ b/tests/mindspore_test_framework/components/function/compile_gradient_wrt_params.py @@ -43,6 +43,6 @@ class CompileBackwardBlockWrtParamsBC(IBuilderComponent): dtype=mstype.float32, compute_type=mstype.float32) """ - def build_sut(self, verification_set): + def __call__(self, verification_set): grad_op = GradOperation('grad', get_by_list=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, compile_block, grad_op) + return create_funcs(self.verification_set, gen_grad_net, compile_block, grad_op) diff --git a/tests/mindspore_test_framework/components/function/get_function_from_config.py b/tests/mindspore_test_framework/components/function/get_function_from_config.py index 45ab65a6e61be7538925ad03bf01c9294c00614d..0960e453028ad3e51849b7b853e9708a54f732d7 100644 --- a/tests/mindspore_test_framework/components/function/get_function_from_config.py +++ b/tests/mindspore_test_framework/components/function/get_function_from_config.py @@ -25,5 +25,5 @@ class IdentityBC(IBuilderComponent): Examples: 'function': Add """ - def build_sut(self, verification_set): - return verification_set[keyword.function] + def __call__(self): + return self.verification_set[keyword.function] diff --git a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_block.py b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_block.py index 99048fe2c4faf347e9b48bd328b447401e0b5925..5789e39eb41c6483d4cc384a372f79f24435a415 100644 --- a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_block.py +++ b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_block.py @@ -42,5 +42,5 @@ class RunBlockWithRandParamBC(IBuilderComponent): dtype=mstype.float32, compute_type=mstype.float32) """ - def build_sut(self, verification_set): - return create_funcs(verification_set, gen_net, run_block, default_rand_func=get_uniform_with_shape) + def __call__(self): + return create_funcs(self.verification_set, gen_net, run_block, default_rand_func=get_uniform_with_shape) diff --git a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_inputs.py b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_inputs.py index e6700671b81d837e0a19d6ac5105075ae3e29266..69fcfdc316deea354223ef1ae301d7d507fea18f 100644 --- a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_inputs.py +++ b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_inputs.py @@ -20,6 +20,6 @@ from ...components.icomponent import IBuilderComponent from ...utils.block_util import run_block, gen_grad_net, create_funcs, get_uniform_with_shape class RunBackwardBlockWrtInputsWithRandParamBC(IBuilderComponent): - def build_sut(self, verification_set): + def __call__(self): grad_op = GradOperation('grad', get_all=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, run_block, grad_op, get_uniform_with_shape) + return create_funcs(self.verification_set, gen_grad_net, run_block, grad_op, get_uniform_with_shape) diff --git a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_params.py b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_params.py index bc08d0818300bee759a3eb3535665121278a5971..447531ffaae4f62c4274e6e2e16b4036883cafae 100644 --- a/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_params.py +++ b/tests/mindspore_test_framework/components/function/init_params_with_rand_and_run_gradient_wrt_params.py @@ -20,6 +20,6 @@ from ...components.icomponent import IBuilderComponent from ...utils.block_util import run_block, gen_grad_net, create_funcs, get_uniform_with_shape class RunBackwardBlockWrtParamsWithRandParamBC(IBuilderComponent): - def build_sut(self, verification_set): + def __call__(self): grad_op = GradOperation('grad', get_by_list=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, run_block, grad_op, get_uniform_with_shape) + return create_funcs(self.verification_set, gen_grad_net, run_block, grad_op, get_uniform_with_shape) diff --git a/tests/mindspore_test_framework/components/function/run_block.py b/tests/mindspore_test_framework/components/function/run_block.py index 98e89644ab3ce54225db43c73a06aca47c8e0a38..8340bb7b23878485df36e560aa34136eee4c13d3 100644 --- a/tests/mindspore_test_framework/components/function/run_block.py +++ b/tests/mindspore_test_framework/components/function/run_block.py @@ -42,5 +42,5 @@ class RunBlockBC(IBuilderComponent): dtype=mstype.float32, compute_type=mstype.float32) """ - def build_sut(self, verification_set): - return create_funcs(verification_set, gen_net, run_block) + def __call__(self): + return create_funcs(self.verification_set, gen_net, run_block) diff --git a/tests/mindspore_test_framework/components/function/run_gradient_wrt_inputs.py b/tests/mindspore_test_framework/components/function/run_gradient_wrt_inputs.py index e7a143906710931fed8b67a47536190490e1a6fe..699fc74322965818591309c90b78c9954bc7e21f 100644 --- a/tests/mindspore_test_framework/components/function/run_gradient_wrt_inputs.py +++ b/tests/mindspore_test_framework/components/function/run_gradient_wrt_inputs.py @@ -20,6 +20,6 @@ from ...components.icomponent import IBuilderComponent from ...utils.block_util import run_block, gen_grad_net, create_funcs class RunBackwardBlockWrtInputsBC(IBuilderComponent): - def build_sut(self, verification_set): + def __call__(self): grad_op = GradOperation('grad', get_all=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, run_block, grad_op) + return create_funcs(self.verification_set, gen_grad_net, run_block, grad_op) diff --git a/tests/mindspore_test_framework/components/function/run_gradient_wrt_params.py b/tests/mindspore_test_framework/components/function/run_gradient_wrt_params.py index d935131d7dcb84078a0a4faf25ae9436bb812fac..90e58ac76321b5be9af6de39a48f476917ab5783 100644 --- a/tests/mindspore_test_framework/components/function/run_gradient_wrt_params.py +++ b/tests/mindspore_test_framework/components/function/run_gradient_wrt_params.py @@ -20,6 +20,6 @@ from ...components.icomponent import IBuilderComponent from ...utils.block_util import run_block, gen_grad_net, create_funcs class RunBackwardBlockWrtParamsBC(IBuilderComponent): - def build_sut(self, verification_set): + def __call__(self): grad_op = GradOperation('grad', get_by_list=True, sens_param=True) - return create_funcs(verification_set, gen_grad_net, run_block, grad_op) + return create_funcs(self.verification_set, gen_grad_net, run_block, grad_op) diff --git a/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_group_for_function_inputs.py b/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_group_for_function_inputs.py index 6e696f3a14a2313efb2c3a23676132628ca41fda..13925ee73b6befd6d8406cda2bfccda6e6e5da30 100644 --- a/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_group_for_function_inputs.py +++ b/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_group_for_function_inputs.py @@ -23,7 +23,6 @@ class GroupCartesianProductFIPC(IFIPolicyComponent): """ Combine function/inputs by do cartesian product on group. """ - def combine(self, function, inputs, verification_set): - # pylint: disable=unused-argument - ret = [(s1, s2) for s1 in function for s2 in inputs if s1[keyword.group] == s2[keyword.group]] + def __call__(self): + ret = [(s1, s2) for s1 in self.function for s2 in self.inputs if s1[keyword.group] == s2[keyword.group]] return ret diff --git a/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_id_for_function_inputs.py b/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_id_for_function_inputs.py index 3c930f8eaf33a7f1f33d03caf7fb3393665c3360..2ebae6072e3bac3117f460d46156408cb190d069 100644 --- a/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_id_for_function_inputs.py +++ b/tests/mindspore_test_framework/components/function_inputs_policy/cartesian_product_on_id_for_function_inputs.py @@ -22,7 +22,6 @@ class IdCartesianProductFIPC(IFIPolicyComponent): """ Combine function/inputs by do cartesian product on id. """ - def combine(self, function, inputs, verification_set): - # pylint: disable=unused-argument - ret = [(s1, s2) for s1 in function for s2 in inputs if s1[keyword.id] == s2[keyword.id]] + def __call__(self): + ret = [(s1, s2) for s1 in self.function for s2 in self.inputs if s1[keyword.id] == s2[keyword.id]] return ret diff --git a/tests/mindspore_test_framework/components/icomponent.py b/tests/mindspore_test_framework/components/icomponent.py index b02bfa383cf9fd8fb99ae50c43da8ba13dbb694b..8b535ba39a54293a64f3c9c5ba28ab51a22a75d3 100644 --- a/tests/mindspore_test_framework/components/icomponent.py +++ b/tests/mindspore_test_framework/components/icomponent.py @@ -20,28 +20,19 @@ class IComponent: def __init__(self, verification_set): self.verification_set = verification_set - def run(self): + def __call__(self): raise NotImplementedError - def get_result(self): - return self.result - class IDataComponent(IComponent): """Create inputs for verification_set.""" - def run(self): - self.result = self.create_inputs(self.verification_set) - - def create_inputs(self, verification_set): + def __call__(self): raise NotImplementedError class IBuilderComponent(IComponent): """Build system under test.""" - def run(self): - self.result = self.build_sut(self.verification_set) - - def build_sut(self, verification_set): + def __call__(self): raise NotImplementedError @@ -52,10 +43,7 @@ class IExectorComponent(IComponent): self.function = function self.inputs = inputs - def run(self): - self.result = self.run_function(self.function, self.inputs, self.verification_set) - - def run_function(self, function, inputs, verification_set): + def __call__(self): raise NotImplementedError @@ -66,10 +54,7 @@ class IVerifierComponent(IComponent): self.expect = expect self.func_result = result - def run(self): - self.result = self.verify(self.expect, self.func_result, self.verification_set) - - def verify(self, expect, func_result, verification_set): + def __call__(self): raise NotImplementedError @@ -80,10 +65,7 @@ class IFIPolicyComponent(IComponent): self.function = function self.inputs = inputs - def run(self): - self.result = self.combine(self.function, self.inputs, self.verification_set) - - def combine(self, function, inputs, verification_set): + def __call__(self): raise NotImplementedError @@ -94,17 +76,11 @@ class IERPolicyComponent(IComponent): self.expect = expect self.result = result - def run(self): - self.result = self.combine(self.expect, self.result, self.verification_set) - - def combine(self, expect, result, verification_set): + def __call__(self): raise NotImplementedError class IFacadeComponent(IComponent): """Adapt verification_set.""" - def run(self): - self.result = self.adapt(self.verification_set) - - def adapt(self, verification_set): + def __call__(self): raise NotImplementedError diff --git a/tests/mindspore_test_framework/components/inputs/generate_dataset_for_linear_regression.py b/tests/mindspore_test_framework/components/inputs/generate_dataset_for_linear_regression.py index f173bb34c9818d4b5b331e3b8b4a5f7ebc165776..babda923103b612ab9e9859f1eaba3fcec76225e 100644 --- a/tests/mindspore_test_framework/components/inputs/generate_dataset_for_linear_regression.py +++ b/tests/mindspore_test_framework/components/inputs/generate_dataset_for_linear_regression.py @@ -30,9 +30,9 @@ class GenerateDataSetForLRDC(IDataComponent): 'batch_size': 20, } """ - def create_inputs(self, verification_set): + def __call__(self): result = [] - for config in verification_set[keyword.inputs]: + for config in self.verification_set[keyword.inputs]: desc_inputs = config[keyword.desc_inputs] config[keyword.desc_inputs] = generate_dataset_for_linear_regression(desc_inputs[keyword.true_params][0], desc_inputs[keyword.true_params][1], diff --git a/tests/mindspore_test_framework/components/inputs/generate_inputs_from_shape.py b/tests/mindspore_test_framework/components/inputs/generate_inputs_from_shape.py index ac57a106cc70269407b119464c63639dbb5bed94..dd17804c4ee4eb9c6500c6e41ecec73784dd6285 100644 --- a/tests/mindspore_test_framework/components/inputs/generate_inputs_from_shape.py +++ b/tests/mindspore_test_framework/components/inputs/generate_inputs_from_shape.py @@ -41,9 +41,9 @@ class GenerateFromShapeDC(IDataComponent): ([1, 16, 128, 64], np.float32, 6), # (inputs, dtype, scale) ] """ - def create_inputs(self, verification_set): + def __call__(self): result = [] - for config in verification_set[keyword.inputs]: + for config in self.verification_set[keyword.inputs]: desc_inputs = config[keyword.desc_inputs] add_fake_input = config.get(keyword.add_fake_input, False) fake_input_type = config.get(keyword.fake_input_type, np.float32) diff --git a/tests/mindspore_test_framework/components/inputs/get_inputs_from_config.py b/tests/mindspore_test_framework/components/inputs/get_inputs_from_config.py index 917e5d991cf9d80f92f656e5bcb0aa57d24af9c7..c158cb114a6734e73e1054202acd135a676c8d53 100644 --- a/tests/mindspore_test_framework/components/inputs/get_inputs_from_config.py +++ b/tests/mindspore_test_framework/components/inputs/get_inputs_from_config.py @@ -26,5 +26,5 @@ class IdentityDC(IDataComponent): np.array([[2, 2], [2, 2]]).astype(np.float32) ] """ - def create_inputs(self, verification_set): - return verification_set['inputs'] + def __call__(self): + return self.verification_set['inputs'] diff --git a/tests/mindspore_test_framework/components/inputs/load_inputs_from_npy.py b/tests/mindspore_test_framework/components/inputs/load_inputs_from_npy.py index c51c52da3f5e9161743a9d5a104281f66b2297e9..21e5e4616dbbde7a3170e5ca3672a3ccb7ae5eb2 100644 --- a/tests/mindspore_test_framework/components/inputs/load_inputs_from_npy.py +++ b/tests/mindspore_test_framework/components/inputs/load_inputs_from_npy.py @@ -43,9 +43,9 @@ class LoadFromNpyDC(IDataComponent): ([2, 2], np.float32, 6) ] """ - def create_inputs(self, verification_set): + def __call__(self): result = [] - for config in verification_set[keyword.inputs]: + for config in self.verification_set[keyword.inputs]: config[keyword.desc_inputs] = load_data_from_npy_or_shape(config[keyword.desc_inputs]) config[keyword.desc_bprop] = load_data_from_npy_or_shape(config.get(keyword.desc_bprop, [])) result.append(config) diff --git a/tests/mindspore_test_framework/components/verifier/compare_forward.py b/tests/mindspore_test_framework/components/verifier/compare_forward.py index fe2fea40242acbcc8d39401774cafd3da97279e0..bcef20348d23c626597c63564c88fd2d8c1825d6 100644 --- a/tests/mindspore_test_framework/components/verifier/compare_forward.py +++ b/tests/mindspore_test_framework/components/verifier/compare_forward.py @@ -41,5 +41,5 @@ class CompareWithVC(IVerifierComponent): 'max_error': 1e-3 } """ - def verify(self, expect, func_result, verification_set): - compare(expect, func_result, baseline=keyword.compare_with) + def __call__(self): + compare(self.expect, self.func_result, baseline=keyword.compare_with) diff --git a/tests/mindspore_test_framework/components/verifier/compare_gradient.py b/tests/mindspore_test_framework/components/verifier/compare_gradient.py index 8b8955578d5b13099dac20fca40d54d24795fdbd..09919ed219090fc7964893f52a1d1d3dbfb25085 100644 --- a/tests/mindspore_test_framework/components/verifier/compare_gradient.py +++ b/tests/mindspore_test_framework/components/verifier/compare_gradient.py @@ -35,5 +35,5 @@ class CompareGradientWithVC(IVerifierComponent): 'max_error': 1e-3 } """ - def verify(self, expect, func_result, verification_set): - compare(expect, func_result, baseline=keyword.compare_gradient_with) + def __call__(self): + compare(self.expect, self.func_result, baseline=keyword.compare_gradient_with) diff --git a/tests/mindspore_test_framework/components/verifier/verify_expect_from_npy.py b/tests/mindspore_test_framework/components/verifier/verify_expect_from_npy.py index bb62f789b73f6c2af8168922aff519ba7e58d9fd..19e9bbffaa94d01d33371193e662864d462fd4d1 100644 --- a/tests/mindspore_test_framework/components/verifier/verify_expect_from_npy.py +++ b/tests/mindspore_test_framework/components/verifier/verify_expect_from_npy.py @@ -37,10 +37,10 @@ class LoadFromNpyVC(IVerifierComponent): ([2, 2], np.float32, 6, 1e-3) # (shape, dtype, scale, max_error) ] """ - def verify(self, expect, func_result, verification_set): - dpaths = expect.get(keyword.desc_expect) + def __call__(self): + dpaths = self.expect.get(keyword.desc_expect) expects = load_data_from_npy_or_shape(dpaths, False) - results = func_result[keyword.result] + results = self.func_result[keyword.result] if results: results = to_numpy_list(results) for i, e in enumerate(expects): diff --git a/tests/mindspore_test_framework/components/verifier/verify_shapetype.py b/tests/mindspore_test_framework/components/verifier/verify_shapetype.py index 65f064a918e7320107c9ffb228f9544c22e048fd..9ba3371e45999b47251460da27ff9fa4ae91bde4 100644 --- a/tests/mindspore_test_framework/components/verifier/verify_shapetype.py +++ b/tests/mindspore_test_framework/components/verifier/verify_shapetype.py @@ -33,9 +33,9 @@ class ShapeTypeVC(IVerifierComponent): ] } """ - def verify(self, expect, func_result, verification_set): - results = to_numpy_list(func_result[keyword.result]) - expects = expect[keyword.desc_expect][keyword.shape_type] + def __call__(self): + results = to_numpy_list(self.func_result[keyword.result]) + expects = self.expect[keyword.desc_expect][keyword.shape_type] for i, e in enumerate(expects): if results[i].shape != e[keyword.shape] or results[i].dtype != e[keyword.type]: - raise TypeError(f'Error: expect {expect}, but got {func_result}') + raise TypeError(f'Error: expect {self.expect}, but got {self.func_result}') diff --git a/tests/mindspore_test_framework/mindspore_test.py b/tests/mindspore_test_framework/mindspore_test.py index bd638c93d55aa6892a730525975263e59764719a..fde26c94f11a6a443e7573a356efcf79f0c5945e 100644 --- a/tests/mindspore_test_framework/mindspore_test.py +++ b/tests/mindspore_test_framework/mindspore_test.py @@ -61,14 +61,13 @@ def mindspore_test(verification_pipeline): for component in facade_components: fc = component(verification_set) - fc.run() - verification_set = fc.get_result() + verification_set = fc() inputs = [] for component in data_components: dc = component(verification_set) - dc.run() - inputs.extend(dc.get_result()) + item = dc() + inputs.extend(item) if not inputs: logging.warning("Inputs set is empty.") @@ -76,8 +75,8 @@ def mindspore_test(verification_pipeline): functions = [] for component in builder_components: bc = component(verification_set) - bc.run() - functions.extend(bc.get_result()) + f = bc() + functions.extend(f) if not functions: logging.warning("Function set is empty.") @@ -85,8 +84,8 @@ def mindspore_test(verification_pipeline): fis = [] for component in fi_policy_components: fipc = component(verification_set, functions, inputs) - fipc.run() - fis.extend(fipc.get_result()) + result = fipc() + fis.extend(result) if not fis: logging.warning("Function inputs pair set is empty.") @@ -97,8 +96,8 @@ def mindspore_test(verification_pipeline): results = [] for component in executor_components: ec = component(verification_set, sut, inputs) - ec.run() - results.append(ec.get_result()) + result = ec() + results.append(result) if not results: logging.warning("Result set is empty.") @@ -106,8 +105,8 @@ def mindspore_test(verification_pipeline): expect_actuals = [] for component in er_policy_components: erpc = component(verification_set, verification_set['expect'], results) - erpc.run() - expect_actuals.extend(erpc.get_result()) + result = erpc() + expect_actuals.extend(result) if not expect_actuals: logging.warning("Expect Result pair set is empty.") @@ -115,11 +114,11 @@ def mindspore_test(verification_pipeline): for ea in expect_actuals: for component in verifier_components: vc = component(verification_set, *ea) - vc.run() + vc() def get_tc_name(f, inputs): - tc_id = f[keyword.id]+'-'+inputs[keyword.id] - group = f[keyword.group]+'-'+inputs[keyword.group] + tc_id = f[keyword.id] + '-' + inputs[keyword.id] + group = f[keyword.group] + '-' + inputs[keyword.group] return 'Group_' + group + '-' + 'Id_' + tc_id if fis: