-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #764 from Microsoft/prep37
Prep37
- Loading branch information
Showing
48 changed files
with
4,179 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# MalmoEnv (Prototype) # | ||
|
||
MalmoEnv is an OpenAI "gym" like Python Environment for Malmo/Minecraft, directly implemented Python to Java Minecraft. | ||
|
||
A python "gym env" is created and used to run an agent in a Malmo mission. Each env has a remote Minecraft instance | ||
associated to it (by DNS name or IP and Port). For multi-agent missions, the first agent's (role 0) Minecraft | ||
client instance is used as a coordinator to allow all agents to rendezvous on mission starts (i.e. on env resets). | ||
|
||
As it's python only, you just need this one package, its direct dependencies and (Java) Minecraft! | ||
|
||
## Examples of use: ## | ||
|
||
Install dependencies: | ||
|
||
Java8 JDK, python3, git | ||
|
||
`pip install gym lxml numpy pillow` | ||
|
||
To prepare Minecraft (after cloning this repository with | ||
`git clone -b malmoenv https://github.com/Microsoft/malmo.git`): | ||
|
||
`cd Minecraft` | ||
|
||
`(echo -n "malmo.version=" && cat ../VERSION) > ./src/main/resources/version.properties` | ||
|
||
Running a single agent example mission (run each command in different cmd prompt/shells): | ||
|
||
`./launchClient.sh -port 9000 -env` or (On Windows) `launchClient.bat -port 9000 -env` | ||
|
||
(In another shell) `cd MalmoEnv` optionally run `python3 setup.py install` | ||
|
||
`python3 run.py --mission missions/mobchase_single_agent.xml --port 9000 --episodes 10` | ||
|
||
A two agent example mission (run each command in different cmd prompt/shells): | ||
|
||
`./launchClient.sh -port 9000 -env` | ||
|
||
`./launchClient.sh -port 9001 -env` | ||
|
||
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 | ||
- the first for the mission coordinator and a second (port2) for the other agent's Minecraft: | ||
|
||
`python3 run.py --mission missions/mobchase_two_agents.xml --port 9000 --role 0 --experimentUniqueId "test1"` | ||
|
||
`python3 run.py --mission missions/mobchase_two_agents.xml --port 9000 --port2 9001 --role 1 --experimentUniqueId "test1"` | ||
|
||
## Running multi-threaded multi-agent examples: ## | ||
|
||
`python3 runmultiagent.py --mission missions/mobchase_two_agents.xml | ||
|
||
## Installing with pip ## | ||
|
||
If you install with `pip3 install malmoenv` then you can download the Minecraft mod | ||
(assuming you have git available from the command line) with: | ||
|
||
`python3 -c "import malmoenv.bootstrap();malmoenv.bootstrap.download()` | ||
|
||
The sample missions will be in ./MalmoPlatform/MalmoEnv/missions. | ||
|
||
`malmoenv.bootstrap.launchMinecraft(9000)` can be used to start up the Malmo Minecraft Mod | ||
listening for MalmoEnv connections on port 9000 after downloading Malmo. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# ------------------------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 Microsoft Corporation | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
# associated documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies or | ||
# substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# ------------------------------------------------------------------------------------------------ | ||
|
||
from malmoenv.core import ActionSpace, StringActionSpace, VisualObservationSpace, Env, make | ||
|
||
__all__ = ['ActionSpace', 'StringActionSpace', 'VisualObservationSpace', 'Env', 'make'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# ------------------------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 Microsoft Corporation | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
# associated documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies or | ||
# substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# ------------------------------------------------------------------------------------------------ | ||
import os | ||
import subprocess | ||
import pathlib | ||
|
||
from malmoenv.version import malmo_version | ||
|
||
|
||
def download(branch=None, build=True, installdir="MalmoPlatform"): | ||
"""Download Malmo from github and build (by default) the Minecraft Mod. | ||
Example usage: import malmoenv.bootstrap; malmoenv.bootstrap.download() | ||
Args: | ||
branch: optional branch to clone. TODO Default is release version. | ||
build: build the Mod unless build arg is given as False. | ||
installdir: the install dir name. Defaults to MalmoPlatform. | ||
Returns: | ||
The path for the Malmo Minecraft mod. | ||
""" | ||
|
||
if branch is None: | ||
branch = malmo_version | ||
|
||
subprocess.check_call(["git", "clone", "-b", branch, "https://github.com/Microsoft/malmo.git", installdir]) | ||
|
||
return setup(build=build, installdir=installdir) | ||
|
||
|
||
def setup(build=True, installdir="MalmoPlatform"): | ||
"""Set up Minecraft for use with the MalmoEnv gym environment""" | ||
|
||
gradlew = './gradlew' | ||
if os.name == 'nt': | ||
gradlew = 'gradlew.bat' | ||
|
||
cwd = os.getcwd() | ||
os.chdir(installdir) | ||
os.chdir("Minecraft") | ||
try: | ||
# Create the version properties file. | ||
pathlib.Path("src/main/resources/version.properties").write_text("malmomod.version={}\n".format(malmo_version)) | ||
# Optionally do a test build. | ||
if build: | ||
subprocess.check_call([gradlew, "setupDecompWorkspace", "build", "testClasses", | ||
"-x", "test", "--stacktrace", "-Pversion={}".format(malmo_version)]) | ||
minecraft_dir = os.getcwd() | ||
finally: | ||
os.chdir(cwd) | ||
return minecraft_dir | ||
|
||
|
||
def launch_minecraft(port, installdir="MalmoPlatform", replaceable=False): | ||
"""Launch Minecraft listening for malmoenv connections. | ||
Args: | ||
port: the TCP port to listen on. | ||
installdir: the install dir name. Defaults to MalmoPlatform. | ||
Must be same as given (or defaulted) in download call if used. | ||
replaceable: whether or not to automatically restart Minecraft (default is false). | ||
""" | ||
launch_script = 'launchClient.sh' | ||
if os.name == 'nt': | ||
launch_script = 'launchClient.bat' | ||
cwd = os.getcwd() | ||
os.chdir(installdir) | ||
os.chdir("Minecraft") | ||
try: | ||
cmd = [launch_script, '-port', str(port), '-env'] | ||
if replaceable: | ||
cmd.append('-replaceable') | ||
subprocess.check_call(cmd) | ||
finally: | ||
os.chdir(cwd) |
Oops, something went wrong.