@@ -550,8 +550,8 @@ def __init__(
550550 self .debug_dispatch = False
551551
552552 # Thermal limit and protection
553- self .ts_manager : thermalLimits . ThermalLimits = None
554- self .protection = protectionScheme .NoProtection = None
553+ self ._init_thermal_limit ()
554+ self .protection : protectionScheme .DefaultProtection = None
555555
556556 # to change the parameters
557557 self .__new_param = None
@@ -637,18 +637,8 @@ def __init__(
637637 self ._reward_to_obs = {}
638638
639639 def _init_thermal_limit (self ):
640-
641- if self ._thermal_limit_a is None :
642- if hasattr (self .ts_manager , '_thermal_limit_a' ) and isinstance (self .ts_manager .limits , np .ndarray ):
643- _thermal_limits = self .ts_manager .limits .astype (dt_float )
644- else :
645- raise ValueError ("Thermal limits not provided and 'self.ts_manager.limits' is unavailable or invalid." )
646- else :
647- _thermal_limits = self ._thermal_limit_a
648-
649- # Update the thermal limits manager for protection scheme
650640 self .ts_manager = thermalLimits .ThermalLimits (
651- _thermal_limit_a = _thermal_limits ,
641+ _thermal_limit_a = self . _thermal_limit_a ,
652642 n_line = self .n_line ,
653643 line_names = self .name_line
654644 )
@@ -733,6 +723,7 @@ def _custom_deepcopy_for_copy(self, new_obj, dict_=None):
733723 new_obj ._backend_action = copy .deepcopy (self ._backend_action )
734724
735725 # specific to Basic Env, do not change
726+ new_obj .backend = self .backend .copy ()
736727 new_obj .ts_manager = self .ts_manager .copy ()
737728 if self ._thermal_limit_a is not None :
738729 new_obj .ts_manager .limits = self ._thermal_limit_a
@@ -1792,52 +1783,51 @@ def _init_backend(
17921783 """
17931784 pass
17941785
1795- def set_thermal_limit (self , thermal_limit ):
1796- """
1797- Set the thermal limit effectively.
1786+ # def set_thermal_limit(self, thermal_limit):
1787+ # """
1788+ # Set the thermal limit effectively.
17981789
1799- Parameters
1800- ----------
1801- thermal_limit: ``numpy.ndarray``
1802- The new thermal limit. It must be a numpy ndarray vector (or convertible to it). For each powerline it
1803- gives the new thermal limit.
1790+ # Parameters
1791+ # ----------
1792+ # thermal_limit: ``numpy.ndarray``
1793+ # The new thermal limit. It must be a numpy ndarray vector (or convertible to it). For each powerline it
1794+ # gives the new thermal limit.
18041795
1805- Alternatively, this can be a dictionary mapping the line names (keys) to its thermal limits (values). In
1806- that case, all thermal limits for all powerlines should be specified (this is a safety measure
1807- to reduce the odds of misuse).
1796+ # Alternatively, this can be a dictionary mapping the line names (keys) to its thermal limits (values). In
1797+ # that case, all thermal limits for all powerlines should be specified (this is a safety measure
1798+ # to reduce the odds of misuse).
18081799
1809- Examples
1810- ---------
1800+ # Examples
1801+ # ---------
18111802
1812- This function can be used like this:
1803+ # This function can be used like this:
18131804
1814- .. code-block:: python
1805+ # .. code-block:: python
18151806
1816- import grid2op
1807+ # import grid2op
18171808
1818- # I create an environment
1819- env = grid2op.make(""l2rpn_case14_sandbox"", test=True)
1809+ # # I create an environment
1810+ # env = grid2op.make(""l2rpn_case14_sandbox"", test=True)
18201811
1821- # i set the thermal limit of each powerline to 20000 amps
1822- env.set_thermal_limit([20000 for _ in range(env.n_line)])
1812+ # # i set the thermal limit of each powerline to 20000 amps
1813+ # env.set_thermal_limit([20000 for _ in range(env.n_line)])
18231814
1824- Notes
1825- -----
1826- As of grid2op > 1.5.0, it is possible to set the thermal limit by using a dictionary with the keys being
1827- the name of the powerline and the values the thermal limits.
1815+ # Notes
1816+ # -----
1817+ # As of grid2op > 1.5.0, it is possible to set the thermal limit by using a dictionary with the keys being
1818+ # the name of the powerline and the values the thermal limits.
18281819
1829- """
1830- if self .__closed :
1831- raise EnvError ("This environment is closed, you cannot use it." )
1832- if not self .__is_init :
1833- raise Grid2OpException (
1834- "Impossible to set the thermal limit to a non initialized Environment. "
1835- "Have you called `env.reset()` after last game over ?"
1836- )
1837- # update n_line and name_line of ts_manager (old : self.ts_manager.n_line = -1 and self.ts_manager.name_line = None)
1838- self .ts_manager .env_limits (thermal_limit = thermal_limit )
1839- self .ts_manager .limits = self ._thermal_limit_a
1840- self .observation_space .set_thermal_limit (self ._thermal_limit_a )
1820+ # """
1821+ # if self.__closed:
1822+ # raise EnvError("This environment is closed, you cannot use it.")
1823+ # if not self.__is_init:
1824+ # raise Grid2OpException(
1825+ # "Impossible to set the thermal limit to a non initialized Environment. "
1826+ # "Have you called `env.reset()` after last game over ?"
1827+ # )
1828+ # # update n_line and name_line of ts_manager (old : self.ts_manager.n_line = -1 and self.ts_manager.name_line = None)
1829+ # self.ts_manager.env_limits(thermal_limit=thermal_limit)
1830+ # self.observation_space.set_thermal_limit(thermal_limit=thermal_limit)
18411831
18421832 def _reset_redispatching (self ):
18431833 # redispatching
@@ -2492,33 +2482,33 @@ def get_obs(self, _update_state=True, _do_copy=True):
24922482 else :
24932483 return self ._last_obs
24942484
2495- def get_thermal_limit (self ):
2496- """
2497- Get the current thermal limit in amps registered for the environment.
2485+ # def get_thermal_limit(self):
2486+ # """
2487+ # Get the current thermal limit in amps registered for the environment.
24982488
2499- Examples
2500- ---------
2489+ # Examples
2490+ # ---------
25012491
2502- It can be used like this:
2492+ # It can be used like this:
25032493
2504- .. code-block:: python
2494+ # .. code-block:: python
25052495
2506- import grid2op
2496+ # import grid2op
25072497
2508- # I create an environment
2509- env = grid2op.make("l2rpn_case14_sandbox")
2498+ # # I create an environment
2499+ # env = grid2op.make("l2rpn_case14_sandbox")
25102500
2511- thermal_limits = env.get_thermal_limit()
2501+ # thermal_limits = env.get_thermal_limit()
25122502
2513- """
2514- if self .__closed :
2515- raise EnvError ("This environment is closed, you cannot use it." )
2516- if not self .__is_init :
2517- raise EnvError (
2518- "This environment is not initialized. It has no thermal limits. "
2519- "Have you called `env.reset()` after last game over ?"
2520- )
2521- return 1.0 * self ._thermal_limit_a
2503+ # """
2504+ # if self.__closed:
2505+ # raise EnvError("This environment is closed, you cannot use it.")
2506+ # if not self.__is_init:
2507+ # raise EnvError(
2508+ # "This environment is not initialized. It has no thermal limits. "
2509+ # "Have you called `env.reset()` after last game over ?"
2510+ # )
2511+ # return 1.0 * self._thermal_limit_a
25222512
25232513 def _withdraw_storage_losses (self ):
25242514 """
@@ -3053,7 +3043,7 @@ def _update_alert_properties(self, action, lines_attacked, subs_attacked):
30533043 def _aux_register_env_converged (self , disc_lines , action , init_line_status , new_p ):
30543044 beg_res = time .perf_counter ()
30553045 # update the thermal limit, for DLR for example
3056- self .ts_manager .update_limits (thermal_limit_a = self . _thermal_limit_a ) # old code : self.backend.update_thermal_limit(self)
3046+ self .ts_manager .update_limits (self ) # old code : self.backend.update_thermal_limit(self)
30573047
30583048 overflow_lines = self .backend .get_line_overflow ()
30593049 # save the current topology as "last" topology (for connected powerlines)
@@ -3116,11 +3106,10 @@ def _aux_register_env_converged(self, disc_lines, action, init_line_status, new_
31163106 # TODO is non zero and disconnected, this should be ok.
31173107 self ._time_extract_obs += time .perf_counter () - beg_res
31183108
3119- def _backend_next_grid_state (self ):
3109+ def _protection_next_grid_state (self ):
31203110 """overlaoded in MaskedEnv"""
31213111 self ._init_thermal_limit ()
31223112 self ._init_protection ()
3123- return self .protection .next_grid_state ()
31243113
31253114 def _aux_run_pf_after_state_properly_set (
31263115 self , action , init_line_status , new_p , except_
@@ -3130,7 +3119,8 @@ def _aux_run_pf_after_state_properly_set(
31303119 try :
31313120 # compute the next _grid state
31323121 beg_pf = time .perf_counter ()
3133- disc_lines , detailed_info , conv_ = self ._backend_next_grid_state ()
3122+ self ._protection_next_grid_state ()
3123+ disc_lines , detailed_info , conv_ = self .protection .next_grid_state ()
31343124 self ._disc_lines [:] = disc_lines
31353125 self ._time_powerflow += time .perf_counter () - beg_pf
31363126 if conv_ is None :
0 commit comments