Feat: Exclude pre-existing overloads in N-1 analysis unless worsened - #21
Merged
Merged
Conversation
…g file specified Root cause: The expert_op4grid_recommender library (pre-commit 0b14be7) had a bug where IGNORE_LINES_MONITORING=True left lines_we_care_about as an empty list [] instead of all lines, causing zero overloads to be detected and no results returned. ExpertAssist changes: - Simplify fallback when no monitoring file provided: always set IGNORE_LINES_MONITORING=True (matching UI placeholder behavior) - Clear config.LINES_MONITORING_FILE=None when switching to monitor-all mode to prevent stale state from prior configurations - Import load_interesting_lines from data_loader instead of environment to avoid unnecessary grid2op dependency chain Requires: expert_op4grid_recommender >= 0b14be7 (main branch) https://claude.ai/code/session_01VXHyCpr7Nz1p4hz6DEkiDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the implementation plan, this PR introduces a filtering mechanism for N-1 overloads. Lines that are already overloaded in the base N-state are excluded from the N-1 overloaded lines list, unless their maximum current has increased by a specified threshold (default 2%). Configured for both React and Standalone UIs.
Implementation Plan
Pre-Existing Overloads: Exclude from N-1 Display, Analysis & max_rho
Pre-existing overloads (lines already overloaded in N state) should be excluded from N-1 overloads display, contingency analysis, and action
max_rho— unless worsened by a configurable threshold (default 2% of initial current).Proposed Changes
Expert_op4grid_recommender — Config
[MODIFY] config.py
Add
PRE_EXISTING_OVERLOAD_WORSENING_THRESHOLD = 0.02alongside other config parameters.Expert_op4grid_recommender — Analysis Engine
[MODIFY] main.py
Overload filtering (lines 375-389): Already done ✅ — Pre-existing overloads filtered from
lines_overloaded_ids.Store pre-existing rho (~line 384): Also store a dict
{line_idx: rho_N}for pre-existing overloads, needed for the worsening check.Reassessment max_rho (lines 579-593): When computing
max_rhofor each action, exclude lines whereobs.rho[i] >= 1(pre-existing) unless the action's rho exceedsobs.rho[i] * (1 + threshold).Return value (line 614-618): Include
pre_existing_overloadsinfo in the result dict (list of{name, rho_N}).ExpertAssist Backend
[MODIFY] main.py
Add
pre_existing_overload_threshold: float = 0.02toConfigRequest.[MODIFY] recommender_service.py
update_config: Setconfig.PRE_EXISTING_OVERLOAD_WORSENING_THRESHOLDfrom settings._get_overloaded_lines: Add optional paramsn_state_currentsandworsening_thresholdto filter pre-existing overloads.get_network_diagram: Also store N-state element currents inself._n_state_currentsfor comparison.get_n1_diagram: Call_get_overloaded_lineswith N-state currents to exclude pre-existing overloads unless worsened.ExpertAssist Frontend
[MODIFY] App.tsx
Add
preExistingOverloadThresholdstate, backup/restore in settings, pass to config updates.[MODIFY] standalone_interface.html
Mirror the same threshold setting in the standalone interface.
Verification Plan
Manual Verification
bare_env_small_grid_test, select contingencyP.SAOL31RONCIlignes_a_monitorerspecified:BUGEYY712,BUGEYY714,N.SE5Y711,N.SE5Y712BEON L31CPVAN(pre-existing excluded)max_rhoNOT referencingN.SE5Y7110(0%) → pre-existing overloads should re-appear in N-1 if their current changed at all