minerl.env

The minerl.env package provides an optimized python software layer over MineRLEnv, a fork of the popular Minecraft simulator Malmo which enables synchronous, stable, and fast samples from the Minecraft environment.

MineRLEnv

class minerl.env.core.MineRLEnv(xml, observation_space, action_space, port=None, noop_action=None, docstr=None)

Bases: gym.core.Env

The MineRLEnv class.

Example

To actually create a MineRLEnv. Use any one of the package MineRL environments (Todo: Link.) literal blocks:

import minerl
import gym

env = gym.make('MineRLTreechop-v0') # Makes a minerl environment.

# Use env like any other OpenAI gym environment.
# ...
Parameters
  • xml (str) – The path to the MissionXML file for this environment.

  • observation_space (gym.Space) – The observation for the environment.

  • action_space (gym.Space) – The action space for the environment.

  • port (int, optional) – The port of an exisitng Malmo environment. Defaults to None.

  • noop_action (Any, optional) – The no-op action for the environment. This must be in the action_space. Defaults to None.

STEP_OPTIONS = 0
close()

gym api close

init()

Initializes the MineRL Environment.

Note

This is called automatically when the environment is made.

Parameters
  • observation_space (gym.Space) – The observation for the environment.

  • action_space (gym.Space) – The action space for the environment.

  • port (int, optional) – The port of an exisitng Malmo environment. Defaults to None.

Raises
  • EnvException – If the Mission XML is malformed this is thrown.

  • ValueError – The space specified for this environment does not have a default action.

  • NotImplementedError – When multiagent environments are attempted to be used.

is_closed()
metadata = {'render.modes': ['rgb_array', 'human']}
noop_action()

Gets the no-op action for the environment.

In addition one can get the no-op/default action directly from the action space.

env.action_space.noop()

Returns

A no-op action in the env’s space.

Return type

Any

reinit()

Use carefully to reset the episode count to 0.

render(mode='human')

Renders the environment.

The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:

  • human: render to the current display or terminal and return nothing. Usually for human consumption.

  • rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.

  • ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).

Note

Make sure that your class’s metadata ‘render.modes’ key includes

the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.

Parameters

mode (str) – the mode to render with

Example:

class MyEnv(Env):

metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}

def render(self, mode=’human’):
if mode == ‘rgb_array’:

return np.array(…) # return RGB frame suitable for video

elif mode == ‘human’:

… # pop up a window and render

else:

super(MyEnv, self).render(mode=mode) # just raise an exception

reset()

Resets the state of the environment and returns an initial observation.

Returns

the initial observation.

Return type

observation (object)

seed(seed=None)

Seeds the environment!

Note: THIS MUST BE CALLED BEFORE env.reset()

Parameters

seed (long, optional) – Defaults to None.

status()

Get status from server. head - Ping the the head node if True.

step(action)

Run one timestep of the environment’s dynamics. When end of episode is reached, you are responsible for calling reset() to reset this environment’s state.

Accepts an action and returns a tuple (observation, reward, done, info).

Parameters

action (object) – an action provided by the agent

Returns

agent’s observation of the current environment reward (float) : amount of reward returned after previous action done (bool): whether the episode has ended, in which case further step() calls will return undefined results info (dict): contains auxiliary diagnostic information (helpful for debugging, and sometimes learning)

Return type

observation (object)

InstanceManager

class minerl.env.malmo.CustomAsyncRemoteMethod(proxy, name, max_retries)

Bases: Pyro4.core._AsyncRemoteMethod

minerl.env.malmo.INSTANCE_MANAGER_PYRO = 'minerl.instance_manager'
class minerl.env.malmo.InstanceManager

Bases: object

The Minecraft instance manager library. The instance manager can be used to allocate and safely terminate existing Malmo instances for training agents.

Note: This object never needs to be explicitly invoked by the user of the MineRL library as the creation of one of the several MineRL environments will automatically query the InstanceManager to create a new instance.

Note: In future versions of MineRL the instance manager will become its own daemon process which provides instance allocation capability using remote procedure calls.

DEFAULT_IP = 'localhost'
class Instance(port=None, existing=False, status_dir=None, seed=None)

Bases: object

A subprocess wrapper which maintains a reference to a minecraft subprocess and also allows for stable closing and launching of such subprocesses across different platforms.

The Minecraft instance class works by launching two subprocesses: the Malmo subprocess, and a watcher subprocess with access to the process IDs of both the parent process and the Malmo subprocess. If the parent process dies, it will kill the subprocess, and then itself.

This scheme has a single failure point of the process dying before the watcher process is launched.

MAX_PIPE_LENGTH = 500
close()

Closes the object.

get_output()
property host
kill()

Kills the process (if it has been launched.)

launch()
property port
release_lock()
property status_dir
KEEP_ALIVE_PYRO_FREQUENCY = 5
MAXINSTANCES = None
MINECRAFT_DIR = '/home/wguss/.local/lib/python3.6/site-packages/minerl/env/Malmo/Minecraft'
REMOTE = False
SCHEMAS_DIR = '/home/wguss/.local/lib/python3.6/site-packages/minerl/env/Malmo/Schemas'
STATUS_DIR = '/home/wguss/.local/bin/performance'
X11_DIR = '/tmp/.X11-unix'
classmethod add_existing_instance(port)
classmethod add_keep_alive(_pid, _callback)
classmethod allocate_pool(num)
classmethod configure_malmo_base_port(malmo_base_port)

Configure the lowest or base port for Malmo

classmethod get_instance(pid)

Gets an instance from the instance manager. This method is a context manager and therefore when the context is entered the method yields a InstanceManager.Instance object which contains the allocated port and host for the given instance that was created.

Yields

The allocated InstanceManager.Instance object.

Raises
  • RuntimeError – No available instances or the maximum number of allocated instances reached.

  • RuntimeError – No available instances and automatic allocation of instances is off.

headless = False
classmethod is_remote()
managed = True
ninstances = 0
classmethod shutdown()
minerl.env.malmo.MAXRAND = 1000000
minerl.env.malmo.MINERL_INSTANCE_MANAGER_REMOTE = 'MINERL_INSTANCE_MANAGER_REMOTE'
class minerl.env.malmo.SeedType

Bases: enum.Enum

The seed type for an instance manager.

Values:

0 - NONE: No seeding whatsoever. 1 - CONSTANT: All envrionments have the same seed (the one specified

to the instance manager)

2 - GENERATED: All environments have different seeds generated from a single

random generator with the seed specified to the InstanceManager.

CONSTANT = 1
GENERATED = 2
NONE = 0
minerl.env.malmo.launch_instance_manager()

Defines the entry point for the remote procedure call server.

minerl.env.malmo.launch_queue_logger_thread(output_producer, should_end)
minerl.env.malmo.logger = <Logger minerl.env.malmo (WARNING)>
minerl.env.malmo.malmo_version = '0.37.0'