rll / rllab

rllab is a framework for developing and evaluating reinforcement learning algorithms, fully compatible with OpenAI Gym.
Other
2.91k stars 799 forks source link

ValueError: I/O operation on closed file #31

Closed aravindr93 closed 8 years ago

aravindr93 commented 8 years ago

I'm not sure what I'm doing wrong here. I haven't changed anything from the master branch and the following simple implementation gives me this error. Would appreciate some help. Thanks!

from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.gym_env import GymEnv
from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy
from rllab.envs.normalized_env import normalize
from rllab.algos.vpg import VPG
import numpy as np

env = normalize(GymEnv("Reacher-v1"))
policy = GaussianMLPPolicy(env_spec=env.spec, hidden_sizes=(16,16))
baseline = LinearFeatureBaseline(env_spec=env.spec)

# set properties
algo.batch_size = 50  # N
algo.max_path_length=50   # T
algo.discount=0.99  # gamma
algo.n_itr=250  # n_iter

algo.train()

I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-f78c549ec9f8> in <module>()
----> 1 algo.train()

/home/aravind/Programs/rllab/rllab/algos/batch_polopt.pyc in train(self)
    249             with logger.prefix('itr #%d | ' % itr):
    250                 paths = self.sampler.obtain_samples(itr)
--> 251                 samples_data = self.sampler.process_samples(itr, paths)
    252                 self.log_diagnostics(paths)
    253                 self.optimize_policy(itr, samples_data)

/home/aravind/Programs/rllab/rllab/algos/batch_polopt.pyc in process_samples(self, itr, paths)
    146             )
    147 
--> 148         logger.log("fitting baseline...")
    149         self.algo.baseline.fit(paths)
    150         logger.log("fitted")

/home/aravind/Programs/rllab/rllab/misc/logger.pyc in log(s, with_prefix, with_timestamp)
    112     if not _log_tabular_only:
    113         # Also log to stdout
--> 114         print(out)
    115         for fd in _text_fds.values():
    116             fd.write(out + '\n')

/home/aravind/anaconda2/envs/rllab/lib/python2.7/site-packages/ipykernel/iostream.pyc in write(self, string)
    315 
    316             is_child = (not self._is_master_process())
--> 317             self._buffer.write(string)
    318             if is_child:
    319                 # newlines imply flush in subprocesses

ValueError: I/O operation on closed file
dementrock commented 8 years ago

Hi @aravindr93, can you try running it outside of IPython and see if it works?

aravindr93 commented 8 years ago

@dementrock It works outside. Not sure what is happening here. Anyway, I'm closing the issue :) Thanks!