create operators based on the config Args: params(list): a dict list, used to create some operators
(op_param_list, global_config=None)
| 77 | |
| 78 | |
| 79 | def create_operators(op_param_list, global_config=None): |
| 80 | """ |
| 81 | create operators based on the config |
| 82 | |
| 83 | Args: |
| 84 | params(list): a dict list, used to create some operators |
| 85 | """ |
| 86 | assert isinstance(op_param_list, list), "operator config should be a list" |
| 87 | ops = [] |
| 88 | for operator in op_param_list: |
| 89 | assert isinstance(operator, dict) and len(operator) == 1, "yaml format error" |
| 90 | op_name = list(operator)[0] |
| 91 | param = {} if operator[op_name] is None else operator[op_name] |
| 92 | if global_config is not None: |
| 93 | param.update(global_config) |
| 94 | op = eval(op_name)(**param) |
| 95 | ops.append(op) |
| 96 | return ops |