-
Notifications
You must be signed in to change notification settings - Fork 61
Add output threshold and myopic capacity config #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c67a2c0
3e2b3cd
7a77877
fdc8ab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,7 +64,15 @@ class MyopicSequencer: | |||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def __init__(self, config: TemoaConfig | None): | ||||||||||||||||||||||||||||||||||||||||
| self.capacity_epsilon = 1e-5 | ||||||||||||||||||||||||||||||||||||||||
| # Minimum capacity (MW) to carry forward between myopic periods. | ||||||||||||||||||||||||||||||||||||||||
| # Configurable via [myopic] capacity_threshold in TOML. | ||||||||||||||||||||||||||||||||||||||||
| default_cap_threshold = 1e-3 | ||||||||||||||||||||||||||||||||||||||||
| if config and config.myopic_inputs: | ||||||||||||||||||||||||||||||||||||||||
| self.capacity_epsilon = config.myopic_inputs.get( | ||||||||||||||||||||||||||||||||||||||||
| 'capacity_threshold', default_cap_threshold | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| self.capacity_epsilon = default_cap_threshold | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Missing validation for
Consider adding validation consistent with ♻️ Proposed fix to add validation+import math
+
+def _validate_capacity_threshold(value: float, default: float) -> float:
+ """Validate capacity threshold, returning default if invalid."""
+ if not isinstance(value, (int, float)):
+ return default
+ if not math.isfinite(value) or value < 0:
+ return default
+ return float(value)
+
class MyopicSequencer:
...
def __init__(self, config: TemoaConfig | None):
# Minimum capacity (MW) to carry forward between myopic periods.
# Configurable via [myopic] capacity_threshold in TOML.
default_cap_threshold = 1e-3
if config and config.myopic_inputs:
- self.capacity_epsilon = config.myopic_inputs.get(
+ raw_threshold = config.myopic_inputs.get(
'capacity_threshold', default_cap_threshold
)
+ self.capacity_epsilon = _validate_capacity_threshold(raw_threshold, default_cap_threshold)
else:
self.capacity_epsilon = default_cap_threshold📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| self.debugging = False | ||||||||||||||||||||||||||||||||||||||||
| self.optimization_periods: list[int] | None = None | ||||||||||||||||||||||||||||||||||||||||
| self.instance_queue: deque[MyopicIndex] = deque() # a LIFO queue | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -387,7 +395,7 @@ def update_myopic_efficiency_table(self, myopic_index: MyopicIndex, prev_base: i | |||||||||||||||||||||||||||||||||||||||
| 'DELETE FROM myopic_efficiency ' | ||||||||||||||||||||||||||||||||||||||||
| 'WHERE (SELECT region, tech, vintage) ' | ||||||||||||||||||||||||||||||||||||||||
| ' NOT IN (SELECT region, tech, vintage FROM output_net_capacity ' | ||||||||||||||||||||||||||||||||||||||||
| ' WHERE period = ? AND scenario = ?) ' | ||||||||||||||||||||||||||||||||||||||||
| ' WHERE period = ? AND scenario = ? AND ABS(capacity) >= ?) ' | ||||||||||||||||||||||||||||||||||||||||
| 'AND tech not in (SELECT tech FROM main.technology where unlim_cap > 0)' | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -396,16 +404,20 @@ def update_myopic_efficiency_table(self, myopic_index: MyopicIndex, prev_base: i | |||||||||||||||||||||||||||||||||||||||
| 'SELECT * FROM myopic_efficiency ' | ||||||||||||||||||||||||||||||||||||||||
| 'WHERE (SELECT region, tech, vintage) ' | ||||||||||||||||||||||||||||||||||||||||
| ' NOT IN (SELECT region, tech, vintage FROM output_net_capacity ' | ||||||||||||||||||||||||||||||||||||||||
| ' WHERE period = ? AND scenario = ?) ' | ||||||||||||||||||||||||||||||||||||||||
| ' WHERE period = ? AND scenario = ? AND ABS(capacity) >= ?) ' | ||||||||||||||||||||||||||||||||||||||||
| 'AND tech not in (SELECT tech FROM Technology where unlim_cap > 0)' | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| print('\n\n **** Removing these unused region-tech-vintage combos ****') | ||||||||||||||||||||||||||||||||||||||||
| removals = self.cursor.execute( | ||||||||||||||||||||||||||||||||||||||||
| debug_query, (last_interval_end, self.config.scenario) | ||||||||||||||||||||||||||||||||||||||||
| debug_query, | ||||||||||||||||||||||||||||||||||||||||
| (last_interval_end, self.config.scenario, self.capacity_epsilon), | ||||||||||||||||||||||||||||||||||||||||
| ).fetchall() | ||||||||||||||||||||||||||||||||||||||||
| for i, removal in enumerate(removals): | ||||||||||||||||||||||||||||||||||||||||
| print(f'{i}. Removing: {removal}') | ||||||||||||||||||||||||||||||||||||||||
| self.cursor.execute(delete_qry, (last_interval_end, self.config.scenario)) | ||||||||||||||||||||||||||||||||||||||||
| self.cursor.execute( | ||||||||||||||||||||||||||||||||||||||||
| delete_qry, | ||||||||||||||||||||||||||||||||||||||||
| (last_interval_end, self.config.scenario, self.capacity_epsilon), | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| self.output_con.commit() | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 2. Add the new stuff now visible | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.