AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)
MIT License
2.14k stars 470 forks source link

[QUESTION] Error in TradeEnv running check_env() from stable baselines #2

Closed simonesalvucci closed 4 years ago

simonesalvucci commented 4 years ago

Hi there,

I've encountered an issue running the following code:

import gym
from gym_anytrading.envs import TradingEnv, ForexEnv, Actions, Positions 
from gym_anytrading.datasets import FOREX_EURUSD_1H_ASK
from stable_baselines.common.env_checker import check_env

env = gym.make('forex-v0', frame_bound=(10, 500), window_size=10)
check_env(env, warn=False, skip_render_check=False)

The output I get is: AssertionError: The observation returned by the reset() method does not match the given observation space

I've debugged your TradingEnv class and did't see any issue, so I've thought the problem could be in check_env().

I've debugged check_env() as well, but everything seems fine there. Then I went for the last test which was running check_env() with the classic CartPole-v0 from gym, here check_env() didn't trow any exception and run smoothly.

This is the code for the CartPole-v0:

import gym
from gym.envs.classic_control import CartPoleEnv
from stable_baselines.common.env_checker import check_env

env = gym.make('CartPole-v0')
check_env(env, warn=False, skip_render_check=False)

Do you have any clue why this is happening? I'm confused lol

simonesalvucci commented 4 years ago

I've just realised I didn't reset the environment before running check_env() Doing that solves the issue.

simonesalvucci commented 4 years ago

Actually I was wrong, resetting the environment doesn't solve the issue. Sorry about that...

AminHP commented 4 years ago

Hi.

It was a small bug and I fixed it. Thank you!

simonesalvucci commented 4 years ago

The fix solves the issue, thank you!