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

create a new environment using Shichao's wrapper update #97

Open
YangyangFu opened this issue Feb 23, 2022 · 2 comments
Open

create a new environment using Shichao's wrapper update #97

YangyangFu opened this issue Feb 23, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@YangyangFu
Copy link
Owner


class Gym_Wrapper(gym.Wrapper):
    def __init__(self, env):
        super(Gym_Wrapper, self).__init__(env)
        self.h = np.array([86400., 273.15+30, 273.15+40,1200., 1000.]+[273.15+40]*3+[1200.]*3 + [args.num_of_days*24*3600.0])
        self.l = np.array([0., 273.15+12, 273.15+0,0, 0]+[273.15+0]*3+[0.0]*3 + [0.0])
        self.time_cnt = 0.0
        self.state_dim = self.env.observation_space.shape[0] + 1
        self.action_n = self.env.action_space.n
    def step(self, action):
        ob, r, d, info = self.env.step(action)
        self.time_cnt += args.time_step
        ob = np.append(ob, [self.time_cnt])
        ob = (ob - self.l)/(self.h-self.l)
        #print(ob)
        return ob, r, d, info
    def reset(self):
        self.time_cnt = 0.0
        ob = self.env.reset()
        ob = np.append(ob, [self.time_cnt])
        ob = (ob - self.l)/(self.h-self.l)
        return ob
    def get_cost(self):
        return self.env.get_cost()
1:29
env = make_building_env(args)
env = Gym_Wrapper(env)
@YangyangFu YangyangFu added the enhancement New feature or request label May 13, 2022
@mingzhe37
Copy link
Collaborator

mingzhe37 commented Nov 27, 2023

@YangyangFu Have ever tried if this wrapper approach works? This runs into an error if I use Ray to run the simulation using a similar wrapper.

Failure # 1 (occurred at 2023-11-27_22-57-21)
Traceback (most recent call last):
File "/opt/conda/lib/python3.8/site-packages/ray/tune/trial_runner.py", line 893, in _process_trial
results = self.trial_executor.fetch_result(trial)
File "/opt/conda/lib/python3.8/site-packages/ray/tune/ray_trial_executor.py", line 707, in fetch_result
result = ray.get(trial_future[0], timeout=DEFAULT_GET_TIMEOUT)
File "/opt/conda/lib/python3.8/site-packages/ray/_private/client_mode_hook.py", line 105, in wrapper
return func(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/ray/worker.py", line 1733, in get
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(TuneError): �[36mray::ImplicitFunc.train()�[39m (pid=178, ip=172.17.0.2, repr=trainable_function)
File "/opt/conda/lib/python3.8/site-packages/ray/tune/trainable.py", line 315, in train
result = self.step()
File "/opt/conda/lib/python3.8/site-packages/ray/tune/function_runner.py", line 381, in step
self._report_thread_runner_error(block=True)
File "/opt/conda/lib/python3.8/site-packages/ray/tune/function_runner.py", line 531, in _report_thread_runner_error
raise TuneError(
ray.tune.error.TuneError: Trial raised an exception. Traceback:
�[36mray::ImplicitFunc.train()�[39m (pid=178, ip=172.17.0.2, repr=trainable_function)
File "/opt/conda/lib/python3.8/site-packages/ray/tune/function_runner.py", line 262, in run
self._entrypoint()
File "/opt/conda/lib/python3.8/site-packages/ray/tune/function_runner.py", line 330, in entrypoint
return self._trainable_func(self.config, self._status_reporter,
File "/opt/conda/lib/python3.8/site-packages/ray/tune/function_runner.py", line 600, in _trainable_func
output = fn()
File "/mnt/shared/test_gail_tianshou.py", line 303, in trainable_function
test_gail(args)
File "/mnt/shared/test_gail_tianshou.py", line 107, in test_gail
train_envs = SubprocVectorEnv(
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/venvs.py", line 394, in init
super().init(env_fns, worker_fn, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/venvs.py", line 80, in init
self.workers = [worker_fn(fn) for fn in env_fns]
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/venvs.py", line 80, in
self.workers = [worker_fn(fn) for fn in env_fns]
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/venvs.py", line 392, in worker_fn
return SubprocEnvWorker(fn, share_memory=False)
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/worker/subproc.py", line 162, in init
super().init(env_fn)
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/worker/base.py", line 19, in init
self.action_space = self.get_env_attr("action_space") # noqa: B009
File "/opt/conda/lib/python3.8/site-packages/tianshou/env/worker/subproc.py", line 166, in get_env_attr
return self.parent_remote.recv()
File "/opt/conda/lib/python3.8/multiprocessing/connection.py", line 250, in recv
buf = self._recv_bytes()
File "/opt/conda/lib/python3.8/multiprocessing/connection.py", line 414, in _recv_bytes
buf = self._recv(4)
File "/opt/conda/lib/python3.8/multiprocessing/connection.py", line 379, in _recv
chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer

@YangyangFu
Copy link
Owner Author

@mingzhe37 I didn't. It seems this env SubprocVectorEnv not working. Maybe isolate the issue to debug?

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

No branches or pull requests

2 participants