Skip to content

Commit 04f9a16

Browse files
committed
Add economies of scale and discrete capacities to myopic capacities test
Signed-off-by: Davey Elder <iandavidelder@gmail.com>
1 parent 3123bf9 commit 04f9a16

3 files changed

Lines changed: 123 additions & 5 deletions

File tree

tests/test_full_runs.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,41 @@ def test_myopic_stress_tests(
171171
) -> None:
172172
"""
173173
The idea of these is that they should be tightly constrained so that if anything
174-
is wrong the model will fail to find a feasible solution. Use lots of equality constraints
174+
is wrong the model will fail to find a feasible solution. Use lots of equality constraints.
175+
176+
Two new paths test limit_discrete_capacity and limit_discrete_new_capacity with EoS costs
177+
and survival curves.
175178
"""
176179
_, _, _, sequencer = system_test_run
177180
import contextlib
178181

179182
with contextlib.closing(sqlite3.connect(sequencer.config.output_database)) as con:
180183
cur = con.cursor()
184+
dc_fixed = cur.execute(
185+
"SELECT SUM(fixed) FROM output_cost WHERE tech='tech_discrete_cap'"
186+
).fetchone()[0]
187+
dc_variable = cur.execute(
188+
"SELECT SUM(var) FROM output_cost WHERE tech='tech_discrete_cap'"
189+
).fetchone()[0]
190+
dnc_invest = cur.execute(
191+
"SELECT SUM(invest) FROM output_cost WHERE tech='tech_discrete_new_cap'"
192+
).fetchone()[0]
193+
194+
assert dc_fixed == pytest.approx(37, rel=1e-5), (
195+
'tech_discrete_cap fixed cost did not match expected'
196+
)
197+
assert dc_variable == pytest.approx(24, rel=1e-5), (
198+
'tech_discrete_cap variable cost did not match expected'
199+
)
200+
assert dnc_invest == pytest.approx(2.5, rel=1e-5), (
201+
'tech_discrete_new_cap invest cost did not match expected'
202+
)
203+
204+
# This part is just a very rough check on the objective function. Constraints inside the
205+
# model are extremely tight so other changes will likely lead to infeasibility
181206
res = cur.execute('SELECT SUM(total_system_cost) FROM main.output_objective').fetchone()
182207
obj = res[0]
183-
# This part is just a very rough check on the objective function. Constraints inside the
184-
# model are extremely tight so any other changes will lead to infeasibility
185-
assert obj == pytest.approx(32, abs=1), (
208+
assert obj == pytest.approx(309, rel=0.01), (
186209
'objective function value did not match expected for myopic stress test'
187210
)
188211

tests/testing_configs/config_myopic_capacities.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
scenario = "test myopic capacities"
22
scenario_mode = "myopic"
3-
extensions= ["growth_rates"]
3+
extensions= ["growth_rates", "discrete_capacity", "eos"]
44
input_database = "tests/testing_outputs/myopic_capacities.sqlite"
55
output_database = "tests/testing_outputs/myopic_capacities.sqlite"
66
neos = false

tests/testing_data/myopic_capacities.sql

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,98 @@ REPLACE INTO technology VALUES('tech_current','p','energy',NULL,NULL,0,0,0,0,1,0
240240
REPLACE INTO technology VALUES('tech_future','p','energy',NULL,NULL,0,0,0,0,1,0,0,0,NULL);
241241
REPLACE INTO technology VALUES('tech_retire','p','energy',NULL,NULL,0,0,0,0,1,0,0,0,NULL);
242242
REPLACE INTO time_season VALUES(0,'s',1.0,NULL);
243+
REPLACE INTO commodity VALUES('demand_dc','d',NULL,NULL);
244+
REPLACE INTO commodity VALUES('demand_dnc','d',NULL,NULL);
245+
REPLACE INTO technology VALUES('tech_discrete_cap','p','energy',NULL,NULL,0,0,0,0,1,0,0,0,NULL);
246+
REPLACE INTO technology VALUES('tech_dc_dummy','p','energy',NULL,NULL,1,0,0,0,0,0,0,0,NULL);
247+
REPLACE INTO technology VALUES('tech_discrete_new_cap','p','energy',NULL,NULL,0,0,0,0,1,0,0,0,NULL);
248+
REPLACE INTO technology VALUES('tech_dnc_dummy','p','energy',NULL,NULL,1,0,0,0,0,0,0,0,NULL);
249+
REPLACE INTO lifetime_tech VALUES('region','tech_discrete_cap',35.0,NULL,NULL);
250+
REPLACE INTO lifetime_tech VALUES('region','tech_dc_dummy',35.0,NULL,NULL);
251+
REPLACE INTO lifetime_tech VALUES('region','tech_discrete_new_cap',5.0,NULL,NULL);
252+
REPLACE INTO lifetime_tech VALUES('region','tech_dnc_dummy',35.0,NULL,NULL);
253+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2025,0.0,NULL);
254+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2030,0.0,NULL);
255+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2035,0.0,NULL);
256+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2040,0.0,NULL);
257+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2045,0.0,NULL);
258+
REPLACE INTO loan_rate VALUES('region','tech_discrete_new_cap',2050,0.0,NULL);
259+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_cap',2025,'demand_dc',1.0,NULL,NULL);
260+
REPLACE INTO efficiency VALUES('region','source','tech_dc_dummy',2025,'demand_dc',1.0,NULL,NULL);
261+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2025,'demand_dnc',1.0,NULL,NULL);
262+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2030,'demand_dnc',1.0,NULL,NULL);
263+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2035,'demand_dnc',1.0,NULL,NULL);
264+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2040,'demand_dnc',1.0,NULL,NULL);
265+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2045,'demand_dnc',1.0,NULL,NULL);
266+
REPLACE INTO efficiency VALUES('region','source','tech_discrete_new_cap',2050,'demand_dnc',1.0,NULL,NULL);
267+
REPLACE INTO efficiency VALUES('region','source','tech_dnc_dummy',2025,'demand_dnc',1.0,NULL,NULL);
268+
REPLACE INTO demand VALUES('region',2025,'demand_dc',2.0,NULL,NULL);
269+
REPLACE INTO demand VALUES('region',2030,'demand_dc',2.0,NULL,NULL);
270+
REPLACE INTO demand VALUES('region',2035,'demand_dc',2.0,NULL,NULL);
271+
REPLACE INTO demand VALUES('region',2040,'demand_dc',2.0,NULL,NULL);
272+
REPLACE INTO demand VALUES('region',2045,'demand_dc',2.0,NULL,NULL);
273+
REPLACE INTO demand VALUES('region',2050,'demand_dc',2.0,NULL,NULL);
274+
REPLACE INTO demand VALUES('region',2025,'demand_dnc',1.0,NULL,NULL);
275+
REPLACE INTO demand VALUES('region',2030,'demand_dnc',1.0,NULL,NULL);
276+
REPLACE INTO demand VALUES('region',2035,'demand_dnc',1.0,NULL,NULL);
277+
REPLACE INTO demand VALUES('region',2040,'demand_dnc',1.0,NULL,NULL);
278+
REPLACE INTO demand VALUES('region',2045,'demand_dnc',1.0,NULL,NULL);
279+
REPLACE INTO demand VALUES('region',2050,'demand_dnc',1.0,NULL,NULL);
280+
REPLACE INTO cost_variable VALUES('region',2025,'tech_dc_dummy',2025,10.0,NULL,NULL);
281+
REPLACE INTO cost_variable VALUES('region',2030,'tech_dc_dummy',2025,10.0,NULL,NULL);
282+
REPLACE INTO cost_variable VALUES('region',2035,'tech_dc_dummy',2025,10.0,NULL,NULL);
283+
REPLACE INTO cost_variable VALUES('region',2040,'tech_dc_dummy',2025,10.0,NULL,NULL);
284+
REPLACE INTO cost_variable VALUES('region',2045,'tech_dc_dummy',2025,10.0,NULL,NULL);
285+
REPLACE INTO cost_variable VALUES('region',2050,'tech_dc_dummy',2025,10.0,NULL,NULL);
286+
REPLACE INTO cost_variable VALUES('region',2025,'tech_dnc_dummy',2025,10.0,NULL,NULL);
287+
REPLACE INTO cost_variable VALUES('region',2030,'tech_dnc_dummy',2025,10.0,NULL,NULL);
288+
REPLACE INTO cost_variable VALUES('region',2035,'tech_dnc_dummy',2025,10.0,NULL,NULL);
289+
REPLACE INTO cost_variable VALUES('region',2040,'tech_dnc_dummy',2025,10.0,NULL,NULL);
290+
REPLACE INTO cost_variable VALUES('region',2045,'tech_dnc_dummy',2025,10.0,NULL,NULL);
291+
REPLACE INTO cost_variable VALUES('region',2050,'tech_dnc_dummy',2025,10.0,NULL,NULL);
292+
REPLACE INTO lifetime_survival_curve VALUES('region',2025,'tech_discrete_cap',2025,1.0,NULL);
293+
REPLACE INTO lifetime_survival_curve VALUES('region',2030,'tech_discrete_cap',2025,0.8,NULL);
294+
REPLACE INTO lifetime_survival_curve VALUES('region',2035,'tech_discrete_cap',2025,0.6,NULL);
295+
REPLACE INTO lifetime_survival_curve VALUES('region',2040,'tech_discrete_cap',2025,0.4,NULL);
296+
REPLACE INTO lifetime_survival_curve VALUES('region',2045,'tech_discrete_cap',2025,0.2,NULL);
297+
REPLACE INTO lifetime_survival_curve VALUES('region',2060,'tech_discrete_cap',2025,0.0,NULL);
298+
REPLACE INTO lifetime_survival_curve VALUES('region',2025,'tech_discrete_new_cap',2025,1.0,NULL);
299+
REPLACE INTO lifetime_survival_curve VALUES('region',2030,'tech_discrete_new_cap',2025,0.0,NULL);
300+
REPLACE INTO lifetime_survival_curve VALUES('region',2030,'tech_discrete_new_cap',2030,1.0,NULL);
301+
REPLACE INTO lifetime_survival_curve VALUES('region',2035,'tech_discrete_new_cap',2030,0.0,NULL);
302+
REPLACE INTO lifetime_survival_curve VALUES('region',2035,'tech_discrete_new_cap',2035,1.0,NULL);
303+
REPLACE INTO lifetime_survival_curve VALUES('region',2040,'tech_discrete_new_cap',2035,0.0,NULL);
304+
REPLACE INTO lifetime_survival_curve VALUES('region',2040,'tech_discrete_new_cap',2040,1.0,NULL);
305+
REPLACE INTO lifetime_survival_curve VALUES('region',2045,'tech_discrete_new_cap',2040,0.0,NULL);
306+
REPLACE INTO lifetime_survival_curve VALUES('region',2045,'tech_discrete_new_cap',2045,1.0,NULL);
307+
REPLACE INTO lifetime_survival_curve VALUES('region',2050,'tech_discrete_new_cap',2045,0.0,NULL);
308+
REPLACE INTO lifetime_survival_curve VALUES('region',2050,'tech_discrete_new_cap',2050,1.0,NULL);
309+
REPLACE INTO lifetime_survival_curve VALUES('region',2055,'tech_discrete_new_cap',2050,0.0,NULL);
310+
REPLACE INTO limit_discrete_capacity VALUES('region','tech_discrete_cap',0.2,NULL,NULL);
311+
REPLACE INTO limit_discrete_new_capacity VALUES('region','tech_discrete_new_cap',0.2,NULL,NULL);
312+
REPLACE INTO cost_invest_eos VALUES('region','tech_discrete_new_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
313+
REPLACE INTO cost_invest_eos VALUES('region','tech_discrete_new_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
314+
REPLACE INTO cost_fixed_eos VALUES('region',2025,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
315+
REPLACE INTO cost_fixed_eos VALUES('region',2025,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
316+
REPLACE INTO cost_fixed_eos VALUES('region',2030,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
317+
REPLACE INTO cost_fixed_eos VALUES('region',2030,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
318+
REPLACE INTO cost_fixed_eos VALUES('region',2035,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
319+
REPLACE INTO cost_fixed_eos VALUES('region',2035,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
320+
REPLACE INTO cost_fixed_eos VALUES('region',2040,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
321+
REPLACE INTO cost_fixed_eos VALUES('region',2040,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
322+
REPLACE INTO cost_fixed_eos VALUES('region',2045,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
323+
REPLACE INTO cost_fixed_eos VALUES('region',2045,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
324+
REPLACE INTO cost_fixed_eos VALUES('region',2050,'tech_discrete_cap',1,0.0,0.5,0.0,1.0,NULL,NULL);
325+
REPLACE INTO cost_fixed_eos VALUES('region',2050,'tech_discrete_cap',2,0.5,2.0,1.0,2.5,NULL,NULL);
326+
REPLACE INTO cost_variable_eos VALUES('region',2025,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
327+
REPLACE INTO cost_variable_eos VALUES('region',2025,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);
328+
REPLACE INTO cost_variable_eos VALUES('region',2030,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
329+
REPLACE INTO cost_variable_eos VALUES('region',2030,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);
330+
REPLACE INTO cost_variable_eos VALUES('region',2035,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
331+
REPLACE INTO cost_variable_eos VALUES('region',2035,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);
332+
REPLACE INTO cost_variable_eos VALUES('region',2040,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
333+
REPLACE INTO cost_variable_eos VALUES('region',2040,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);
334+
REPLACE INTO cost_variable_eos VALUES('region',2045,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
335+
REPLACE INTO cost_variable_eos VALUES('region',2045,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);
336+
REPLACE INTO cost_variable_eos VALUES('region',2050,'tech_discrete_cap',1,0.0,0.5,0.0,0.75,NULL,NULL);
337+
REPLACE INTO cost_variable_eos VALUES('region',2050,'tech_discrete_cap',2,0.5,2.0,0.75,1.5,NULL,NULL);

0 commit comments

Comments
 (0)