Exemplo n.º 1
0
    def test_equal_loads(self):
        """
        Checks that same seed gives the same loads, solar production
        and rewards when set_parameters have been used
        """
        env1 = ActiveEnv(seed=3)
        env2 = ActiveEnv(seed=3)
        env2.set_parameters({
            'forecast_horizon': 10,
            'state_space': ['sun', 'demand', 'imbalance']
        })

        for _ in range(5):
            load1 = env1.powergrid.load['p_mw']
            load2 = env2.powergrid.load['p_mw']
            assert norm(load1 - load2) < 10e-5  # e

            sun1 = env1.powergrid.sgen['p_mw']
            sun2 = env2.powergrid.sgen['p_mw']
            assert norm(sun1 - sun2) < 10e-5

            action = env1.action_space.sample()
            ob1, reward1, episode_over1, info1 = env1.step(action)
            ob2, reward2, episode_over2, info2 = env2.step(action)

            assert reward1 == reward2
Exemplo n.º 2
0
    def test_error_term_solar(self):
        """
        Checks that the forecast values for solar irradiance deviates from
        the actual values
        """
        env = ActiveEnv(seed=3)
        env.set_parameters({'solar_std': 0.5})
        while env.get_solar_forecast()[0, 0] < 0.01:  # to avoid night (no sun)
            action = env.action_space.sample()
            env.step(action)

        nominal_sun = env.powergrid.sgen['sn_mva']
        solar_forecast = nominal_sun * env.get_solar_forecast()[:, 0]
        solar = -env.powergrid.sgen['p_mw']
        assert norm(solar_forecast - solar) > 0.01
Exemplo n.º 3
0
    def test_reward_parameters(self):
        """
        Checks that rewards are different for different reward setups
        """
        env1 = ActiveEnv(seed=3)
        env1.set_parameters({'reward_terms': ['voltage']})
        env2 = ActiveEnv(seed=3)
        env2.set_parameters({'reward_terms': ['current']})
        action = env1.action_space.sample()
        reward1 = 0
        while reward1 == 0:
            ob1, reward1, episode_over1, info1 = env1.step(action)
            ob2, reward2, episode_over2, info2 = env2.step(action)

        assert reward1 != reward2
Exemplo n.º 4
0
    def test_reset_seed(self):
        """
        Checks that same seeds give same environment when
        an episode resets
        """
        env1 = ActiveEnv(seed=7)
        env2 = ActiveEnv(seed=7)

        env1.set_parameters({'episode_length': 3, 'forecast_horizon': 1})
        env2.set_parameters({'episode_length': 3, 'forecast_horizon': 1})
        for _ in range(4):
            action = env1.action_space.sample()
            ob1, reward1, episode_over1, info1 = env1.step(action)
            ob2, reward2, episode_over2, info2 = env2.step(action)

        load1 = env1.powergrid.load['p_mw']
        load2 = env2.powergrid.load['p_mw']
        assert norm(load1 - load2) < 10e-5  # e
Exemplo n.º 5
0
    def test_constant_consumption(self):
        """
        Checks that the total demand and total modified demand is the same.
        In other words, checks that consumption is shifted and not altered.
        This should hold when 'hours' is even and force_commitments is True
        """
        env = ActiveEnv(force_commitments=True)
        env.set_parameters({'demand_std': 0})
        hours = 24
        for hour in range(hours):
            action = 1 * np.ones(len(env.powergrid.load))
            ob, reward, episode_over, info = env.step(action)

        total_demand = env.get_scaled_demand_forecast()[:, :hours].sum()
        total_modified_demand = env.resulting_demand[:hours].sum()
        assert np.abs(total_demand - total_modified_demand) < 10e-6
Exemplo n.º 6
0
        path = 'models/' + model_name + '.pkl'
    powermodel.save('models/' + model_name)
    with open('models/' + model_name + '_params.p', 'wb') as f:
        pickle.dump(env.params, f)


model_name = '800k_full'
path = 'models/' + model_name + '.pkl'
i = 2
while os.path.isfile(path):
    model_name += '_' + str(i)
    i += 1
    path = 'models/' + model_name + '.pkl'
powermodel.save('models/' + model_name)
with open('models/' + model_name + '_params.p', 'wb') as f:
    pickle.dump(env.params, f)

for i in range(100):
    action, _ = powermodel.predict(obs)
    obs, rewards, dones, info = powerenv.step(action)
    line = {}
    for i, act in enumerate(action[0]):
        line[i] = act
    data.append(line)

df = pd.DataFrame(data)
df['demand'] = env.get_episode_demand_forecast()[0][:100]
df['sol'] = env.get_episode_solar_forecast()[:100]
df.loc[:, ['demand', 'sol', 3]].plot()
plt.show()