Skip to content

Commit 9047c39

Browse files
committed
Miscellaneous rabbit-induced cleanup
Signed-off-by: Davey Elder <iandavidelder@gmail.com>
1 parent b6bca6f commit 9047c39

9 files changed

Lines changed: 33 additions & 32 deletions

File tree

docs/source/extensions/unit_commitment.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ parameters. Exactly one row per :math:`(r, t)` pair is required.
105105
":code:`unit_capacity`", ":math:`UC_{r,t}`", "—", "nameplate capacity per discrete unit (same units as :code:`v_capacity`); **required**"
106106
":code:`min_output_fraction`", ":math:`\underline{f}_{r,t}`", "0", "minimum output as a fraction of available nameplate output per online unit; :math:`[0, 1]`"
107107
":code:`max_output_fraction`", ":math:`\overline{f}_{r,t}`", "1", "maximum output as a fraction of available nameplate output per online unit; :math:`(0, 1]`"
108-
":code:`min_up_time_hours`", ":math:`T^{up}_{r,t}`", "0", "minimum number of consecutive hours a unit must remain online after starting; must be less than one full day"
109-
":code:`min_down_time_hours`", ":math:`T^{dn}_{r,t}`", "0", "minimum number of consecutive hours a unit must remain offline after stopping; must be less than one full day"
108+
":code:`min_up_time_hours`", ":math:`T^{up}_{r,t}`", "0", "minimum number of consecutive hours a unit must remain online after starting"
109+
":code:`min_down_time_hours`", ":math:`T^{dn}_{r,t}`", "0", "minimum number of consecutive hours a unit must remain offline after stopping"
110110
":code:`linearized`", "—", "0", "if 1, UC variables are kept continuous (LP relaxation); if 0, they are promoted to non-negative integers (MIP)"
111111

112112
unit_commitment_startup_cost

temoa/components/limits.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,9 @@ def limit_emission_constraint(
798798
if 'unit_commitment' in model.enabled_extensions:
799799
from temoa.extensions.unit_commitment.components import startup
800800

801-
process_emissions += startup.uc_startup_emissions_rpe(model, regions, p, e)
801+
process_emissions += quicksum(
802+
startup.uc_startup_emissions_rpe(model, r, p, e) for r in regions
803+
)
802804

803805
embodied_emissions = quicksum(
804806
model.v_new_capacity[reg, t, v]

temoa/data_io/hybrid_loader.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _load_tech_group_members(
564564
filtered_data: Sequence[tuple[object, ...]],
565565
) -> None:
566566
"""Loads members into the indexed set `tech_group_members`."""
567-
model = TemoaModel()
567+
model = self.model
568568
validator = self.viable_techs.members if self.viable_techs else None
569569
for group_name, tech in filtered_data:
570570
if validator is None or tech in validator:
@@ -582,7 +582,7 @@ def _load_time_season(
582582
"""
583583
Loads time_season as a flat ordered set of season names.
584584
"""
585-
model = TemoaModel()
585+
model = self.model
586586
if not filtered_data:
587587
logger.warning('No time_season table found. Loading a single filler season "S".')
588588
seasons_to_load: list[tuple[object, ...]] = [('S',)]
@@ -599,7 +599,7 @@ def _load_time_season_sequential(
599599
"""
600600
Composite loader for time_season_sequential and its associated index sets.
601601
"""
602-
model = TemoaModel()
602+
model = self.model
603603
if filtered_data:
604604
seg_frac_data = [
605605
(row[0], row[2]) for row in filtered_data
@@ -623,7 +623,7 @@ def _load_existing_capacity(
623623
Handles different queries for myopic vs. standard runs and also
624624
populates the `tech_exist` set.
625625
"""
626-
model = TemoaModel()
626+
model = self.model
627627
cur = self.con.cursor()
628628
mi = self.myopic_index
629629

@@ -672,7 +672,7 @@ def _load_retired_existing_capacity(
672672
)
673673
return
674674

675-
model = TemoaModel()
675+
model = self.model
676676
cur = self.con.cursor()
677677
mi = self.myopic_index
678678

@@ -701,7 +701,7 @@ def _load_lifetime_tech(
701701
filtered_data: Sequence[tuple[object, ...]],
702702
) -> None:
703703
"""Loads the lifetime_tech component."""
704-
model = TemoaModel()
704+
model = self.model
705705
cur = self.con.cursor()
706706
rows_to_load = cur.execute('SELECT region, tech, lifetime FROM lifetime_tech').fetchall()
707707
rt_getter = itemgetter(0, 1)
@@ -717,7 +717,7 @@ def _load_lifetime_process(
717717
filtered_data: Sequence[tuple[object, ...]],
718718
) -> None:
719719
"""Loads the lifetime_process component."""
720-
model = TemoaModel()
720+
model = self.model
721721
cur = self.con.cursor()
722722
mi = self.myopic_index
723723

@@ -743,7 +743,7 @@ def _load_lifetime_survival_curve(
743743
filtered_data: Sequence[tuple[object, ...]],
744744
) -> None:
745745
"""Loads the lifetime_survival_curve component."""
746-
model = TemoaModel()
746+
model = self.model
747747
cur = self.con.cursor()
748748
mi = self.myopic_index
749749

@@ -771,7 +771,7 @@ def _load_global_discount_rate(
771771
filtered_data: Sequence[tuple[object, ...]],
772772
) -> None:
773773
"""Loads the required singleton global_discount_rate."""
774-
model = TemoaModel()
774+
model = self.model
775775
if filtered_data:
776776
data[model.global_discount_rate.name] = {None: cast('float', filtered_data[0][0])}
777777
else:
@@ -787,7 +787,7 @@ def _load_default_loan_rate(
787787
filtered_data: Sequence[tuple[object, ...]],
788788
) -> None:
789789
"""Loads the optional singleton default_loan_rate."""
790-
model = TemoaModel()
790+
model = self.model
791791
if filtered_data:
792792
data[model.default_loan_rate.name] = {None: cast('float', filtered_data[0][0])}
793793

@@ -799,7 +799,7 @@ def _load_efficiency(
799799
filtered_data: Sequence[tuple[object, ...]],
800800
) -> None:
801801
"""Loads the main efficiency parameter, which is pre-calculated."""
802-
model = TemoaModel()
802+
model = self.model
803803
self._load_component_data(data, model.efficiency, self.efficiency_values)
804804

805805
def _load_linked_techs(
@@ -832,7 +832,7 @@ def _load_ramping_down(
832832
filtered_data: Sequence[tuple[object, ...]],
833833
) -> None:
834834
"""Composite loader for ramp_down_hourly and its index set `tech_downramping`."""
835-
model = TemoaModel()
835+
model = self.model
836836
self._load_component_data(data, model.ramp_down_hourly, filtered_data)
837837
if filtered_data:
838838
tech_data = sorted({(row[1],) for row in filtered_data})
@@ -848,7 +848,7 @@ def _load_ramping_up(
848848
filtered_data: Sequence[tuple[object, ...]],
849849
) -> None:
850850
"""Composite loader for ramp_up_hourly and its index set `tech_upramping`."""
851-
model = TemoaModel()
851+
model = self.model
852852
self._load_component_data(data, model.ramp_up_hourly, filtered_data)
853853
if filtered_data:
854854
tech_data = sorted({(row[1],) for row in filtered_data})
@@ -864,7 +864,7 @@ def _load_rps_requirement(
864864
filtered_data: Sequence[tuple[object, ...]],
865865
) -> None:
866866
"""Handles deprecation warning for renewable_portfolio_standard."""
867-
model = TemoaModel()
867+
model = self.model
868868
self._load_component_data(data, model.renewable_portfolio_standard, filtered_data)
869869
if filtered_data:
870870
logger.warning(

temoa/extensions/economies_of_scale/core/model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
Var,
1515
)
1616

17-
import temoa.extensions.economies_of_scale.components.cost_fixed_eos as cost_fixed_eos
18-
import temoa.extensions.economies_of_scale.components.cost_invest_eos as cost_invest_eos
19-
import temoa.extensions.economies_of_scale.components.cost_variable_eos as cost_variable_eos
17+
from temoa.extensions.economies_of_scale.components import (
18+
cost_fixed_eos,
19+
cost_invest_eos,
20+
cost_variable_eos,
21+
)
2022

2123
if TYPE_CHECKING:
2224
from temoa.core.model import TemoaModel

temoa/extensions/framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def normalize_extension_ids(extension_ids: Sequence[str | object] | None) -> tup
4343
if not isinstance(ext_id, str):
4444
msg = f'Extension ids must be strings. Received: {type(ext_id).__name__}'
4545
logger.error(msg)
46-
raise ValueError(msg)
46+
raise TypeError(msg)
4747
cleaned = ext_id.strip().lower()
4848
if not cleaned:
4949
continue

temoa/extensions/unit_commitment/components/startup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
from temoa.components.costs import fixed_or_variable_cost
2222

2323
if TYPE_CHECKING:
24-
from collections.abc import Iterable
25-
2624
from pyomo.core.base.objective import ObjectiveData
2725

2826
from temoa.core.model import TemoaModel
@@ -40,9 +38,7 @@
4038
logger = logging.getLogger(__name__)
4139

4240

43-
def uc_startup_emissions_rpe(
44-
model: TemoaModel, r_g: Iterable[Region], p: Period, e: Commodity
45-
) -> Expression:
41+
def uc_startup_emissions_rpe(model: TemoaModel, r: Region, p: Period, e: Commodity) -> Expression:
4642
"""
4743
Startup emissions to add to limit_emission_constraint.
4844
"""
@@ -52,7 +48,7 @@ def uc_startup_emissions_rpe(
5248
* value(model.uc_unit_capacity[_r, t])
5349
* model.v_uc_started[_r, p, s, d, t, v]
5450
for _r, _e, t in model.uc_startup_emissions.sparse_keys()
55-
if _r in r_g and _e == e
51+
if _r == r and _e == e
5652
for v in model.process_vintages.get((_r, p, t), [])
5753
for s in model.time_season
5854
for d in model.time_of_day

temoa/extensions/unit_commitment/core/data_puller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def write_uc_results(
6363
records = []
6464

6565
for uci, (online, started, stopped) in results.items():
66-
# if all(abs(v) < epsilon for v in (online, started, stopped)):
67-
# continue
66+
if all(abs(v) < epsilon for v in (online, started, stopped)):
67+
continue
6868
row = {
6969
'scenario': scenario,
7070
'region': uci.r,

temoa/extensions/unit_commitment/core/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
Var,
1515
)
1616

17-
import temoa.extensions.unit_commitment.components.commitment as commitment
18-
import temoa.extensions.unit_commitment.components.startup as startup
1917
from temoa.components import capacity, operations
18+
from temoa.extensions.unit_commitment.components import commitment, startup
2019

2120
if TYPE_CHECKING:
2221
from temoa.core.model import TemoaModel

tests/test_full_runs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@ def test_time_sequence_tests(
243243
'representative_periods': 1467.912766,
244244
'seasonal_timeslices': 1467.912766,
245245
}
246+
time_sequencing = str(sequencer.config.time_sequencing)
247+
expected_obj = objectives[time_sequencing]
246248

247249
with contextlib.closing(sqlite3.connect(sequencer.config.output_database)) as con:
248250
cur = con.cursor()
249251
res = cur.execute('SELECT SUM(total_system_cost) FROM main.output_objective').fetchone()
250252
obj = res[0]
251-
assert obj == pytest.approx(objectives[sequencer.config.time_sequencing], abs=0.00001), (
253+
assert obj == pytest.approx(expected_obj, abs=0.00001), (
252254
'objective function value did not match expected for time sequencing test'
253255
)
254256

0 commit comments

Comments
 (0)