question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Stable Baseline render vectorized forex enviroment

See original GitHub issue

Hello, I have a question…

I’m currently using the stable baselines library to train a model using your ‘forex-v0’ environment.

env = DummyVecEnv([lambda: gym.make('forex-v0', frame_bound=(10, 500), window_size=10)])
policy_kwargs = dict(net_arch=[64, 'lstm',dict(vf=[128,128,128], pi=[64,64])])
model = A2C("MlpLstmPolicy", env, verbose=1, policy_kwargs=policy_kwargs)
model.learn(total_timesteps=5000)

After training the model I perform a test using your code:

observation = env.reset()
while True:
        action = model.predict(observation)
        observation, reward, done, info = env.step(action)
        # env.render()
        if done:
            print("info:", info)
            break

# Plotting results
plt.cla()
env.render_all()
plt.show()

But unfortunately I get a DummyVecEnv has no render_all() which makes sense to me because now the environment is in a Vector. The thing I don’t understand is how I can call env.render_all() in the Vector. My confusion it’s because when I call env.render() everything works fine, but not when I call env.render_all()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
AminHPcommented, Jan 30, 2020

The problem is something inside the DummyVecEnv which resets the environment automatically after it is done.

Also, there was a mistake in your code. Try this:

env_maker = lambda: gym.make('forex-v0', frame_bound=(100, 5000), window_size=10)
env = DummyVecEnv([env_maker])

# Training Env
policy_kwargs = dict(net_arch=[64, 'lstm',dict(vf=[128,128,128], pi=[64,64])])
model = A2C("MlpLstmPolicy", env, verbose=1, policy_kwargs=policy_kwargs)
model.learn(total_timesteps=1000)

# Testing Env 
env = env_maker()
observation = env.reset()

while True:
    observation = observation[np.newaxis, ...]
    # action = env.action_space.sample()
    action, _states = model.predict(observation)
    observation, reward, done, info = env.step(action)
    # env.render()
    if done:
        print("info:", info)
        break

# Plotting results
plt.cla()
env.render_all()
plt.show()

0reactions
simonesalvuccicommented, Jan 30, 2020

Thank you @AminHP

I must have missed the reset of the environment in DummyVecEnv. Now it makes much more sense.

The code above works perfectly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vectorized Environments - Stable Baselines - Read the Docs
Vectorized Environments are a method for stacking multiple independent environments into a single environment. Instead of training an RL agent on 1 ...
Read more >
Newest 'stable-baselines' Questions - Stack Overflow
I would like to train a gym model based on a custom environment. The training loop looks like this: obs = env.reset() for...
Read more >
Create custom gym environments from scratch — A stock ...
OpenAI's gym is an awesome package that allows you to create custom reinforcement learning agents. It comes with quite a few pre-built ...
Read more >
Stable Baselines Documentation - Read the Docs
env.render(). 1.6.3 Multiprocessing: Unleashing the Power of Vectorized Environments. 14. Chapter 1. Main differences with OpenAI Baselines ...
Read more >
QuickLaTeX - Pavel Holoborodko
and environments: equation , align , displaymath , eqnarray , multline , flalign ... Rendering into vector image format SVG, which means formulas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found