0
$\begingroup$

How can one render the environment using the Tensorforce library?

I've tried calling environment.render, but it says that the function does not exist. This is my code:

from tensorforce.agents import Agent
from tensorforce.environments import Environment
from tensorforce.execution import Runner

# Create an OpenAI-Gym environment
environment = Environment.create(environment='gym', level='MountainCarContinuous-v0')

agent = Agent.create(agent='random', environment=environment)   

# runner = Runner(agent=agent, environment=environment) # Initialize the runner
# runner.run(num_episodes=NUM_EPISODES) # Start the runner
# runner.close()

# Train
for ep in range(NUM_EPISODES): # Number of episodes

    print('********Episode ' + str(ep) + '********')

    # Initialize episode
    states = environment.reset()
    done = False
    step = 0

    while not done: # Episode timestep
        actions = agent.act(states=states)
        states, done, reward = environment.execute(actions=actions)
        agent.observe(terminal=done, reward=reward)
        environment.render() # Gives error

environment.close()
agent.close()

And this is the error I get:

Traceback (most recent call last):

  File "c:\users\user\reinforcement learning\rl.py", line 179, in <module>
    environment.render()

AttributeError: 'OpenAIGym' object has no attribute 'render'
$\endgroup$
1
$\begingroup$

In case you use https://github.com/tensorforce/tensorforce/blob/master/examples/act_observe_interface.py ,
the following modification works.
Import gym:

import gym
from gym import wrappers

then define a Tensorforce environment with a Gym environment:

    env = gym.make('CartPole-v1')
    env = wrappers.Monitor(env, 'tmp', force=True)

    environment = Environment.create(environment=env, max_episode_timesteps=500)
    # environment = Environment.create(environment='/Users/rondelion/git/tensorforce/benchmarks/configs/cartpole.json')

and render the Gym environment:

            ....
            num_updates += agent.observe(terminal=terminal, reward=reward)
            env.render()
            sum_rewards += reward
            ....


$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.