@@ -432,7 +432,63 @@ def test_shedding_load_step(self):
432432 assert np .abs (self .env ._delta_gen_p .sum () / self .env ._gen_activeprod_t .sum ()) <= 0.02 # less than 2% losses
433433
434434
435+ class TestSheddingActionsNoShedding (unittest .TestCase ):
436+ def setUp (self ) -> None :
437+ super ().setUp ()
438+ p = Parameters ()
439+ p .MAX_SUB_CHANGED = 999999
440+ with warnings .catch_warnings ():
441+ warnings .filterwarnings ("ignore" )
442+ self .env = grid2op .make ("educ_case14_storage" ,
443+ param = p ,
444+ action_class = CompleteAction ,
445+ allow_detachment = False ,
446+ test = True ,
447+ _add_to_name = type (self ).__name__ )
448+ obs = self .env .reset (seed = 0 , options = {"time serie id" : 0 }) # Reproducibility
449+
450+ def tearDown (self ) -> None :
451+ self .env .close ()
452+ super ().tearDown ()
453+
454+ def test_load (self ):
455+ obs = self .env .reset ()
456+ assert not type (self .env ).detachment_is_allowed
457+ assert (~ obs .load_detached ).all ()
458+
459+ with self .assertRaises (UserWarning ):
460+ with warnings .catch_warnings ():
461+ warnings .filterwarnings ("error" )
462+ self .env .action_space ({"detach_load" : 0 })
463+
464+ obs , reward , done , info = self .env .step (self .env .action_space ({"set_bus" : {"loads_id" : [(0 , - 1 )]}}))
465+ assert done
466+
467+ def test_gen (self ):
468+ obs = self .env .reset ()
469+ assert not type (self .env ).detachment_is_allowed
470+ assert (~ obs .gen_detached ).all ()
471+
472+ with self .assertRaises (UserWarning ):
473+ with warnings .catch_warnings ():
474+ warnings .filterwarnings ("error" )
475+ self .env .action_space ({"detach_gen" : 0 })
476+
477+ obs , reward , done , info = self .env .step (self .env .action_space ({"set_bus" : {"generators_id" : [(0 , - 1 )]}}))
478+ assert done
479+
480+ def test_storage (self ):
481+ obs = self .env .reset ()
482+ assert not type (self .env ).detachment_is_allowed
483+ assert (~ obs .storage_detached ).all ()
484+
485+ with self .assertRaises (UserWarning ):
486+ with warnings .catch_warnings ():
487+ warnings .filterwarnings ("error" )
488+ self .env .action_space ({"detach_storage" : 0 })
435489
490+ obs , reward , done , info = self .env .step (self .env .action_space ({"set_bus" : {"storages_id" : [(0 , - 1 )]}, "set_storage" : [(0 , 1. )]}))
491+ assert done
436492
437493
438494# TODO with the env parameters STOP_EP_IF_GEN_BREAK_CONSTRAINTS and ENV_DOES_REDISPATCHING
0 commit comments