Skip to content

Commit 3123bf9

Browse files
committed
Cleanup for Bugs
Signed-off-by: Davey Elder <iandavidelder@gmail.com>
1 parent b311769 commit 3123bf9

6 files changed

Lines changed: 34 additions & 33 deletions

File tree

scripts/generate_etl_figure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
from pathlib import Path
11+
from typing import Any
1112

1213
import matplotlib
1314
import matplotlib.patches as mpatches
@@ -109,7 +110,12 @@
109110
ax.set_yticklabels(y_labels, fontsize=8.5, color=PALETTE['tick'])
110111

111112
# ——— Dashed reference lines to axes from segment endpoints ———————————————————
112-
dash_kw = {'color': PALETTE['inactive'], 'linewidth': 0.8, 'linestyle': ':', 'zorder': 1}
113+
dash_kw: dict[str, Any] = {
114+
'color': PALETTE['inactive'],
115+
'linewidth': 0.8,
116+
'linestyle': ':',
117+
'zorder': 1,
118+
}
113119
for ql, qu, cl, cu in segments:
114120
ax.plot([ql, ql], [0, cl], **dash_kw)
115121
ax.plot([qu, qu], [0, cu], **dash_kw)

temoa/_internal/run_actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ def solve_instance(
247247
# it also doesn't seem to support duals properly so disable those
248248
if solver_name == 'appsi_highs':
249249
dual_suffix = instance.component('dual')
250-
dual_suffix._direction = Suffix.LOCAL
250+
if dual_suffix is not None:
251+
dual_suffix.direction = Suffix.LOCAL
251252
result = optimizer.solve(instance)
252253
else:
253254
result = optimizer.solve(instance, suffixes=solver_suffixes_list)

temoa/extensions/economies_of_scale/core/data_puller.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,90 +98,84 @@ def poll_costs(
9898
else:
9999
# The period `p` for an investment cost is its vintage `v`.
100100
key = (cast('Region', r), cast('Period', p), cast('Technology', t), cast('Vintage', p))
101-
if CostType.INVEST in entries.get(key, {}):
102-
entries[key][CostType.D_INVEST] += discounted_cost
103-
entries[key][CostType.INVEST] += undiscounted_cost
104-
else:
105-
entries[key].update(
106-
{CostType.D_INVEST: discounted_cost, CostType.INVEST: undiscounted_cost}
107-
)
101+
entry = entries[key]
102+
entry[CostType.D_INVEST] = entry.get(CostType.D_INVEST, 0.0) + discounted_cost
103+
entry[CostType.INVEST] = entry.get(CostType.INVEST, 0.0) + undiscounted_cost
108104

109105
for r, p, t in model.cost_fixed_eos_period_rpt:
110106
fixed_cost = value(cost_fixed_eos.period_cost(model, r, p, t))
111107
if fixed_cost < epsilon:
112108
continue
113109

114-
undiscounted_fixed_cost = fixed_cost * value(model.period_length[p])
115-
discounted_fixed_cost = costs.fixed_or_variable_cost(
110+
ud_fixed = float(fixed_cost * value(model.period_length[p]))
111+
d_fixed = costs.fixed_or_variable_cost(
116112
1,
117113
fixed_cost,
118114
value(model.period_length[p]),
119115
global_discount_rate=global_discount_rate,
120116
p_0=p_0,
121117
p=p,
122118
)
119+
d_fixed = float(value(d_fixed))
123120

124121
if '-' in r:
125122
exchange_costs.add_cost_record(
126123
r,
127124
period=p,
128125
tech=t,
129126
vintage=p,
130-
cost=float(value(discounted_fixed_cost)),
127+
cost=d_fixed,
131128
cost_type=CostType.D_FIXED,
132129
)
133130
exchange_costs.add_cost_record(
134131
r,
135132
period=p,
136133
tech=t,
137134
vintage=p,
138-
cost=float(undiscounted_fixed_cost),
135+
cost=ud_fixed,
139136
cost_type=CostType.FIXED,
140137
)
141138
else:
142-
entries[r, p, t, p].update(
143-
{
144-
CostType.D_FIXED: float(value(discounted_fixed_cost)),
145-
CostType.FIXED: float(undiscounted_fixed_cost),
146-
}
147-
)
139+
key = (cast('Region', r), cast('Period', p), cast('Technology', t), cast('Vintage', p))
140+
entry = entries[key]
141+
entry[CostType.D_FIXED] = entry.get(CostType.D_FIXED, 0.0) + d_fixed
142+
entry[CostType.FIXED] = entry.get(CostType.FIXED, 0.0) + ud_fixed
148143

149-
for r, p, t in model.cost_fixed_eos_period_rpt:
144+
for r, p, t in model.cost_variable_eos_period_rpt:
150145
variable_cost = value(cost_variable_eos.period_cost(model, r, p, t))
151146
if variable_cost < epsilon:
152147
continue
153148

154-
undiscounted_variable_cost = variable_cost * value(model.period_length[p])
155-
discounted_variable_cost = costs.fixed_or_variable_cost(
149+
ud_variable = float(variable_cost * value(model.period_length[p]))
150+
d_variable = costs.fixed_or_variable_cost(
156151
1,
157152
variable_cost,
158153
value(model.period_length[p]),
159154
global_discount_rate=global_discount_rate,
160155
p_0=p_0,
161156
p=p,
162157
)
158+
d_variable = float(value(d_variable))
163159

164160
if '-' in r:
165161
exchange_costs.add_cost_record(
166162
r,
167163
period=p,
168164
tech=t,
169165
vintage=p,
170-
cost=float(value(discounted_variable_cost)),
166+
cost=d_variable,
171167
cost_type=CostType.D_VARIABLE,
172168
)
173169
exchange_costs.add_cost_record(
174170
r,
175171
period=p,
176172
tech=t,
177173
vintage=p,
178-
cost=float(undiscounted_variable_cost),
174+
cost=ud_variable,
179175
cost_type=CostType.VARIABLE,
180176
)
181177
else:
182-
entries[r, p, t, p].update(
183-
{
184-
CostType.D_VARIABLE: float(value(discounted_variable_cost)),
185-
CostType.VARIABLE: float(undiscounted_variable_cost),
186-
}
187-
)
178+
key = (cast('Region', r), cast('Period', p), cast('Technology', t), cast('Vintage', p))
179+
entry = entries[key]
180+
entry[CostType.D_VARIABLE] = entry.get(CostType.D_VARIABLE, 0.0) + d_variable
181+
entry[CostType.VARIABLE] = entry.get(CostType.VARIABLE, 0.0) + ud_variable

temoa/extensions/economies_of_scale/core/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def register_model_components(model: TemoaModel) -> None:
169169
rule=cost_fixed_eos.cost_fixed_eos_capacity_upper_bound_constraint,
170170
)
171171

172+
m.append_cost_fixed_eos_to_total_cost = BuildAction(rule=cost_fixed_eos.total_cost)
173+
172174
# -- cost_variable_eos ---
173175
m.cost_variable_eos_segments = {}
174176

temoa/extensions/method_of_morris/morris.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def evaluate(
4747
with TableWriter(config) as table_writer:
4848
table_writer.write_results(model=mdl)
4949

50-
import contextlib
51-
5250
with contextlib.closing(sqlite3.connect(db_file)) as con:
5351
cur = con.cursor()
5452
cur.execute('SELECT * FROM output_objective')

tests/test_table_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LoanCostInput(TypedDict):
99
capacity: float
1010
invest_cost: float
1111
loan_life: float
12-
loan_rate: float
12+
loan_annualize: float
1313
global_discount_rate: float
1414
process_life: int
1515
p_0: int

0 commit comments

Comments
 (0)