We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.7.0
1.4.0
Ubuntu 18.04 LTS
3.9.12
I'm trying to add some features to the space using the as_networkx method but sometimes there are some problems with that conversion.
# python script.py
import torch as th from stable_baselines3 import SAC from stable_baselines3.common.torch_layers import BaseFeaturesExtractor import gym from grid2op import make from grid2op.gym_compat import BoxGymActSpace, GymEnv from copy import deepcopy import networkx as nx from gym.spaces import Box import numpy as np import torch.nn as nn def build_matrix(obs, key): if isinstance(obs, nx.Graph): graph = obs else: graph = obs.as_networkx() matrix = nx.attr_matrix(graph, edge_attr=key)[0] return matrix class FeatureExtractor(BaseFeaturesExtractor): def __init__(self, observation_space: gym.spaces.Dict, features_dim: int, device): super(FeatureExtractor, self).__init__( observation_space, features_dim) self.device = device space = observation_space["rho_matrix"] n = space.shape[0] * space.shape[1] self.last_dense = nn.Sequential( nn.Linear(n, self.features_dim), nn.ReLU()) def forward(self, observations: gym.spaces.Dict) -> th.Tensor: return self.last_dense.forward(observations["rho_matrix"].flatten(1)) POLICY = { "features_extractor_class": FeatureExtractor, "features_extractor_kwargs": { "features_dim": 256, "device": "cpu", }, "activation_fn": th.nn.ReLU} if __name__ == "__main__": grid2op_env = make("rte_case5_example", test=True) env = GymEnv(grid2op_env) # create the gym environment # CHANGING ACTION SPACE env.action_space = BoxGymActSpace(env.init_env.action_space) # CHANGING OBSERVATION SPACE # Adding vars grid2op_obs = grid2op_env.reset() # Adding vars graph = deepcopy(grid2op_obs).as_networkx() # graph_vars = {} graph_vars = {"rho":(-1000, 1000)} for k in graph_vars.keys(): shape_ = build_matrix(graph, k).shape env.observation_space.add_key(f"{k}_matrix", lambda obs: build_matrix(obs, k), Box(shape=shape_, low=np.full(shape_, graph_vars[k][0]), high=np.full(shape_, graph_vars[k][1]))) agent = SAC("MultiInputPolicy",env, policy_kwargs=POLICY) agent.learn(total_timesteps=1e5)
ValueError: zero-size array to reduction operation maximum which has no identity
The text was updated successfully, but these errors were encountered:
Hello,
Thanks for notifying us of this bug.
It's rather easy to reproduce with your code snippet. Thanks. Hopefully i'll be able to fix it for the next release.
Sorry, something went wrong.
adressing issue rte-france#327
3e5d487
Merge pull request #328 from BDonnot/master
7fcabf1
fix issue #327 and implement l2rpn 2022 score
No branches or pull requests
Environment
1.7.0
1.4.0
Ubuntu 18.04 LTS
3.9.12
Bug description
I'm trying to add some features to the space using the as_networkx method but sometimes there are some problems with that conversion.
Command line
# python script.py
Code snippet
Current output
The text was updated successfully, but these errors were encountered: