Repository navigation
Conversation
Add grid2op/Environment/protection: a frozen Protection dataclass, a structure-of-arrays ProtectionConfig (only in_service is mutable), a per-protection ProtectionState and a vectorized solver used by the cascading failure loop of Backend.next_grid_state. - protections on the "or" and/or "ex" side, any number per line, each with its own threshold (x thermal limit), delay and in_service status - default config built from HARD/SOFT_OVERFLOW_THRESHOLD and NB_TIMESTEP_OVERFLOW_ALLOWED, rebuilt when parameters change: same behaviour as before - env.set_protections / add_protection / set_protection_in_service / get_protections, protections.json in the env folder - carried to env.copy, obs.simulate, obs.get_forecast_env, the runner and multiprocessing (pickle keeps the read only flags) - obs.protection_counters / protection_line_id / protection_side; timestep_protection_engaged is the per-line max of the counters - Backend.get_line_flow_ex and get_line_flows_both_sides - MaskedEnvironment and EpisodeReboot migrated; old private attributes _protection_counter, _hard_overflow_threshold and _nb_ts_max_protection_counter removed Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
- the observation returned by env.reset is the initial state of the grid: no protection trips on it (previously the hard overflow could), whatever its delay, and counters start at 0 - rename default_from_parameters to legacy_from_parameters and document the mapping convention of the legacy parameters - add env.init_protection_legacy(parameters=None) - explicit tests for both Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
…tection - a protection has a limit in A (instead of a multiplier of the thermal limit); it is engaged when the current on its side is above PROTECTION_THRESHOLD * limit - new parameter PROTECTION_THRESHOLD; SOFT_OVERFLOW_THRESHOLD becomes a deprecated alias of it (still read from json files) - protections on the same side of a powerline must be consistent: no equal limits, no equal delays, a higher limit needs a strictly lower delay (checked when the configuration is built) - the protection with the lowest limit of each side is its reference protection (ProtectionConfig.reference_limits / is_reference); env.get_thermal_limit returns the reference limits - legacy mapping (legacy_from_parameters) now takes the thermal limits: reference protection at th with delay NB_TIMESTEP_OVERFLOW_ALLOWED, instantaneous one at HARD / PROTECTION_THRESHOLD * th (omitted when NB_TIMESTEP_OVERFLOW_ALLOWED is 0), rebuilt when the thermal limits or the parameters change - MaskedEnvironment adapted, tests rewritten for absolute limits Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
- rho_or / rho_ex: current divided by the limit of the reference protection of each side (0 on a side without protection); rho is the maximum of both, a_or / thermal_limit with the legacy protections - timestep_overflow counts the consecutive steps with rho > 1 (any side) - timestep_protection_engaged_or / _ex (per side maximum counter), timestep_protection_engaged is the maximum of both sides - time_before_protection_trip (_or / _ex): steps before a protection disconnects the powerline if the currents stay above the limits of the protections currently engaged (-1 if none), unambiguous with several delayed stages on the same side; protection_steps_before_trip per protection - the per line attributes are copied with the observation but are not part of its vector representation Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
- the environment no longer calls Backend.update_thermal_limit (DLR); Backend.update_thermal_limit_from_vect does nothing - Backend.set_thermal_limit does nothing (with a DeprecationWarning) once the backend has exposed its thermal limits; grid2op no longer calls it (env, obs env, observation space, simulator, BackendConverter) - CloseToOverflowReward reads the limits from the environment - deprecation notes: env.set_thermal_limit / get_thermal_limit, the "thermal limit" reset option, obs.thermal_limit, Runner thermal_limit_a, Backend.get_thermal_limit / get_relative_flow / get_line_overflow, simulator update_thermal_limit; MaskedEnvironment points to set_protection_in_service - backend conformance tests updated: the cascade tests set the limits on the environment, set_thermal_limit is checked to be a no-op Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
- docs/user/environment.rst: absolute limits, consistency rules, reference protection, legacy mapping, new observation attributes, no protection at reset, DLR removed from the backend - CHANGELOG: added / updated / breaking / deprecation entries, and TODO items for backend-exposed protections and DLR as a protection Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
- test_resest_options: a line above the hard limit is not disconnected by env.reset anymore (no protection acts on the initial state), it is at the first step - test_diff_backend: the simulator keeps the limits in its observation, not in its backend (Backend.set_thermal_limit is a no-op): check the observation limits and the rho of the predictions instead Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Benjamin Donnot <benjamin.donnot@rte-france.com>
Conflicts resolved: - baseEnv.py: keep the protection imports next to the new dispatch imports (the redispatch error message now lives in Environment/dispatch) - docs/user/environment.rst: keep both new sections (redispatch solver from dev_1.12.7, overcurrent protections from this branch) - CHANGELOG.rst: 1.12.6 is released, the protection entries move to the 1.12.7 section The version markers added by this branch (versionadded / deprecated / "since grid2op ...") are retargeted from 1.12.6 to 1.12.7. Assisted-by: Claude Code (Claude Opus 5.5) Claude-Session: https://claude.ai/code/session_01Rq4DmgaczxciTCF6xsR4GA Signed-off-by: Claude <noreply@anthropic.com>
Not up to standards ⛔🟢 Coverage
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ +0.26% coverage variation (-1.00%) |
| Diff coverage | ✅ 96.09% diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (ad26e9b) 25969 21318 82.09% Head commit (8130337) 26535 (+566) 21851 (+533) 82.35% (+0.26%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#797) 640 615 96.09% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This branch has not been deployed
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.
What
Overcurrent protections become a first-class, configurable part of the environment (
grid2op.Environment.protection), replacing the hard-coded "hard / soft overflow" logic ofBackend.next_grid_state.Protectionis placed on one side ("or"/"ex") of one powerline, with alimitin A, adelayin steps (0 = instantaneous) and anin_servicestatus. They are stored as a structure of arrays (ProtectionConfig, read-only exceptin_service) with one counter per protection (ProtectionState); the trip logic is vectorized (protection_solver.py).PROTECTION_THRESHOLD * limit(new parameter,SOFT_OVERFLOW_THRESHOLDbecomes a deprecated alias of it). It trips when it has been engaged for strictly more thandelayconsecutive steps.rho:rho_or/rho_ex= current / limit of the reference protection of the side (0 without protection),rho = max(rho_or, rho_ex);timestep_overflowcounts the steps withrho > 1.time_before_protection_trip(and_or/_ex, plusprotection_steps_before_tripper protection) gives the number of steps before a protection disconnects the line if the currents stay the same. It is unambiguous when several delayed stages are on the same side, unliketimestep_protection_engaged(kept for compatibility: maximum counter, also per side).env.resetis the initial state of the grid, no protection acts on it whatever its delay (previously the hard overflow could disconnect lines there).env.set_protections(...),env.add_protection(...),env.set_protection_in_service(...), aprotections.jsonfile in the environment directory, carried toenv.copy,obs.simulate,obs.get_forecast_env, the runner and multiprocessing.Backward compatibility
When no protections are given, the "legacy" ones are built from the thermal limits and the parameters (
legacy_from_parameters,env.init_protection_legacy()): per line, on the "or" side, a reference protection atthwith delayNB_TIMESTEP_OVERFLOW_ALLOWEDand an instantaneous one atHARD_OVERFLOW_THRESHOLD / PROTECTION_THRESHOLD * th(omitted whenNB_TIMESTEP_OVERFLOW_ALLOWEDis 0). They followset_thermal_limitand parameter changes.This was checked against the code before this PR on stressed scenarios over every combination of
NB_TIMESTEP_OVERFLOW_ALLOWEDin {0..3},SOFT_OVERFLOW_THRESHOLDin {0.95, 1.0, 1.1},HARD_OVERFLOW_THRESHOLDin {1.3, 2.0} andNO_OVERFLOW_DISCONNECTIONon/off (line status,disc_lines,rho,timestep_overflow,timestep_protection_engaged,simulate): identical on every real step. The only differences come from the hard overflow no longer acting duringenv.reset.Breaking changes / deprecations
env.reset(see above);test_resest_options.test_hard_overflowis updated accordingly.Backend.update_thermal_limitis no longer called,update_thermal_limit_from_vectdoes nothing. DLR belongs to the protections (out of scope here).Backend.set_thermal_limitdoes nothing (with aDeprecationWarning) once the backend has exposed its thermal limits; it still works whilethermal_limit_ais unset so a backend can use it inload_grid._protection_counter,_hard_overflow_threshold,_nb_ts_max_protection_counterare replaced by_protection_config/_protection_state(the backend conformance tests inBaseBackendTest.pyare updated).SOFT_OVERFLOW_THRESHOLD,HARD_OVERFLOW_THRESHOLD,NB_TIMESTEP_OVERFLOW_ALLOWED, the thermal limits (env.set_thermal_limit, the"thermal limit"reset option,thermal_limit_a,config.pythermal_limits),Backend.get_thermal_limit/get_relative_flow/get_line_overflow.Not in this PR (TODO in the CHANGELOG)
protections.json(as it exposes the thermal limits today): to be tracked in an issue referencing this PR.Tests
grid2op/tests/test_protections.py(config, consistency rules, reference, solver, legacy mapping, ex side, multi-stage,in_service,NO_OVERFLOW_DISCONNECTION, copy, simulate / forecast env, runner,protections.json, no protection at reset, observation attributes including the 3-stage delays 4/1/0 case).test_genericlist and the CI module groups pass on the branch before the merge ofdev_1.12.7; after the merge, the protection, overflow, reset, simulator and new dispatch tests pass (164 tests).Generated by Claude Code