Skip to content
New issue

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

Occasional failure of tests due to GraphSnakeEnv #23

Open
eunkich opened this issue Apr 27, 2022 · 4 comments
Open

Occasional failure of tests due to GraphSnakeEnv #23

eunkich opened this issue Apr 27, 2022 · 4 comments

Comments

@eunkich
Copy link
Contributor

eunkich commented Apr 27, 2022

#21 Pytest occasionally fails because of an error in graph_snake_env.py

logs when test fails

====================================================================== test session starts ======================================================================
platform linux -- Python 3.7.9, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/eunki/repos/marlenv
collected 5 items                                                                                                                                               

tests/test_snake.py ..F..                                                                                                                                 [100%]

=========================================================================== FAILURES ============================================================================
____________________________________________________________________ test_graph_env_rollout _____________________________________________________________________

graph_snake_env = <marlenv.envs.graph_snake_env.GraphSnakeEnv object at 0x7ff949543510>

    def test_graph_env_rollout(graph_snake_env):
        n_rollouts = 100
>       rollout(graph_snake_env, n=n_rollouts)

tests/test_snake.py:78: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_snake.py:65: in rollout
    obs, rews, dones, _ = env.step(ac)
marlenv/envs/snake_env.py:261: in step
    obs = self._get_obs()
marlenv/envs/graph_snake_env.py:54: in _get_obs
    proc_obs = self._process_obs(obs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <marlenv.envs.graph_snake_env.GraphSnakeEnv object at 0x7ff949543510>
obs = [array([[[1., 0., 0., ..., 0., 0., 0.],
        [1., 0., 0., ..., 0., 0., 0.],
        [1., 0., 0., ..., 0., 0., 0.],
..., 0., ..., 0., 0., 0.],
        [1., 0., 0., ..., 0., 0., 0.],
        [1., 0., 0., ..., 0., 0., 0.]]], dtype=float32)]

    def _process_obs(self, obs):
    
        if not self.observer=='snake':
            raise ValueError("This is not yet implemented for 'human' observers.")
        if self.image_obs:
            raise ValueError("This is not yet implemented for 'image' observation.")
    
        vision_range = 5 # range of vision in default five
        if self.vision_range:
            vision_range = self.vision_range
        proc_obs = []
        sqrt2 = math.sqrt(2)
        snake_idx = 0
        for snake in self.snakes: # for each snake
            proc_ob = []
            angle = math.atan2(snake.direction.value[1], snake.direction.value[0])
            head = snake.head_coord
            if self.vision_range: # if so, the head is at the center
                head = (self.vision_range, self.vision_range)
            for l in range(3): # for each of three directions except backward
                dx = (int(math.cos(angle + self.action_dict[l])), int(math.sin(angle + self.action_dict[l])))
                proc_ob.append(np.zeros((self.obs_ch, )))
                for i in range(vision_range):
>                   temp_ob = obs[snake_idx][head[0] + dx[0]*(i+1)][head[1] + dx[1]*(i+1)]
E                   IndexError: index 20 is out of bounds for axis 0 with size 20

marlenv/envs/graph_snake_env.py:81: IndexError
==================================================================== short test summary info ====================================================================
FAILED tests/test_snake.py::test_graph_env_rollout - IndexError: index 20 is out of bounds for axis 0 with size 20
================================================================== 1 failed, 4 passed in 1.72s ==================================================================

@eunkich
Copy link
Contributor Author

eunkich commented Apr 27, 2022

@anthony0727 I haven't looked into the test codes yet, but we might need some corner case tests without stochasticity for safety.

@anthony0727
Copy link
Member

@leeynsn can you plz take a look into this? 🙏

@leeynsn
Copy link
Contributor

leeynsn commented Jun 24, 2022

@anthony0727 Sure.

@leeynsn
Copy link
Contributor

leeynsn commented Jul 2, 2022

It was mainly caused by the observations of dead snakes.
I fixed the error by making those ones excluded from the graph observations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants