예제 #1
0
 def __init__(
     self,
     action_size,
     observation_size,  # not used here for retro compatibility with NNParam.from_dict
     sizes,
     activs,
     x_dim,
     list_attr_obs,
     tau_dims,
     tau_adds,
     tau_mults,
     list_attr_obs_tau,
 ):
     NNParam.__init__(
         self,
         action_size,
         observation_size=x_dim +
         np.sum(tau_dims),  # TODO this might not be usefull
         sizes=sizes,
         activs=activs,
         list_attr_obs=list_attr_obs)
     self.tau_dims = [int(el) for el in tau_dims]
     self.list_attr_obs_tau = [str(el) for el in list_attr_obs_tau]
     self.x_dim = x_dim
     self.tau_adds = tau_adds
     self.tau_mults = tau_mults
예제 #2
0
    def test_train_eval(self):
        tp = TrainingParam()
        tp.buffer_size = 100
        tp.minibatch_size = 8
        tp.update_freq = 32
        tp.min_observation = 32
        tmp_dir = tempfile.mkdtemp()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            env = grid2op.make("rte_case5_example", test=True)
            # neural network architecture
            li_attr_obs_X = ["prod_p", "load_p", "rho"]
            li_attr_obs_Tau = ["line_status"]
            sizes = [100, 50, 10]

            x_dim = NNParam.get_obs_size(env, li_attr_obs_X)
            tau_dims = [
                NNParam.get_obs_size(env, [el]) for el in li_attr_obs_Tau
            ]

            kwargs_archi = {
                'sizes': sizes,
                'activs': ["relu" for _ in sizes],
                'x_dim': x_dim,
                'tau_dims': tau_dims,
                'tau_adds': [0.0 for _ in range(len(tau_dims))],
                'tau_mults': [1.0 for _ in range(len(tau_dims))],
                "list_attr_obs": li_attr_obs_X,
                "list_attr_obs_tau": li_attr_obs_Tau
            }

            kwargs_converters = {
                "all_actions": None,
                "set_line_status": False,
                "change_bus_vect": True,
                "set_topo_vect": False
            }
            nm_ = "AnneOnymous"
            train_leap(env,
                       name=nm_,
                       iterations=100,
                       save_path=tmp_dir,
                       load_path=None,
                       logs_dir=tmp_dir,
                       training_param=tp,
                       verbose=False,
                       kwargs_converters=kwargs_converters,
                       kwargs_archi=kwargs_archi)

            baseline_2 = eval_leap(env,
                                   name=nm_,
                                   load_path=tmp_dir,
                                   logs_path=tmp_dir,
                                   nb_episode=1,
                                   nb_process=1,
                                   max_steps=30,
                                   verbose=False,
                                   save_gif=False)
예제 #3
0
 def __init__(
         self,
         action_size,
         observation_size,  # TODO this might not be usefull
         sizes,
         activs,
         list_attr_obs):
     NNParam.__init__(
         self,
         action_size,
         observation_size,  # TODO this might not be usefull
         sizes,
         activs,
         list_attr_obs)
예제 #4
0
    def test_train_eval(self):
        if has_SACOld is not None:
            raise ImportError(
                f"TestSACOld is not available with error:\n{has_SACOld}")
        tp = TrainingParam()
        tp.buffer_size = 100
        tp.minibatch_size = 8
        tp.update_freq = 32
        tp.min_observation = 32
        tmp_dir = tempfile.mkdtemp()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            env = grid2op.make("rte_case5_example", test=True)
            li_attr_obs_X = ["prod_p", "load_p", "rho"]

            # neural network architecture
            observation_size = NNParam.get_obs_size(env, li_attr_obs_X)
            sizes_q = [100, 50, 10]  # sizes of each hidden layers
            sizes_v = [100, 100]  # sizes of each hidden layers
            sizes_pol = [100, 10]  # sizes of each hidden layers
            kwargs_archi = {
                'observation_size': observation_size,
                'sizes': sizes_q,
                'activs': ["relu" for _ in range(len(sizes_q))],
                "list_attr_obs": li_attr_obs_X,
                "sizes_value": sizes_v,
                "activs_value": ["relu" for _ in range(len(sizes_v))],
                "sizes_policy": sizes_pol,
                "activs_policy": ["relu" for _ in range(len(sizes_pol))]
            }

            kwargs_converters = {
                "all_actions": None,
                "set_line_status": False,
                "change_bus_vect": True,
                "set_topo_vect": False
            }
            nm_ = "AnneOnymous"
            train_sacold(env,
                         name=nm_,
                         iterations=100,
                         save_path=tmp_dir,
                         load_path=None,
                         logs_dir=tmp_dir,
                         training_param=tp,
                         verbose=False,
                         kwargs_converters=kwargs_converters,
                         kwargs_archi=kwargs_archi)

            baseline_2 = eval_sacold(env,
                                     name=nm_,
                                     load_path=tmp_dir,
                                     logs_path=tmp_dir,
                                     nb_episode=1,
                                     nb_process=1,
                                     max_steps=30,
                                     verbose=False,
                                     save_gif=False)
예제 #5
0
    def test_train_eval(self):
        tp = TrainingParam()
        tp.buffer_size = 100
        tp.minibatch_size = 8
        tp.update_freq = 32
        tmp_dir = tempfile.mkdtemp()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            env = grid2op.make("rte_case5_example", test=True)
            li_attr_obs_X = [
                "day_of_week", "hour_of_day", "minute_of_hour", "prod_p",
                "prod_v", "load_p", "load_q", "actual_dispatch",
                "target_dispatch", "topo_vect", "time_before_cooldown_line",
                "time_before_cooldown_sub", "rho", "timestep_overflow",
                "line_status"
            ]

            # neural network architecture
            observation_size = NNParam.get_obs_size(env, li_attr_obs_X)
            sizes = [100, 50, 10]  # sizes of each hidden layers
            kwargs_archi = {
                'observation_size': observation_size,
                'sizes': sizes,
                'activs':
                ["relu" for _ in sizes],  # all relu activation function
                "list_attr_obs": li_attr_obs_X
            }

            kwargs_converters = {
                "all_actions": None,
                "set_line_status": False,
                "change_bus_vect": True,
                "set_topo_vect": False
            }
            nm_ = "AnneOnymous"
            train_d3qn(env,
                       name=nm_,
                       iterations=100,
                       save_path=tmp_dir,
                       load_path=None,
                       logs_dir=tmp_dir,
                       nb_env=1,
                       training_param=tp,
                       verbose=False,
                       kwargs_converters=kwargs_converters,
                       kwargs_archi=kwargs_archi)

            baseline_2 = eval_d3qn(env,
                                   name=nm_,
                                   load_path=tmp_dir,
                                   logs_path=tmp_dir,
                                   nb_episode=1,
                                   nb_process=1,
                                   max_steps=30,
                                   verbose=False,
                                   save_gif=False)
예제 #6
0
    def test_train_eval_multiprocess(self):
        # test only done for this baselines because the feature is coded in base class in DeepQAgent
        tp = TrainingParam()
        tp.buffer_size = 100
        tp.minibatch_size = 8
        tp.update_freq = 32
        tp.min_observation = 32
        tmp_dir = tempfile.mkdtemp()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            env_init = grid2op.make("rte_case5_example", test=True)
            env = make_multi_env(env_init=env_init, nb_env=2)
            li_attr_obs_X = ["prod_p", "load_p", "rho"]

            # neural network architecture
            observation_size = NNParam.get_obs_size(env, li_attr_obs_X)
            sizes = [100, 50, 10]  # sizes of each hidden layers
            kwargs_archi = {
                'observation_size': observation_size,
                'sizes': sizes,
                'activs':
                ["relu" for _ in sizes],  # all relu activation function
                "list_attr_obs": li_attr_obs_X
            }

            kwargs_converters = {
                "all_actions": None,
                "set_line_status": False,
                "change_bus_vect": True,
                "set_topo_vect": False
            }
            nm_ = "AnneOnymous"
            train_dqn(env,
                      name=nm_,
                      iterations=100,
                      save_path=tmp_dir,
                      load_path=None,
                      logs_dir=tmp_dir,
                      training_param=tp,
                      verbose=False,
                      kwargs_converters=kwargs_converters,
                      kwargs_archi=kwargs_archi)

            baseline_2 = eval_dqn(env_init,
                                  name=nm_,
                                  load_path=tmp_dir,
                                  logs_path=tmp_dir,
                                  nb_episode=1,
                                  nb_process=1,
                                  max_steps=30,
                                  verbose=False,
                                  save_gif=False)
예제 #7
0
 def __init__(
         self,
         action_size,
         observation_size,  # TODO this might not be usefull
         sizes,
         activs,
         list_attr_obs,
         sizes_value,
         activs_value,
         sizes_policy,
         activs_policy):
     NNParam.__init__(
         self,
         action_size,
         observation_size,  # TODO this might not be usefull
         sizes,
         activs,
         list_attr_obs)
     self.sizes_value = sizes_value
     self.activs_value = activs_value
     self.sizes_policy = sizes_policy
     self.activs_policy = activs_policy