Skip to content

Commit

Permalink
Add resource area group constraint tests (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering authored and sjpfenninger committed Jun 27, 2019
1 parent 634ffd4 commit 035faf6
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 58 deletions.
2 changes: 1 addition & 1 deletion calliope/config/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tech_groups:
storage:
required_constraints: []
allowed_constraints: ['charge_rate', 'energy_cap_per_storage_cap_min', 'energy_cap_per_storage_cap_max', 'energy_cap_per_storage_cap_equals', 'energy_cap_equals', 'energy_cap_equals_systemwide', 'energy_cap_max', 'energy_cap_max_systemwide', 'energy_cap_min', 'energy_cap_min_use', 'energy_cap_per_unit', 'energy_cap_scale', 'energy_con', 'energy_eff', 'energy_prod', 'energy_ramping', 'export_cap', 'export_carrier', 'force_asynchronous_prod_con', 'lifetime', 'storage_cap_equals', 'storage_cap_max', 'storage_cap_min', 'storage_cap_per_unit', 'storage_initial', 'storage_loss', 'storage_time_max', 'units_equals', 'units_equals_systemwide', 'units_max', 'units_max_systemwide', 'units_min']
allowed_group_constraints: [cost_max, cost_min, cost_equals, cost_var_max, cost_var_min, cost_var_equals, cost_investment_min, cost_investment_max, cost_investment_equals, energy_cap_share_min, energy_cap_share_max, energy_cap_min, energy_cap_max, resource_area_min, resource_area_max]
allowed_group_constraints: [cost_max, cost_min, cost_equals, cost_var_max, cost_var_min, cost_var_equals, cost_investment_min, cost_investment_max, cost_investment_equals, energy_cap_share_min, energy_cap_share_max, energy_cap_min, energy_cap_max]
allowed_costs: ['depreciation_rate', 'energy_cap', 'export', 'interest_rate', 'om_annual', 'om_annual_investment_fraction', 'om_prod', 'purchase', 'storage_cap']
essentials:
parent: null
Expand Down
6 changes: 4 additions & 2 deletions calliope/core/preprocess/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,10 @@ def check_final(model_run):
'All technologies were requested for inclusion in group constraint '
'`{}`, but those from tech group(s) `{}` have been ignored as one '
'or more of the constraints cannot be applied to technologies '
'in these groups'
.format(group_constraint_name, dropped_tech_groups | unallowed_tech_groups)
'in these groups'.format(
group_constraint_name,
sorted(dropped_tech_groups | unallowed_tech_groups)
)
)
else:
trans_techs = set(requested_techs).intersection(model_run.sets['techs_transmission_names'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import:
- scenarios_add_techs.yaml
- scenarios_energy_cap.yaml
- scenarios_energy_cap_share.yaml
- scenarios_resource_area.yaml

model:
name: Group share constraint test model
Expand All @@ -19,6 +20,7 @@ tech_groups:
constraints:
lifetime: 25
energy_cap_max: .inf
resource_area_per_energy_cap: 2
costs:
monetary:
interest_rate: 0.1
Expand All @@ -29,6 +31,7 @@ tech_groups:
constraints:
lifetime: 25
energy_cap_max: .inf
resource_area_per_energy_cap: 2
costs:
monetary:
interest_rate: 0.1
Expand All @@ -39,6 +42,7 @@ tech_groups:
constraints:
lifetime: 25
energy_cap_max: .inf
resource_area_per_energy_cap: 2
costs:
monetary:
interest_rate: 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,23 @@ overrides:
interest_rate: 0.1
om_prod: 0.001
energy_cap: 0.001
locations.1.techs: {elec_storage}
locations.1.techs: {elec_storage}

add_elec_supply_plus:
techs.elec_supply_plus:
essentials:
name: Electricity supply plus
carrier: electricity
parent: supply_plus
constraints:
lifetime: 15
storage_loss: 0.001
resource: file=supply_simple.csv
parasitic_eff: 0.95
resource_area_per_energy_cap: 2
costs:
monetary:
interest_rate: 0.1
om_prod: 0.001
energy_cap: 0.001
locations.0,1.techs: {elec_supply_plus}
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ scenarios:
energy_cap_min_all_techs: [
energy_cap_min, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
energy_cap_max_all_techs: [
energy_cap_max_high, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
energy_cap_max_all_techs_infeasible: [
energy_cap_max, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ scenarios:
energy_cap_share_min_all_techs: [
energy_cap_share_min, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
energy_cap_share_max_all_techs: [
energy_cap_share_max_high, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
energy_cap_share_max_all_techs_infeasible: [
energy_cap_share_max, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand, add_elec_supply_plus
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ energy_cap_min_all_techs:
'1::expensive_elec_supply', '0::cheap_elec_transmission:1',
'1::cheap_elec_supply', '0::normal_elec_supply',
'1::normal_elec_supply', '1::elec_storage', '0::expensive_elec_supply',
'1::cheap_elec_transmission:0']]
'1::cheap_elec_transmission:0', '0::elec_supply_plus',
'1::elec_supply_plus']]
energy_cap_max_all_techs:
constraint: [energy_cap_max]
group_name: [example_energy_cap_constraint]
Expand All @@ -29,7 +30,8 @@ energy_cap_max_all_techs:
'1::expensive_elec_supply', '0::cheap_elec_transmission:1',
'1::cheap_elec_supply', '0::normal_elec_supply',
'1::normal_elec_supply', '1::elec_storage', '0::expensive_elec_supply',
'1::cheap_elec_transmission:0']]
'1::cheap_elec_transmission:0', '0::elec_supply_plus',
'1::elec_supply_plus']]

energy_cap_share_min_max_supply:
constraint: [energy_cap_share_min, energy_cap_share_max]
Expand All @@ -50,12 +52,38 @@ energy_cap_share_min_all_techs:
'1::elec_to_heat_cool_linked', '1::elec_to_heat',
'1::expensive_elec_supply', '1::cheap_elec_supply',
'0::normal_elec_supply', '1::normal_elec_supply',
'0::expensive_elec_supply']]
'0::expensive_elec_supply', '0::elec_supply_plus',
'1::elec_supply_plus']]
energy_cap_share_max_all_techs:
constraint: [energy_cap_share_max]
group_name: [example_energy_cap_share_constraint]
loc_techs: [['1::elec_to_heat_cool_unlinked', '0::cheap_elec_supply',
'1::elec_to_heat_cool_linked', '1::elec_to_heat',
'1::expensive_elec_supply', '1::cheap_elec_supply',
'0::normal_elec_supply', '1::normal_elec_supply',
'0::expensive_elec_supply']]
'0::expensive_elec_supply', '0::elec_supply_plus',
'1::elec_supply_plus']]


resource_area_min_max_supply:
constraint: [resource_area_min, resource_area_max]
group_name: [example_resource_area_constraint, example_resource_area_max_constraint]
loc_techs: [[0::expensive_elec_supply, 1::expensive_elec_supply], [0::cheap_elec_supply, 1::cheap_elec_supply]]
resource_area_min_max_supply_loc_0_1:
constraint: [resource_area_min, resource_area_max]
group_name: [example_resource_area_constraint, example_resource_area_max_constraint]
loc_techs: [[0::expensive_elec_supply], [1::cheap_elec_supply]]
resource_area_min_all_techs:
constraint: [resource_area_min]
group_name: [example_resource_area_constraint]
loc_techs: [['0::cheap_elec_supply', '1::cheap_elec_supply',
'0::expensive_elec_supply', '1::expensive_elec_supply',
'0::normal_elec_supply', '1::normal_elec_supply',
'0::elec_supply_plus', '1::elec_supply_plus']]
resource_area_max_all_techs:
constraint: [resource_area_max]
group_name: [example_resource_area_constraint]
loc_techs: [['0::cheap_elec_supply', '1::cheap_elec_supply',
'0::expensive_elec_supply', '1::expensive_elec_supply',
'0::normal_elec_supply', '1::normal_elec_supply',
'0::elec_supply_plus', '1::elec_supply_plus']]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

overrides:

resource_area_min:
group_constraints.example_resource_area_constraint:
resource_area_min: 12

resource_area_max:
group_constraints.example_resource_area_constraint:
resource_area_max: 28

resource_area_max_high:
group_constraints.example_resource_area_constraint:
resource_area_max: 46

resource_area_max_low:
group_constraints.example_resource_area_constraint:
resource_area_max: 2

resource_area_loc_0:
group_constraints.example_resource_area_constraint:
locs: ["0"]

resource_area_max_cheap_supply:
group_constraints.example_resource_area_max_constraint:
resource_area_max: 8
techs: ["cheap_elec_supply"]

resource_area_max_loc_1:
group_constraints.example_resource_area_max_constraint:
locs: ["1"]

resource_area_cheap_supply:
group_constraints.example_resource_area_constraint:
techs: ["cheap_elec_supply"]

resource_area_expensive_supply:
group_constraints.example_resource_area_constraint:
techs: ["expensive_elec_supply"]

scenarios:
resource_area_max_supply: [resource_area_max, resource_area_cheap_supply]
resource_area_min_supply: [resource_area_min, resource_area_expensive_supply]
resource_area_min_max_supply: [
resource_area_max_cheap_supply, resource_area_min,
resource_area_expensive_supply
]
resource_area_max_supply_loc_1: [resource_area_max_loc_1, resource_area_max_cheap_supply]
resource_area_min_supply_loc_0: [
resource_area_min, resource_area_loc_0,
resource_area_expensive_supply
]
resource_area_min_max_supply_loc_0_1: [
resource_area_min, resource_area_max_loc_1,
resource_area_max_cheap_supply, resource_area_loc_0, resource_area_expensive_supply
]
resource_area_min_all_techs: [
resource_area_min, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand,
add_elec_supply_plus
]
resource_area_max_all_techs: [
resource_area_max_high, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand,
add_elec_supply_plus
]
resource_area_max_all_techs_infeasible: [
resource_area_max, add_expensive_elec_transmission, add_elec_storage,
add_elec_to_heat_conversion, add_elec_to_heat_cooling_linked_conversion_plus,
add_elec_to_heat_cooling_unlinked_conversion_plus, add_heat_demand, add_cooling_demand,
add_elec_supply_plus
]
27 changes: 27 additions & 0 deletions calliope/test/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,30 @@ def check_variable_exists(backend_model, constraint, variable):
variables = identify_variables(v.body)
exists.append(any(variable in j.getname() for j in list(variables)))
return any(exists)


def get_indexed_constraint_body(backend_model, constraint, input_index):
"""
Return all indeces of a specific decision variable used in a constraint.
This is useful to check that all expected loc_techs are in a summation.
Parameters
----------
backend_model : Pyomo ConcreteModel
constraint : str,
Name of constraint which could exist in the backend
input_index : tuple or string,
The index of the constraint in which to look for a the variable.
The index may impact the index of the decision ariable
"""
constraint_index = [
v for v in getattr(backend_model, constraint).values()
if v.index() == input_index
]
if len(constraint_index) == 0:
raise KeyError(
'Unable to find index {} in constraint {}'.format(input_index, constraint)
)
else:
return constraint_index[0].body
Loading

0 comments on commit 035faf6

Please sign in to comment.