-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (40 loc) · 1.51 KB
/
server.py
File metadata and controls
49 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# import wrapper
import rpyc
from gymnasium import Wrapper
from rpyc.utils.server import ThreadedServer
rpyc.core.protocol.DEFAULT_CONFIG["allow_pickle"] = True
@rpyc.service
class RcsServer(Wrapper, rpyc.Service):
def __init__(self, env, host="localhost", port=50051):
super().__init__(env)
self.host = host
self.port = port
@rpyc.exposed
def step(self, action):
"""Perform a step in the environment using the Wrapper base class."""
return super().step(action)
@rpyc.exposed
def reset(self, **kwargs):
"""Reset the environment using the Wrapper base class."""
return super().reset(**kwargs)
@rpyc.exposed
def get_obs(self):
"""Get the current observation using the Wrapper base class if available."""
if hasattr(super(), "get_obs"):
return super().get_obs()
if hasattr(self.env, "get_obs"):
return self.env.get_obs()
error = "The environment does not have a get_obs method."
raise NotImplementedError(error)
@rpyc.exposed
def unwrapped(self):
"""Return the unwrapped environment using the Wrapper base class."""
return super().unwrapped
@rpyc.exposed
def action_space(self):
"""Return the action space using the Wrapper base class."""
return super().action_space
def start(self):
print(f"Starting RcsServer RPC (looped OneShotServer) on {self.host}:{self.port}")
t = ThreadedServer(self, port=self.port)
t.start()