Exemplo n.º 1
0
    def test_step_dn(self):
        mme = MultiMixEnvironment(PATH_DATA_MULTIMIX)
        dn = mme.action_space({})

        obs, r, done, info  = mme.step(dn)
        assert obs is not None
        assert r is not None
        assert isinstance(info, dict)
        assert done is not True
Exemplo n.º 2
0
    def test_copy(self):
        # https://github.com/BDonnot/lightsim2grid/issues/10
        mme = MultiMixEnvironment(PATH_DATA_MULTIMIX)
        for i in range(5):
            obs, reward, done, info = mme.step(mme.action_space())
        env2 = mme.copy()

        obsnew = env2.get_obs()
        assert obsnew == obs

        # after the same action, the original env and its copy are the same
        obs0, reward0, done0, info0 = mme.step(mme.action_space())
        obs1, reward1, done1, info1 = env2.step(env2.action_space())
        assert obs0 == obs1
        assert reward0 == reward1
        assert done1 == done0

        # reset has the correct behaviour
        obs_after = env2.reset()
        obs00, reward00, done00, info00 = mme.step(mme.action_space())
        # i did not affect the other environment
        assert obs00.minute_of_hour == obs0.minute_of_hour + mme.chronics_handler.time_interval.seconds // 60
        # reset read the right chronics
        assert obs_after.minute_of_hour == 0
Exemplo n.º 3
0
    def test_step_switch_line(self):
        LINE_ID = 4
        mme = MultiMixEnvironment(PATH_DATA_MULTIMIX)
        line_ex_topo = mme.line_ex_pos_topo_vect[LINE_ID]
        line_or_topo = mme.line_or_pos_topo_vect[LINE_ID]
        switch_status = mme.action_space.get_change_line_status_vect()
        switch_status[LINE_ID] = True
        switch_action = mme.action_space({'change_line_status': switch_status})

        obs, r, d, info = mme.step(switch_action)
        assert d is False
        assert obs.line_status[LINE_ID] == False
        obs, r, d, info = mme.step(switch_action)
        assert d is False, "Diverged powerflow on reconnection"
        assert info["is_illegal"] == False, "Reconnecting should be legal"
        assert obs.line_status[LINE_ID] == True, "Line is not reconnected"
Exemplo n.º 4
0
 def test_creation_with_other_rewards(self):
     p = Parameters()
     p.NO_OVERFLOW_DISCONNECTION = True
     oth_r = {
         "game": GameplayReward,
         "l2rpn": L2RPNReward,
     }
     mme = MultiMixEnvironment(PATH_DATA_MULTIMIX,
                               param=p,
                               other_rewards=oth_r)
     assert mme.current_obs is not None
     assert mme.current_env is not None
     o, r, d, i = mme.step(mme.action_space({}))
     assert i is not None
     assert "rewards" in i
     assert "game" in i["rewards"]
     assert "l2rpn" in i["rewards"]
Exemplo n.º 5
0
 def test_forecast_toggle(self):
     mme = MultiMixEnvironment(PATH_DATA_MULTIMIX)
     dn = mme.action_space({})
     # Forecast off
     mme.deactivate_forecast()
     # Step once
     obs, _, _ , _ = mme.step(dn)
     # Cant simulate
     with self.assertRaises(NoForecastAvailable):
         obs.simulate(dn)
     # Forecast ON
     mme.reactivate_forecast()
     # Reset, step once
     mme.reset()
     obs, _, _ , _ = mme.step(dn)
     # Can simulate
     obs, r, done, info = obs.simulate(dn)
     assert obs is not None
     assert r is not None
     assert isinstance(info, dict)
     assert done is not True