Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wat ssp upd4 #268

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions message_ix_models/data/water/set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cooling:
- cooling__loil_cc
- cooling__loil_ppl
- cooling__nuc_hc
- cooling__nuc_lc
- cooling__solar_th_ppl
- cooling__csp_sm1_ppl
- cooling__csp_sm3_ppl
Expand Down Expand Up @@ -94,105 +95,87 @@ cooling:
- extract__saline_supply
- bio_hpl__ot_fresh
- bio_hpl__cl_fresh
- bio_hpl__cl_fresh
- bio_hpl__ot_saline
- bio_hpl__air
- bio_istig__ot_fresh
- bio_istig__cl_fresh
- bio_istig__cl_fresh
- bio_istig__ot_saline
- bio_istig__air
- bio_istig_ccs__ot_fresh
- bio_istig_ccs__cl_fresh
- bio_istig_ccs__cl_fresh
- bio_istig_ccs__ot_saline
- bio_istig_ccs__air
- bio_ppl__ot_fresh
- bio_ppl__cl_fresh
- bio_ppl__cl_fresh
- bio_ppl__ot_saline
- bio_ppl__air
- coal_adv__ot_fresh
- coal_adv__cl_fresh
- coal_adv__cl_fresh
- coal_adv__ot_saline
- coal_adv__air
- coal_adv_ccs__ot_fresh
- coal_adv_ccs__cl_fresh
- coal_adv_ccs__cl_fresh
- coal_adv_ccs__ot_saline
- coal_ppl__ot_fresh
- coal_ppl__cl_fresh
- coal_ppl__cl_fresh
- coal_ppl__ot_saline
- coal_ppl__air
- coal_ppl_u__ot_fresh
- coal_ppl_u__cl_fresh
- coal_ppl_u__cl_fresh
- coal_ppl_u__ot_saline
- coal_ppl_u__air
- foil_hpl__ot_fresh
- foil_hpl__cl_fresh
- foil_hpl__cl_fresh
- foil_hpl__ot_saline
- foil_hpl__air
- foil_ppl__ot_fresh
- foil_ppl__cl_fresh
- foil_ppl__cl_fresh
- foil_ppl__ot_saline
- foil_ppl__air
- gas_cc__ot_fresh
- gas_cc__cl_fresh
- gas_cc__cl_fresh
- gas_cc__ot_saline
- gas_cc__air
- gas_cc_ccs__ot_fresh
- gas_cc_ccs__cl_fresh
- gas_cc_ccs__cl_fresh
- gas_cc_ccs__ot_saline
- gas_hpl__ot_fresh
- gas_hpl__cl_fresh
- gas_hpl__cl_fresh
- gas_hpl__ot_saline
- gas_hpl__air
- gas_ppl__ot_fresh
- gas_ppl__cl_fresh
- gas_ppl__cl_fresh
- gas_ppl__ot_saline
- gas_ppl__air
- geo_hpl__ot_fresh
- geo_hpl__cl_fresh
- geo_hpl__cl_fresh
- geo_hpl__ot_saline
- geo_hpl__air
- geo_ppl__ot_fresh
- geo_ppl__cl_fresh
- geo_ppl__cl_fresh
- geo_ppl__ot_saline
- geo_ppl__air
- igcc__ot_fresh
- igcc__cl_fresh
- igcc__cl_fresh
- igcc__ot_saline
- igcc__air
- igcc_ccs__ot_fresh
- igcc_ccs__cl_fresh
- igcc_ccs__cl_fresh
- igcc_ccs__ot_saline
- loil_cc__ot_fresh
- loil_cc__cl_fresh
- loil_cc__cl_fresh
- loil_cc__ot_saline
- loil_cc__air
- loil_ppl__ot_fresh
- loil_ppl__cl_fresh
- loil_ppl__cl_fresh
- loil_ppl__ot_saline
- loil_ppl__air
- nuc_hc__ot_fresh
- nuc_hc__cl_fresh
- nuc_hc__cl_fresh
- nuc_hc__ot_saline
- nuc_lc__ot_fresh
- nuc_lc__cl_fresh
- nuc_lc__ot_saline
- solar_th_ppl__ot_fresh
- solar_th_ppl__cl_fresh
- solar_th_ppl__ot_saline
Expand Down Expand Up @@ -363,6 +346,10 @@ cooling:
- nuc_hc__cl_fresh
- nuc_hc__ot_saline
- nuc_hc__air
- nuc_lc__ot_fresh
- nuc_lc__cl_fresh
- nuc_lc__ot_saline
- nuc_lc__air
- solar_th_ppl__ot_fresh
- solar_th_ppl__cl_fresh
- solar_th_ppl__ot_saline
Expand Down
10 changes: 10 additions & 0 deletions message_ix_models/model/water/build.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a for inside a for inside a for? I'm surprised that this is the faster solution, it doesn't seem very efficient. Without spending more time, I'm not sure how to improve this, though, and if you say it's an improvement, then it's fine with me :)

Copy link
Contributor Author

@adrivinca adrivinca Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the thing is that for any item to be removed, the message_ix_models.model.build.apply_spec() checks if elements exist and proceeds or says that there are no elements. This is very slow.
now we just exclude in advance sets from the remove list that we know are not in the scenario, so that they do not get sent to apply_spec()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a serious problem and/or you know a solution for it, please record it in a new issue. This will raise awareness and eventually lead to a solution :)

Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading