temoa
temoa copied to clipboard
Bug: Type mismatch in unit_cost_explorer.py causes KeyError at runtime
Description
A type mismatch bug was identified in temoa/utilities/unit_cost_explorer.py at line 128 that will cause a KeyError at runtime.
Problem
The call to StorageEnergyUpperBound_Constraint passes '1' (string) for the time-of-day parameter, but the model initializes M.time_of_day with integers (line 103: range(1, tod_slices + 1)). This type mismatch will cause a KeyError when the constraint attempts to index M.V_StorageLevel[r, p, s, d, t, v] at line 258 of temoa/components/storage.py.
Location
Primary Issue:
- File:
temoa/utilities/unit_cost_explorer.py - Line: 128
- Current:
StorageEnergyUpperBound_Constraint(M, 'A', 2020, 'winter', '1', 'battery', 2020) - Should be:
StorageEnergyUpperBound_Constraint(M, 'A', 2020, 'winter', 1, 'battery', 2020)
Secondary Issue:
- File:
temoa/components/storage.py - Line: 207
- The type hint for parameter
dshould be changed fromstrtointto reflect actual usage
Impact
- Runtime KeyError when executing the unit cost explorer script
- Type hints don't reflect actual expected types, causing confusion and type-checking issues
References
- PR #165: https://github.com/TemoaProject/temoa/pull/165
- Comment: https://github.com/TemoaProject/temoa/pull/165#discussion_r2438054845
- Requested by: @ParticularlyPythonicBS