
Dear Xi Xi,
Sorry for the delay in getting back to you! Is this happening with the “East_China_small” from the “Small” tutorial at https://switch-model.org/china_tutorial/index.html? Have you made any changes to the model data?
This error means that the BuildGen_assign_default_value component is trying to assign a value for BuildGen['Hydro_L', 1981] but that index is not valid for this variable. Looking for “BuildGen_assign_default_value” in the source code brings up switch_model/generators/core/build.py. There, we can see that BuildGen_assign_default_value gets its indexes from PREDETERMINED_GEN_BLD_YRS but BuildGen is indexed over GEN_BLD_YRS. So it sounds like there is an inconsistency between these sets.
PREDETERMINED_GEN_BLD_YRS comes from the gen_build_predetermined.csv file - it is combinations of (generator, year) when existing or planned capacity are added. GEN_BLD_YRS comes from gen_build_costs.csv - it is the (generator, year) combinations for which costs have been defined.
So most likely there is a line in your gen_build_predetermined.csv for ('Hydro_L', 1981), but not a cost for that generator and year in gen_build_costs.csv. (This is an easy mistake to make, and I will try to add a better error message in the next version of Switch.)
If you add a row with a cost for ('Hydro_L', 1981) in gen_build_costs.csv, that should fix the problem.
Matthias
From:
'Xi Xi' via Switch Model <switch...@googlegroups.com>
Date: Tuesday, April 23, 2024 at 6:59 PM
To: Switch Model <switch...@googlegroups.com>
Subject: [EXTERNAL] [switch-model] Re: error related to gen_build_predetermined
Here is a screenshot of the error message.

On Tuesday, April 23, 2024 at 6:53:52 PM UTC-7 Xi Xi wrote:
When I'm trying to solve the model, I get this message:
ERROR: Constructing component 'BuildGen_assign_default_value' from data=None
failed:
KeyError: "Index '('Hydro_L', 1981)' is not valid for indexed
component 'BuildGen'"
I can't figure out what the problem would be...this is the first line of gen_build_predetermined.csv and if I clear the file, the model solves. I'm sure the GENERATION_PROJECT columns match that of gen_info. I checked the data types as well - if I import the csv file with pandas dataframe, the datatypes are object, integer, and float. What am I missing here?
--
You received this message because you are subscribed to the Google Groups "Switch Model" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
switch-model...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/switch-model/e0c3cf82-95b8-4681-9f36-738c3429b4d7n%40googlegroups.com.