From 8d96626746a00eaea7fcf3c45229022910c74470 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 23 Sep 2022 12:54:59 +0200 Subject: ignore_param: work on by_name rather than observations --- lib/utils.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/utils.py b/lib/utils.py index 9914862..f81f8ff 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -302,14 +302,26 @@ def observations_enum_to_bool(observations: list, kconfig=False): binary_keys.add(binary_key) -def observations_ignore_param(observations: list, ignored_parameters: list) -> list: - unpoppable_params = set() - for observation in observations: - for ignored_parameter in ignored_parameters: - try: - observation["param"].pop(ignored_parameter) - except KeyError: - unpoppable_params.add(ignored_parameter) +def ignore_param(by_name: dict, parameter_names: list, ignored_parameters: list): + ignored_indexes = list() + unpoppable_params = list() + for param_name in sorted(ignored_parameters): + try: + ignored_indexes.append(parameter_names.index(param_name)) + except ValueError: + unpoppable_params.append(param_name) + + assert ignored_indexes == sorted(ignored_indexes) + ignored_indexes = sorted(ignored_indexes, reverse=True) + + for name in by_name: + for param in by_name[name]["param"]: + for ignored_index in ignored_indexes: + param.pop(ignored_index) + + for ignored_index in ignored_indexes: + parameter_names.pop(ignored_index) + if unpoppable_params: logger.info( f"ignore_param: Parameters {unpoppable_params} were not part of the observations to begin with" -- cgit v1.2.3