Fix action_space setup

This commit is contained in:
Timothyxxx
2023-12-06 22:59:19 +08:00
parent b9c317f0f5
commit 343b40ecac
3 changed files with 68 additions and 236 deletions

View File

@@ -21,6 +21,8 @@ class SetupController:
# can add other setup steps
def _download_setup(self, config):
if not config:
return
if not 'download' in config:
return
for url, path in config['download']:
@@ -43,6 +45,8 @@ class SetupController:
print("An error occurred while trying to send the request:", e)
def _change_wallpaper(self, config):
if not config:
return
if not 'wallpaper' in config:
return
path = config['wallpaper']
@@ -68,6 +72,8 @@ class SetupController:
raise NotImplementedError
def _open_setup(self, config):
if not config:
return
if not 'open' in config:
return
for path in config['open']:

View File

@@ -4,19 +4,25 @@ import os
import subprocess
import time
import uuid
import platform
from typing import List
import gymnasium as gym
from desktop_env.controllers.python import PythonController
from desktop_env.controllers.setup import SetupController
def _execute_command(command: List[str]) -> None:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=60, text=True)
if result.returncode != 0:
raise Exception("\033[91m" + result.stdout + result.stderr + "\033[0m")
return result.stdout
if command[:4] == ["vmrun", "-T", "ws", "start"]:
p = subprocess.Popen(command)
p.wait()
else:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=60, text=True)
if result.returncode != 0:
raise Exception("\033[91m" + result.stdout + result.stderr + "\033[0m")
return result.stdout
class DesktopEnv(gym.Env):
@@ -27,7 +33,7 @@ class DesktopEnv(gym.Env):
path_to_vm: str,
snapshot_path: str = "base",
config: dict = None,
action_space: str = "pyautogui",
action_space: str = "computer_13",
):
# Initialize environment variables
self.path_to_vm = path_to_vm
@@ -111,6 +117,7 @@ class DesktopEnv(gym.Env):
return observation
def step(self, action, pause=0.5):
# fixme: add reminding logic here, decide if the action is valid for the current action_space
if self.action_space == "computer_13":
# the set of all possible actions defined in the action representation
self.controller.execute_action(action)