Skip to content

Commit e79632b

Browse files
authored
Merge pull request #764 from Microsoft/prep37
Prep37
2 parents abc82d2 + 8b65204 commit e79632b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4179
-120
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 Microsoft Corporation
3+
Copyright (c) 2016, 2018 Microsoft Corporation
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
66
associated documentation files (the "Software"), to deal in the Software without restriction,

Malmo/samples/Python_examples/team_reward_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def safeStartMission(agent_host, my_mission, my_client_pool, my_mission_record,
7777
print("Will wait and retry.", max_attempts - used_attempts, "attempts left.")
7878
time.sleep(2)
7979
else:
80-
print("Other error:", e.message)
80+
print("Other error: ", str(e))
8181
print("Waiting will not help here - bailing immediately.")
8282
exit(1)
8383
if used_attempts == max_attempts:

MalmoEnv/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# MalmoEnv (Prototype) #
2+
3+
MalmoEnv is an OpenAI "gym" like Python Environment for Malmo/Minecraft, directly implemented Python to Java Minecraft.
4+
5+
A python "gym env" is created and used to run an agent in a Malmo mission. Each env has a remote Minecraft instance
6+
associated to it (by DNS name or IP and Port). For multi-agent missions, the first agent's (role 0) Minecraft
7+
client instance is used as a coordinator to allow all agents to rendezvous on mission starts (i.e. on env resets).
8+
9+
As it's python only, you just need this one package, its direct dependencies and (Java) Minecraft!
10+
11+
## Examples of use: ##
12+
13+
Install dependencies:
14+
15+
Java8 JDK, python3, git
16+
17+
`pip install gym lxml numpy pillow`
18+
19+
To prepare Minecraft (after cloning this repository with
20+
`git clone -b malmoenv https://github.com/Microsoft/malmo.git`):
21+
22+
`cd Minecraft`
23+
24+
`(echo -n "malmo.version=" && cat ../VERSION) > ./src/main/resources/version.properties`
25+
26+
Running a single agent example mission (run each command in different cmd prompt/shells):
27+
28+
`./launchClient.sh -port 9000 -env` or (On Windows) `launchClient.bat -port 9000 -env`
29+
30+
(In another shell) `cd MalmoEnv` optionally run `python3 setup.py install`
31+
32+
`python3 run.py --mission missions/mobchase_single_agent.xml --port 9000 --episodes 10`
33+
34+
A two agent example mission (run each command in different cmd prompt/shells):
35+
36+
`./launchClient.sh -port 9000 -env`
37+
38+
`./launchClient.sh -port 9001 -env`
39+
40+
In the two agent case, running each agent in it's own shell, the run script (for agents other than the first) is given two ports
41+
- the first for the mission coordinator and a second (port2) for the other agent's Minecraft:
42+
43+
`python3 run.py --mission missions/mobchase_two_agents.xml --port 9000 --role 0 --experimentUniqueId "test1"`
44+
45+
`python3 run.py --mission missions/mobchase_two_agents.xml --port 9000 --port2 9001 --role 1 --experimentUniqueId "test1"`
46+
47+
## Running multi-threaded multi-agent examples: ##
48+
49+
`python3 runmultiagent.py --mission missions/mobchase_two_agents.xml
50+
51+
## Installing with pip ##
52+
53+
If you install with `pip3 install malmoenv` then you can download the Minecraft mod
54+
(assuming you have git available from the command line) with:
55+
56+
`python3 -c "import malmoenv.bootstrap();malmoenv.bootstrap.download()`
57+
58+
The sample missions will be in ./MalmoPlatform/MalmoEnv/missions.
59+
60+
`malmoenv.bootstrap.launchMinecraft(9000)` can be used to start up the Malmo Minecraft Mod
61+
listening for MalmoEnv connections on port 9000 after downloading Malmo.
62+

MalmoEnv/malmoenv/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ------------------------------------------------------------------------------------------------
2+
# Copyright (c) 2018 Microsoft Corporation
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5+
# associated documentation files (the "Software"), to deal in the Software without restriction,
6+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
7+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all copies or
11+
# substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
# ------------------------------------------------------------------------------------------------
19+
20+
from malmoenv.core import ActionSpace, StringActionSpace, VisualObservationSpace, Env, make
21+
22+
__all__ = ['ActionSpace', 'StringActionSpace', 'VisualObservationSpace', 'Env', 'make']

MalmoEnv/malmoenv/bootstrap.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ------------------------------------------------------------------------------------------------
2+
# Copyright (c) 2018 Microsoft Corporation
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5+
# associated documentation files (the "Software"), to deal in the Software without restriction,
6+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
7+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all copies or
11+
# substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
# ------------------------------------------------------------------------------------------------
19+
import os
20+
import subprocess
21+
import pathlib
22+
23+
from malmoenv.version import malmo_version
24+
25+
26+
def download(branch=None, build=True, installdir="MalmoPlatform"):
27+
"""Download Malmo from github and build (by default) the Minecraft Mod.
28+
Example usage: import malmoenv.bootstrap; malmoenv.bootstrap.download()
29+
Args:
30+
branch: optional branch to clone. TODO Default is release version.
31+
build: build the Mod unless build arg is given as False.
32+
installdir: the install dir name. Defaults to MalmoPlatform.
33+
Returns:
34+
The path for the Malmo Minecraft mod.
35+
"""
36+
37+
if branch is None:
38+
branch = malmo_version
39+
40+
subprocess.check_call(["git", "clone", "-b", branch, "https://github.com/Microsoft/malmo.git", installdir])
41+
42+
return setup(build=build, installdir=installdir)
43+
44+
45+
def setup(build=True, installdir="MalmoPlatform"):
46+
"""Set up Minecraft for use with the MalmoEnv gym environment"""
47+
48+
gradlew = './gradlew'
49+
if os.name == 'nt':
50+
gradlew = 'gradlew.bat'
51+
52+
cwd = os.getcwd()
53+
os.chdir(installdir)
54+
os.chdir("Minecraft")
55+
try:
56+
# Create the version properties file.
57+
pathlib.Path("src/main/resources/version.properties").write_text("malmomod.version={}\n".format(malmo_version))
58+
# Optionally do a test build.
59+
if build:
60+
subprocess.check_call([gradlew, "setupDecompWorkspace", "build", "testClasses",
61+
"-x", "test", "--stacktrace", "-Pversion={}".format(malmo_version)])
62+
minecraft_dir = os.getcwd()
63+
finally:
64+
os.chdir(cwd)
65+
return minecraft_dir
66+
67+
68+
def launch_minecraft(port, installdir="MalmoPlatform", replaceable=False):
69+
"""Launch Minecraft listening for malmoenv connections.
70+
Args:
71+
port: the TCP port to listen on.
72+
installdir: the install dir name. Defaults to MalmoPlatform.
73+
Must be same as given (or defaulted) in download call if used.
74+
replaceable: whether or not to automatically restart Minecraft (default is false).
75+
"""
76+
launch_script = 'launchClient.sh'
77+
if os.name == 'nt':
78+
launch_script = 'launchClient.bat'
79+
cwd = os.getcwd()
80+
os.chdir(installdir)
81+
os.chdir("Minecraft")
82+
try:
83+
cmd = [launch_script, '-port', str(port), '-env']
84+
if replaceable:
85+
cmd.append('-replaceable')
86+
subprocess.check_call(cmd)
87+
finally:
88+
os.chdir(cwd)

0 commit comments

Comments
 (0)