Skip to content

Feat: Exclude pre-existing overloads in N-1 analysis unless worsened - #21

Merged
marota merged 2 commits into
mainfrom
claude/fix-contingency-selection-fWHxb
Feb 28, 2026
Merged

marota merged 2 commits into
mainfrom
claude/fix-contingency-selection-fWHxb

Conversation

@marota

@marota marota commented Feb 28, 2026 •

Copy link
Copy Markdown
Collaborator

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.02 alongside 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_rho for each action, exclude lines where obs.rho[i] >= 1 (pre-existing) unless the action's rho exceeds obs.rho[i] * (1 + threshold).

Return value (line 614-618): Include pre_existing_overloads info in the result dict (list of {name, rho_N}).


ExpertAssist Backend

[MODIFY] main.py

Add pre_existing_overload_threshold: float = 0.02 to ConfigRequest.

[MODIFY] recommender_service.py

  1. update_config: Set config.PRE_EXISTING_OVERLOAD_WORSENING_THRESHOLD from settings.
  2. _get_overloaded_lines: Add optional params n_state_currents and worsening_threshold to filter pre-existing overloads.
  3. get_network_diagram: Also store N-state element currents in self._n_state_currents for comparison.
  4. get_n1_diagram: Call _get_overloaded_lines with N-state currents to exclude pre-existing overloads unless worsened.

ExpertAssist Frontend

[MODIFY] App.tsx

Add preExistingOverloadThreshold state, 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

  1. Start ExpertAssist backend, load bare_env_small_grid_test, select contingency P.SAOL31RONCI
  2. With no lignes_a_monitorer specified:
    • N Overloads should show BUGEYY712, BUGEYY714, N.SE5Y711, N.SE5Y712
    • N-1 Overloads should ONLY show BEON L31CPVAN (pre-existing excluded)
    • Run Analysis should produce action cards with max_rho NOT referencing N.SE5Y711
  3. Adjust the threshold in settings to 0 (0%) → pre-existing overloads should re-appear in N-1 if their current changed at all

claude and others added 2 commits February 28, 2026 11:08
…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
@marota
marota merged commit c6e55e2 into main Feb 28, 2026
@marota marota mentioned this pull request Feb 28, 2026
26 of 27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants