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._singleagent._SingleAgentEnv(*args, **kwargs)
Bases:
_MultiAgentEnv
The single agent version of the MineRLEnv.
THIS CLASS SHOULD NOT BE INSTANTIATED DIRECTLY USE ENV SPEC.
- 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() Dict[str, Any]
Reset the environment.
Sets-up the Env from its specification (called everytime the env is reset.)
- Returns
The first observation of the environment.
- step(single_agent_action: Dict[str, Any]) Tuple[Dict[str, Any], float, bool, Dict[str, Any]]
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:
_AsyncRemoteMethod
- 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'
- KEEP_ALIVE_PYRO_FREQUENCY = 5
- MAXINSTANCES = None
- MINECRAFT_DIR = '/home/docs/checkouts/readthedocs.org/user_builds/minerl/envs/v0.4.4/lib/python3.7/site-packages/minerl/env/../Malmo/Minecraft'
- REMOTE = False
- SCHEMAS_DIR = '/home/docs/checkouts/readthedocs.org/user_builds/minerl/envs/v0.4.4/lib/python3.7/site-packages/minerl/env/../Malmo/Schemas'
- STATUS_DIR = '/home/docs/checkouts/readthedocs.org/user_builds/minerl/envs/v0.4.4/lib/python3.7/site-packages/sphinx/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, instance_id=None)
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 set_valid_jdwp_port_for_instance(instance) None
Find a valid port for JDWP (Java Debug Wire Protocol), so that the instance can be debugged with an attached debugger. The port is set in the instance, so that other instances can check whether the port is reserved. :param instance: Instance to find and port for, and where we will set the jdwp port.
- classmethod shutdown()
- class minerl.env.malmo.MinecraftInstance(port=None, existing=False, status_dir=None, seed=None, instance_id=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
- property actor_name
- property client_socket
- client_socket_close()
- client_socket_recv_message()
- client_socket_send_message(msg)
- client_socket_shutdown(param)
- close()
Closes the object.
- create_multiagent_instance_socket(socktime)
- get_output()
- property had_to_clean
- has_client_socket()
- property host
- property jdwp_port
JDWP (Java Debug Wire Protocol) port, if any, so the instance can be debugged with an attached debugger.
- kill()
Kills the process (if it has been launched.)
- launch(daemonize=False, replaceable=True)
- property port
- release_lock()
- property status_dir
- class minerl.env.malmo.SeedType(value)
Bases:
IntEnum
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) (or alist of seeds , separated)
- 2 - GENERATED: All environments have different seeds generated from a single
random generator with the seed specified to the InstanceManager.
- 3 - SPECIFIED: Each instance is given a list of seeds. Specify this like
1,2,3,4;848,432,643;888,888,888 Each instance’s seed list is separated by ; and each seed is separated by ,
- CONSTANT = 1
- GENERATED = 2
- NONE = 0
- SPECIFIED = 3
- classmethod get_index(type)
- 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)