Skip to content

Commit b192916

Browse files
committed
Update Effect name in tests to be 'costs' instead of 'Costs' Everywhere
1 parent a8d30f4 commit b192916

6 files changed

Lines changed: 54 additions & 54 deletions

File tree

tests/test_effect.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_shares(self, basic_flow_system_linopy):
204204
class TestEffectResults:
205205
def test_shares(self, basic_flow_system_linopy):
206206
flow_system = basic_flow_system_linopy
207-
flow_system.effects['Costs'].specific_share_to_other_effects_operation['Effect1'] = 0.5
207+
flow_system.effects['costs'].specific_share_to_other_effects_operation['Effect1'] = 0.5
208208
flow_system.add_elements(
209209
fx.Effect(
210210
'Effect1',
@@ -230,9 +230,9 @@ def test_shares(self, basic_flow_system_linopy):
230230

231231
effect_share_factors = {
232232
'operation': {
233-
('Costs', 'Effect1'): 0.5,
234-
('Costs', 'Effect2'): 0.5 * 1.1,
235-
('Costs', 'Effect3'): 0.5 * 1.1 * 5 + 0.5 * 1.2, # This is where the issue lies
233+
('costs', 'Effect1'): 0.5,
234+
('costs', 'Effect2'): 0.5 * 1.1,
235+
('costs', 'Effect3'): 0.5 * 1.1 * 5 + 0.5 * 1.2, # This is where the issue lies
236236
('Effect1', 'Effect2'): 1.1,
237237
('Effect1', 'Effect3'): 1.2 + 1.1 * 5,
238238
('Effect2', 'Effect3'): 5,
@@ -249,8 +249,8 @@ def test_shares(self, basic_flow_system_linopy):
249249
np.testing.assert_allclose(results.effect_share_factors['invest'][key].values, value)
250250

251251
xr.testing.assert_allclose(
252-
results.effects_per_component('operation').sum('component')['Costs'],
253-
results.solution['Costs(operation)|total_per_timestep'].fillna(0),
252+
results.effects_per_component('operation').sum('component')['costs'],
253+
results.solution['costs(operation)|total_per_timestep'].fillna(0),
254254
)
255255

256256
xr.testing.assert_allclose(
@@ -270,7 +270,7 @@ def test_shares(self, basic_flow_system_linopy):
270270

271271
# Invest mode checks
272272
xr.testing.assert_allclose(
273-
results.effects_per_component('invest').sum('component')['Costs'], results.solution['Costs(invest)|total']
273+
results.effects_per_component('invest').sum('component')['costs'], results.solution['costs(invest)|total']
274274
)
275275

276276
xr.testing.assert_allclose(
@@ -290,7 +290,7 @@ def test_shares(self, basic_flow_system_linopy):
290290

291291
# Total mode checks
292292
xr.testing.assert_allclose(
293-
results.effects_per_component('total').sum('component')['Costs'], results.solution['Costs|total']
293+
results.effects_per_component('total').sum('component')['costs'], results.solution['costs|total']
294294
)
295295

296296
xr.testing.assert_allclose(

tests/test_effects_shares_summation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,27 @@ def test_effect_shares_example():
9999
"""Test the specific example from the effects share factors test."""
100100
# Create the conversion dictionary based on test example
101101
conversion_dict = {
102-
'Costs': {'Effect1': xr.DataArray(0.5)},
102+
'costs': {'Effect1': xr.DataArray(0.5)},
103103
'Effect1': {'Effect2': xr.DataArray(1.1), 'Effect3': xr.DataArray(1.2)},
104104
'Effect2': {'Effect3': xr.DataArray(5.0)},
105105
}
106106

107107
result = calculate_all_conversion_paths(conversion_dict)
108108

109109
# Test direct paths
110-
assert result[('Costs', 'Effect1')].item() == 0.5
110+
assert result[('costs', 'Effect1')].item() == 0.5
111111
assert result[('Effect1', 'Effect2')].item() == 1.1
112112
assert result[('Effect2', 'Effect3')].item() == 5.0
113113

114114
# Test indirect paths
115-
# Costs -> Effect2 = Costs -> Effect1 -> Effect2 = 0.5 * 1.1
116-
assert result[('Costs', 'Effect2')].item() == 0.5 * 1.1
115+
# costs -> Effect2 = costs -> Effect1 -> Effect2 = 0.5 * 1.1
116+
assert result[('costs', 'Effect2')].item() == 0.5 * 1.1
117117

118-
# Costs -> Effect3 has two paths:
119-
# 1. Costs -> Effect1 -> Effect3 = 0.5 * 1.2 = 0.6
120-
# 2. Costs -> Effect1 -> Effect2 -> Effect3 = 0.5 * 1.1 * 5 = 2.75
118+
# costs -> Effect3 has two paths:
119+
# 1. costs -> Effect1 -> Effect3 = 0.5 * 1.2 = 0.6
120+
# 2. costs -> Effect1 -> Effect2 -> Effect3 = 0.5 * 1.1 * 5 = 2.75
121121
# Total = 0.6 + 2.75 = 3.35
122-
assert result[('Costs', 'Effect3')].item() == 0.5 * 1.2 + 0.5 * 1.1 * 5
122+
assert result[('costs', 'Effect3')].item() == 0.5 * 1.2 + 0.5 * 1.1 * 5
123123

124124
# Effect1 -> Effect3 has two paths:
125125
# 1. Effect1 -> Effect2 -> Effect3 = 1.1 * 5.0 = 5.5

tests/test_flow.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ def test_effects_per_flow_hour(self, basic_flow_system_linopy):
101101
co2_per_flow_hour = xr.DataArray(np.linspace(4, 5, timesteps.size), coords=(timesteps,))
102102

103103
flow = fx.Flow(
104-
'Wärme', bus='Fernwärme', effects_per_flow_hour={'Costs': costs_per_flow_hour, 'CO2': co2_per_flow_hour}
104+
'Wärme', bus='Fernwärme', effects_per_flow_hour={'costs': costs_per_flow_hour, 'CO2': co2_per_flow_hour}
105105
)
106106
flow_system.add_elements(fx.Sink('Sink', sink=flow), fx.Effect('CO2', 't', ''))
107107
model = create_linopy_model(flow_system)
108-
costs, co2 = flow_system.effects['Costs'], flow_system.effects['CO2']
108+
costs, co2 = flow_system.effects['costs'], flow_system.effects['CO2']
109109

110110
assert_sets_equal(
111111
set(flow.submodel.variables),
@@ -114,12 +114,12 @@ def test_effects_per_flow_hour(self, basic_flow_system_linopy):
114114
)
115115
assert_sets_equal(set(flow.submodel.constraints), {'Sink(Wärme)|total_flow_hours'}, msg='Incorrect constraints')
116116

117-
assert 'Sink(Wärme)->Costs(operation)' in set(costs.submodel.constraints)
117+
assert 'Sink(Wärme)->costs(operation)' in set(costs.submodel.constraints)
118118
assert 'Sink(Wärme)->CO2(operation)' in set(co2.submodel.constraints)
119119

120120
assert_conequal(
121-
model.constraints['Sink(Wärme)->Costs(operation)'],
122-
model.variables['Sink(Wärme)->Costs(operation)']
121+
model.constraints['Sink(Wärme)->costs(operation)'],
122+
model.variables['Sink(Wärme)->costs(operation)']
123123
== flow.submodel.variables['Sink(Wärme)|flow_rate'] * model.hours_per_step * costs_per_flow_hour,
124124
)
125125

@@ -426,22 +426,22 @@ def test_flow_invest_with_effects(self, basic_flow_system_linopy):
426426
minimum_size=20,
427427
maximum_size=100,
428428
optional=True,
429-
fix_effects={'Costs': 1000, 'CO2': 5}, # Fixed investment effects
430-
specific_effects={'Costs': 500, 'CO2': 0.1}, # Specific investment effects
429+
fix_effects={'costs': 1000, 'CO2': 5}, # Fixed investment effects
430+
specific_effects={'costs': 500, 'CO2': 0.1}, # Specific investment effects
431431
),
432432
)
433433

434434
flow_system.add_elements(fx.Sink('Sink', sink=flow), co2)
435435
model = create_linopy_model(flow_system)
436436

437437
# Check investment effects
438-
assert 'Sink(Wärme)->Costs(invest)' in model.variables
438+
assert 'Sink(Wärme)->costs(invest)' in model.variables
439439
assert 'Sink(Wärme)->CO2(invest)' in model.variables
440440

441441
# Check fix effects (applied only when is_invested=1)
442442
assert_conequal(
443-
model.constraints['Sink(Wärme)->Costs(invest)'],
444-
model.variables['Sink(Wärme)->Costs(invest)']
443+
model.constraints['Sink(Wärme)->costs(invest)'],
444+
model.variables['Sink(Wärme)->costs(invest)']
445445
== flow.submodel.variables['Sink(Wärme)|is_invested'] * 1000
446446
+ flow.submodel.variables['Sink(Wärme)|size'] * 500,
447447
)
@@ -464,19 +464,19 @@ def test_flow_invest_divest_effects(self, basic_flow_system_linopy):
464464
minimum_size=20,
465465
maximum_size=100,
466466
optional=True,
467-
divest_effects={'Costs': 500}, # Cost incurred when NOT investing
467+
divest_effects={'costs': 500}, # Cost incurred when NOT investing
468468
),
469469
)
470470

471471
flow_system.add_elements(fx.Sink('Sink', sink=flow))
472472
model = create_linopy_model(flow_system)
473473

474474
# Check divestment effects
475-
assert 'Sink(Wärme)->Costs(invest)' in model.constraints
475+
assert 'Sink(Wärme)->costs(invest)' in model.constraints
476476

477477
assert_conequal(
478-
model.constraints['Sink(Wärme)->Costs(invest)'],
479-
model.variables['Sink(Wärme)->Costs(invest)'] + (model.variables['Sink(Wärme)|is_invested'] - 1) * 500 == 0,
478+
model.constraints['Sink(Wärme)->costs(invest)'],
479+
model.variables['Sink(Wärme)->costs(invest)'] + (model.variables['Sink(Wärme)|is_invested'] - 1) * 500 == 0,
480480
)
481481

482482

@@ -558,12 +558,12 @@ def test_effects_per_running_hour(self, basic_flow_system_linopy):
558558
'Wärme',
559559
bus='Fernwärme',
560560
on_off_parameters=fx.OnOffParameters(
561-
effects_per_running_hour={'Costs': costs_per_running_hour, 'CO2': co2_per_running_hour}
561+
effects_per_running_hour={'costs': costs_per_running_hour, 'CO2': co2_per_running_hour}
562562
),
563563
)
564564
flow_system.add_elements(fx.Sink('Sink', sink=flow), fx.Effect('CO2', 't', ''))
565565
model = create_linopy_model(flow_system)
566-
costs, co2 = flow_system.effects['Costs'], flow_system.effects['CO2']
566+
costs, co2 = flow_system.effects['costs'], flow_system.effects['CO2']
567567

568568
assert_sets_equal(
569569
set(flow.submodel.variables),
@@ -586,12 +586,12 @@ def test_effects_per_running_hour(self, basic_flow_system_linopy):
586586
msg='Incorrect constraints',
587587
)
588588

589-
assert 'Sink(Wärme)->Costs(operation)' in set(costs.submodel.constraints)
589+
assert 'Sink(Wärme)->costs(operation)' in set(costs.submodel.constraints)
590590
assert 'Sink(Wärme)->CO2(operation)' in set(co2.submodel.constraints)
591591

592592
assert_conequal(
593-
model.constraints['Sink(Wärme)->Costs(operation)'],
594-
model.variables['Sink(Wärme)->Costs(operation)']
593+
model.constraints['Sink(Wärme)->costs(operation)'],
594+
model.variables['Sink(Wärme)->costs(operation)']
595595
== flow.submodel.variables['Sink(Wärme)|on'] * model.hours_per_step * costs_per_running_hour,
596596
)
597597

@@ -943,7 +943,7 @@ def test_switch_on_constraints(self, basic_flow_system_linopy):
943943
size=100,
944944
on_off_parameters=fx.OnOffParameters(
945945
switch_on_total_max=5, # Maximum 5 startups
946-
effects_per_switch_on={'Costs': 100}, # 100 EUR startup cost
946+
effects_per_switch_on={'costs': 100}, # 100 EUR startup cost
947947
),
948948
)
949949

@@ -984,12 +984,12 @@ def test_switch_on_constraints(self, basic_flow_system_linopy):
984984
)
985985

986986
# Check that startup cost effect constraint exists
987-
assert 'Sink(Wärme)->Costs(operation)' in model.constraints
987+
assert 'Sink(Wärme)->costs(operation)' in model.constraints
988988

989989
# Verify the startup cost effect constraint
990990
assert_conequal(
991-
model.constraints['Sink(Wärme)->Costs(operation)'],
992-
model.variables['Sink(Wärme)->Costs(operation)'] == flow.submodel.variables['Sink(Wärme)|switch|on'] * 100,
991+
model.constraints['Sink(Wärme)->costs(operation)'],
992+
model.variables['Sink(Wärme)->costs(operation)'] == flow.submodel.variables['Sink(Wärme)|switch|on'] * 100,
993993
)
994994

995995
def test_on_hours_limits(self, basic_flow_system_linopy):

tests/test_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_piecewise_conversion(self, flow_system_piecewise_conversion, highs_solv
248248
assert_almost_equal_numeric(
249249
comps['Speicher'].submodel.variables['Speicher|PiecewiseEffects|costs'].solution.values,
250250
454.74666666666667,
251-
'Speicher investCosts_segmented_costs doesnt match expected value',
251+
'Speicher investcosts_segmented_costs doesnt match expected value',
252252
)
253253

254254

@@ -309,13 +309,13 @@ def test_modeling_types_costs(self, modeling_calculation):
309309
assert_almost_equal_numeric(
310310
calc.results.model['costs|total'].solution.item(),
311311
expected_costs[modeling_type],
312-
f'Costs do not match for {modeling_type} modeling type',
312+
f'costs do not match for {modeling_type} modeling type',
313313
)
314314
else:
315315
assert_almost_equal_numeric(
316316
calc.results.solution_without_overlap('costs(operation)|total_per_timestep').sum(),
317317
expected_costs[modeling_type],
318-
f'Costs do not match for {modeling_type} modeling type',
318+
f'costs do not match for {modeling_type} modeling type',
319319
)
320320

321321
def test_segmented_io(self, modeling_calculation):

tests/test_linear_converter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_linear_converter_with_on_off(self, basic_flow_system_linopy):
146146

147147
# Create OnOffParameters
148148
on_off_params = fx.OnOffParameters(
149-
on_hours_total_min=10, on_hours_total_max=40, effects_per_running_hour={'Costs': 5}
149+
on_hours_total_min=10, on_hours_total_max=40, effects_per_running_hour={'costs': 5}
150150
)
151151

152152
# Create a linear converter with OnOffParameters
@@ -186,10 +186,10 @@ def test_linear_converter_with_on_off(self, basic_flow_system_linopy):
186186
)
187187

188188
# Check on_off effects
189-
assert 'Converter->Costs(operation)' in model.constraints
189+
assert 'Converter->costs(operation)' in model.constraints
190190
assert_conequal(
191-
model.constraints['Converter->Costs(operation)'],
192-
model.variables['Converter->Costs(operation)']
191+
model.constraints['Converter->costs(operation)'],
192+
model.variables['Converter->costs(operation)']
193193
== model.variables['Converter|on'] * model.hours_per_step * 5,
194194
)
195195

@@ -398,7 +398,7 @@ def test_piecewise_conversion_with_onoff(self, basic_flow_system_linopy):
398398

399399
# Create OnOffParameters
400400
on_off_params = fx.OnOffParameters(
401-
on_hours_total_min=10, on_hours_total_max=40, effects_per_running_hour={'Costs': 5}
401+
on_hours_total_min=10, on_hours_total_max=40, effects_per_running_hour={'costs': 5}
402402
)
403403

404404
# Create a linear converter with piecewise conversion and on/off parameters
@@ -489,10 +489,10 @@ def test_piecewise_conversion_with_onoff(self, basic_flow_system_linopy):
489489
)
490490

491491
# Verify that the costs effect is applied
492-
assert 'Converter->Costs(operation)' in model.constraints
492+
assert 'Converter->costs(operation)' in model.constraints
493493
assert_conequal(
494-
model.constraints['Converter->Costs(operation)'],
495-
model.variables['Converter->Costs(operation)']
494+
model.constraints['Converter->costs(operation)'],
495+
model.variables['Converter->costs(operation)']
496496
== model.variables['Converter|on'] * model.hours_per_step * 5,
497497
)
498498

tests/test_scenarios.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def test_system():
6767
size=InvestParameters(
6868
minimum_size=0,
6969
maximum_size=20,
70-
specific_effects={'Costs': 100}, # €/kW
70+
specific_effects={'costs': 100}, # €/kW
7171
),
72-
effects_per_flow_hour={'Costs': 20}, # €/MWh
72+
effects_per_flow_hour={'costs': 20}, # €/MWh
7373
)
7474
generator = Source('Generator', source=power_gen)
7575

@@ -83,15 +83,15 @@ def test_system():
8383
capacity_in_flow_hours=InvestParameters(
8484
minimum_size=0,
8585
maximum_size=50,
86-
specific_effects={'Costs': 50}, # €/kWh
86+
specific_effects={'costs': 50}, # €/kWh
8787
),
8888
eta_charge=0.95,
8989
eta_discharge=0.95,
9090
initial_charge_state='lastValueOfSim',
9191
)
9292

9393
# Create effects and objective
94-
cost_effect = Effect(label='Costs', unit='€', description='Total costs', is_standard=True, is_objective=True)
94+
cost_effect = Effect(label='costs', unit='€', description='Total costs', is_standard=True, is_objective=True)
9595

9696
# Add all elements to the flow system
9797
flow_system.add_elements(electricity_bus, generator, demand_sink, storage, cost_effect)

0 commit comments

Comments
 (0)