From f83cc85dc4b962672cc7b6b2b41d7438df29a3d0 Mon Sep 17 00:00:00 2001 From: adrivinca Date: Tue, 10 Dec 2024 11:51:47 +0100 Subject: [PATCH] Pre-filter remove.set to speed up the build process --- message_ix_models/model/water/build.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/message_ix_models/model/water/build.py b/message_ix_models/model/water/build.py index 0cdbbcc08..660f0495b 100644 --- a/message_ix_models/model/water/build.py +++ b/message_ix_models/model/water/build.py @@ -334,6 +334,16 @@ def get_spec(context: Context) -> Mapping[str, ScenarioInfo]: # Sets to add add.set[set_name].extend(config) + # clean the remove.set from things that are actually not in the scenario + # this saves building time significantly, as remove is slow + scen = context.get_scenario() + for category, elements in ((k, v) for k, v in remove.set.items() if k != "unit"): + # Get the corresponding set from the scenario + scen_set = scen.set(category) + + # Filter elements to keep only those present in the scenario set + remove.set[category] = [elem for elem in elements if elem in scen_set.values] + return dict(require=require, remove=remove, add=add)