Skip to content

Commit

Permalink
- fixed marlene_server.py
Browse files Browse the repository at this point in the history
- changed _reward and _is_terminal observer names to actual observer types
  • Loading branch information
sven1977 committed Jan 18, 2018
1 parent b82d45c commit d31f3d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
26 changes: 13 additions & 13 deletions Plugins/MaRLEnE/Scripts/server_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
-------------------------------------------------------------------------
engine2learn - server_utils.py
MaRLEnE - server_utils.py
Utility functions for the server-side environment script.
Expand All @@ -10,7 +10,7 @@
"""

import unreal_engine as ue
from unreal_engine.classes import E2LObserver, GameplayStatics, CameraComponent, InputSettings, SceneCaptureComponent2D
from unreal_engine.classes import MLObserver, GameplayStatics, CameraComponent, InputSettings, SceneCaptureComponent2D
import numpy as np
import re

Expand Down Expand Up @@ -110,7 +110,7 @@ def get_scene_capture_and_texture(parent, obs_name, width=84, height=84):
if scene_capture:
texture = scene_capture.TextureTarget
else:
scene_capture = parent.get_owner().add_actor_component(SceneCaptureComponent2D, "Engine2LearnScreenCapture", parent)
scene_capture = parent.get_owner().add_actor_component(SceneCaptureComponent2D, "MaRLEnEScreenCapture", parent)
scene_capture.bCaptureEveryFrame = False
scene_capture.bCaptureOnMovement = False
# error -> return nothing
Expand Down Expand Up @@ -147,7 +147,7 @@ def get_scene_capture_image(scene_capture, texture):

def compile_obs_dict(reward=None):
"""
Compiles the current observations (based on all active E2LObservers) into a dictionary that is returned to the
Compiles the current observations (based on all active MLObservers) into a dictionary that is returned to the
UE4Env object's reset/step/... methods.
:param Union[float,None] reward: The absolute global accumulated reward value to set (mostly used to reset
Expand All @@ -158,7 +158,7 @@ def compile_obs_dict(reward=None):
global _REWARD

playing_world = get_playing_world()
r = 0.0
r = 0.0 # accumulated reward
is_terminal = False
if reward is not None:
_REWARD = reward
Expand All @@ -167,28 +167,28 @@ def compile_obs_dict(reward=None):
#pydevd.settrace("localhost", port=20023, stdoutToServer=True, stderrToServer=True) # DEBUG
# END: DEBUG

for observer in E2LObserver.GetRegisteredObservers():
for observer in MLOserver.GetRegisteredObservers():
parent, obs_name = sanity_check_observer(observer, playing_world)
if not parent:
continue
# the reward observer
elif obs_name == "_reward":
elif observer.ObserverType == 1:
if len(observer.ObservedProperties) != 1:
return {"status": "error", "message": "Reward-observer {} has 0 or more than 1 property!".format(obs_name)}
observed_prop = observer.ObservedProperties[0]
prop_name = observed_prop.PropName
if not parent.has_property(prop_name):
return {"status": "error", "message": "Reward-property {} is not a property of parent ({})!".format(prop_name, parent)}
r = parent.get_property(prop_name)[0] # FOR NOW: use x-Location as reward (bad, but we need 20tab to add this functionality)
r = parent.get_property(prop_name)[0] # FOR NOW: use x-Location as accumulated reward (bad, but we need 20tab to add this functionality)
# the is_terminal observer
elif obs_name == "_is_terminal":
elif observer.ObserverType == 2:
if len(observer.ObservedProperties) != 1:
return {"status": "error", "message": "IsTerminal-observer {} has 0 or more than 1 property!".format(obs_name)}
observed_prop = observer.ObservedProperties[0]
prop_name = observed_prop.PropName
if not parent.has_property(prop_name):
return {"status": "error", "message": "IsTerminal-property {} is not a property of parent ({})!".format(prop_name, parent)}
is_terminal = (parent.get_property(prop_name)[0] > 0.0) # FOR NOW: use Rotation: x > 0 as is_terminal signal
is_terminal = (parent.get_property(prop_name)[0] > 0.0) # FOR NOW: use x-Location: x == 1.0? as is_terminal signal
# normal (non-reward/non-is_terminal) observer
else:
# this observer returns a camera image
Expand Down Expand Up @@ -222,7 +222,7 @@ def compile_obs_dict(reward=None):

# update global total reward counter
prev_reward = _REWARD
_REWARD = r
_REWARD = r # update global _REWARD counter
message = {"status": "ok", "obs_dict": _OBS_DICT, "_reward": (r - prev_reward), "_is_terminal": is_terminal}
return message

Expand Down Expand Up @@ -262,10 +262,10 @@ def get_spec():

# build the observation_space descriptor
observation_space_desc = {}
for observer in E2LObserver.GetRegisteredObservers():
for observer in MLObserver.GetRegisteredObservers():
parent, obs_name = sanity_check_observer(observer, playing_world)
# ignore reward observer and is-terminal observer
if not parent or obs_name == "_reward" or obs_name == "_is_terminal":
if not parent or observer.ObserverType > 0: # reward or is_terminal Observer
continue

# ue.log("DEBUG: get_spec observer {}".format(obs_name))
Expand Down
2 changes: 1 addition & 1 deletion bootstrap-builder.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
add-apt-repository -y universe
apt update
sudo apt install git sudo shared-mime-info tzdata build-essential mono-mcs mono-devel mono-xbuild mono-dmcs mono-reference-assemblies-4.0 libmono-system-data-datasetextensions4.0-cil libmono-system-web-extensions4.0-cil libmono-system-management4.0-cil libmono-system-xml-linq4.0-cil cmake dos2unix clang-3.8 libfreetype6-dev libgtk-3-dev libmono-microsoft-build-tasks-v4.0-4.0-cil xdg-user-dirs -y
sudo apt install git sudo shared-mime-info python3 python3-dev tzdata build-essential mono-mcs mono-devel mono-xbuild mono-dmcs mono-reference-assemblies-4.0 libmono-system-data-datasetextensions4.0-cil libmono-system-web-extensions4.0-cil libmono-system-management4.0-cil libmono-system-xml-linq4.0-cil cmake dos2unix clang-3.8 libfreetype6-dev libgtk-3-dev libmono-microsoft-build-tasks-v4.0-4.0-cil xdg-user-dirs -y
cd /vagrant/UnrealEngine

# clone project from github into a (new or empty) directory
Expand Down
4 changes: 3 additions & 1 deletion bootstrap-unreal.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env bash

# start the cooked game without display (-NullRHI) and without sound (-nosound)

echo "
[Unit]
Description=$1 Service
[Service]
ExecStart=/vagrant/$1/Build/LinuxNoEditor/$1.sh -NullRHI
ExecStart=/vagrant/$1/Build/LinuxNoEditor/$1.sh -NullRHI -nosound
RestartSec=5s
Restart=always
User=ubuntu
Expand Down

0 comments on commit d31f3d9

Please sign in to comment.