Skip to main content

The NetHack Learning Environment (NLE): a reinforcement learning environment based on NetHack

Project description

NetHack Learning Environment (NLE)


Twitter

The NetHack Learning Environment (NLE) is a Reinforcement Learning environment originally presented at NeurIPS 2020. This version of NLE is based on NetHack 3.6.7 and designed to provide a standard RL interface to the game, and comes with tasks that function as a first step to evaluate agents on this new environment.

NetHack is one of the oldest and arguably most impactful videogames in history, as well as being one of the hardest roguelikes currently being played by humans. It is procedurally generated, rich in entities and dynamics, and overall an extremely challenging environment for current state-of-the-art RL agents, while being much cheaper to run compared to other challenging testbeds. Through NLE, we wish to establish NetHack as one of the next challenges for research in decision making and machine learning.

You can read more about NLE in the NeurIPS 2020 paper, and about NetHack in its original README, at nethack.org, and on the NetHack wiki.

Example of an agent running on NLE

This version of NLE uses the Farama Organisation Gymnasium Environment APIs.

Getting started

Starting with NLE environments is extremely simple, provided one is familiar with other gym (or Gynmasium) / RL environments.

Installation

NLE requires python>=3.8, cmake>=3.18 to be installed and available both when building the package, and at runtime.

On MacOS, one can use Homebrew as follows:

$ brew install cmake

On a plain Ubuntu 18.04 distribution, cmake and other dependencies can be installed by doing:

# Python and most build deps
$ sudo apt-get install -y build-essential autoconf libtool pkg-config \
    python3-dev python3-pip python3-numpy git flex bison libbz2-dev

# recent cmake version
$ wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
$ sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
$ sudo apt-get update && apt-get --allow-unauthenticated install -y \
    cmake \
    kitware-archive-keyring

Afterwards it's a matter of setting up your environment. We advise using a conda environment for this:

$ conda create -y -n nle python=3.8
$ conda activate nle
$ pip install nle

NOTE: If you want to extend / develop NLE, please install the package as follows:

$ git clone https://github.com/heiner/nle --recursive
$ pip install -e ".[dev]"
$ pre-commit install

Docker

We have provided some docker images. Please see the relevant README.

Trying it out

After installation, one can try out any of the provided tasks as follows:

>>> import gymnasium as gym
>>> import nle
>>> env = gym.make("NetHackScore-v0")
>>> env.reset()  # each reset generates a new dungeon
>>> env.step(1)  # move agent '@' north
>>> env.render()

NLE also comes with a few scripts that allow to get some environment rollouts, and play with the action space:

# Play NetHackStaircase-v0 as a human
$ python -m nle.scripts.play

# Use a random agent
$ python -m nle.scripts.play --mode random

# Play the full game using directly the NetHack internal interface
# (Useful for debugging outside of the gymnasium environment)
$ python -m nle.scripts.play --env NetHackScore-v0 # works with random agent too

# See all the options
$ python -m nle.scripts.play --help

Note that nle.scripts.play can also be run with nle-play, if the package has been properly installed.

Additionally, a TorchBeast agent is bundled in nle.agent together with a simple model to provide a starting point for experiments:

$ pip install "nle[agent]"
$ python -m nle.agent.agent --num_actors 80 --batch_size 32 --unroll_length 80 --learning_rate 0.0001 --entropy_cost 0.0001 --use_lstm --total_steps 1000000000

Plot the mean return over the last 100 episodes:

$ python -m nle.scripts.plot
                              averaged episode return

  140 +---------------------------------------------------------------------+
      |             +             +            ++-+ ++++++++++++++++++++++++|
      |             :             :          ++++++++||||||||||||||||||||||||
  120 |-+...........:.............:...+-+.++++|||||||||||||||||||||||||||||||
      |             :        +++++++++++++++||||||||||AAAAAAAAAAAAAAAAAAAAAA|
      |            +++++++++++++||||||||||||||AAAAAAAAAAAA|||||||||||||||||||
  100 |-+......+++++|+|||||||||||||||||||||||AA||||||||||||||||||||||||||||||
      |       +++|||||||||||||||AAAAAAAAAAAAAA|||||||||||+++++++++++++++++++|
      |    ++++|||||AAAAAAAAAAAAAA||||||||||||++++++++++++++-+:             |
   80 |-++++|||||AAAAAA|||||||||||||||||||||+++++-+...........:...........+-|
      | ++|||||AAA|||||||||||||||++++++++++++-+ :             :             |
   60 |++||AAAAA|||||+++++++++++++-+............:.............:...........+-|
      |++|AA||||++++++-|-+        :             :             :             |
      |+|AA|||+++-+ :             :             :             :             |
   40 |+|A+++++-+...:.............:.............:.............:...........+-|
      |+AA+-+       :             :             :             :             |
      |AA-+         :             :             :             :             |
   20 |AA-+.........:.............:.............:.............:...........+-|
      |++-+         :             :             :             :             |
      |+-+          :             :             :             :             |
    0 |-+...........:.............:.............:.............:...........+-|
      |+            :             :             :             :             |
      |+            +             +             +             +             |
  -20 +---------------------------------------------------------------------+
      0           2e+08         4e+08         6e+08         8e+08         1e+09
                                       steps

NLE Language Wrapper

We thank ngoodger for implementing the NLE Language Wrapper that translates the non-language observations from NetHack tasks into similar language representations. Actions can also be optionally provided in text form which are converted to the Discrete actions of the NLE.

NetHack Learning Dataset

The NetHack Learning Dataset (NLD) code now ships with NLE, allowing users to the load large-scale datasets featured in Dungeons and Data: A Large-Scale NetHack Dataset, while also generating and loading their own datasets.

import nle.dataset as nld

if not nld.db.exists():
    nld.db.create()
    # NB: Different methods are used for data based on NLE and data from NAO.
    nld.add_nledata_directory("/path/to/nld-aa", "nld-aa-v0")
    nld.add_altorg_directory("/path/to/nld-nao", "nld-nao-v0")

dataset = nld.TtyrecDataset("nld-aa-v0", batch_size=128, ...)
for i, mb in enumerate(dataset):
    foo(mb) # etc...

For information on how to download NLD-AA and NLD-NAO, see the dataset doc here.

Otherwise checkout the tutorial Colab notebook here.

Papers using the NetHack Learning Environment

Open a pull request to add papers.

Contributing

We welcome contributions to NLE. If you are interested in contributing please see this document.

Architecture

NLE is direct fork of NetHack and therefore contains code that operates on many different levels of abstraction. This ranges from low-level game logic, to the higher-level administration of repeated nethack games, and finally to binding of these games to Python gymnasium environment.

If you want to learn more about the architecture of nle and how it works under the hood, checkout the architecture document. This may be a useful starting point for anyone looking to contribute to the lower level elements of NLE.

Related Environments

Interview about the environment with Weights&Biases

Facebook AI Research’s Tim & Heiner on democratizing reinforcement learning research.

Interview with Weigths&Biases

Citation

If you use NLE in any of your work, please cite:

@inproceedings{kuettler2020nethack,
  author    = {Heinrich K{\"{u}}ttler and
               Nantas Nardelli and
               Alexander H. Miller and
               Roberta Raileanu and
               Marco Selvatici and
               Edward Grefenstette and
               Tim Rockt{\"{a}}schel},
  title     = {{The NetHack Learning Environment}},
  booktitle = {Proceedings of the Conference on Neural Information Processing Systems (NeurIPS)},
  year      = {2020},
}

If you use NLD or the datasets in any of your work, please cite:

@article{hambro2022dungeons,
  title={Dungeons and Data: A Large-Scale NetHack Dataset},
  author={Hambro, Eric and Raileanu, Roberta and Rothermel, Danielle and Mella, Vegard and Rockt{\"a}schel, Tim and K{\"u}ttler, Heinrich and Murray, Naila},
  journal={Advances in Neural Information Processing Systems},
  volume={35},
  pages={24864--24878},
  year={2022}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nle-1.2.0.tar.gz (7.4 MB view details)

Uploaded Source

Built Distributions

nle-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nle-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nle-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nle-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nle-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nle-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

nle-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

nle-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

nle-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

nle-1.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

Details for the file nle-1.2.0.tar.gz.

File metadata

  • Download URL: nle-1.2.0.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nle-1.2.0.tar.gz
Algorithm Hash digest
SHA256 3d033f8f8bc3dfa819886f620f0bc22aa6d09faa25d9aa1e0b09e047a1a9c450
MD5 49297a3311667364a124ca046683a2f7
BLAKE2b-256 65e7b1a358b46e0f293ff1575855b4a1ad35782dcf4a2aa2c3e4d721e1c26878

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0.tar.gz:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9afea4baf34a229fb30335537f91a1f5e973ac038b3ac4fe24028beacf928492
MD5 5152d78033a6030e73f750e0ea253098
BLAKE2b-256 758fe89e963cbfd75c07b09e987c334fef04a45a887f9b3ecb61135758415e1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4e200b20e7666ecc799e126b1d168a88764bc67ed7d6235f5f39b362f266e5d5
MD5 b26c735120e7dd57209035cb08879847
BLAKE2b-256 3bb18e87d1ef99978369e4b9b337ff1d6073cd7daeb2fba4ba28d898d4c33056

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca4b92773c21d02cced445f9bc9127e7548c24145fc5bc9b8eac467198f09955
MD5 f28fdbe8435b3971c2dbbff664857f1b
BLAKE2b-256 ede98c485441ea08ea4ef90d2a8d1a0e84143144f0be63a33cbc241fea66b650

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4a7315f9a262bbef7ed58502decad44ba5be18526427884b0d3aef49c407a94c
MD5 403af13ae1d17aa7ad8866259fd42154
BLAKE2b-256 97f9411362c99f18c7159c4d2ea5b9ec8c1c18a851e6eb9d669406aa9c5a9348

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bbc7bc2fc3b4f2769c25acab99603146222e3b2fd3a82a514a6d8542c985170
MD5 ce7b7fadf99d519cb8d6f6272b389b6c
BLAKE2b-256 720c7a601b66137d971f8d0f3c3cacb55a42e2d84591ab4d748935e27e269c06

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3be9946e988b444489e01daa353850870525fe8cad5c0d2115b49193432bdb75
MD5 9438a5725e1c4cc1c7f16229a6be560a
BLAKE2b-256 e76772f8c207a247ad199be03a6b3c2d16fdd1af9ed7b0b56241ee2ab6d8b45a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71a4845be78d76e40dfee905537456ab944be9b34446abf7908babed42464ca5
MD5 147c49ce5876b41f866b0fce074c9fab
BLAKE2b-256 397810ce08949fa17b63cf7bbe0953c40dee3e0ee47a0cc5e89f1f48ac142a00

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c73f8fc2580bc3f951ffbfe952b52223e380ae46105952c53b71c1456ecc50a2
MD5 80b142482c2b17bf5ed3780e04a1f2e1
BLAKE2b-256 6da1488ff2e901a96737a5f973bc0f903ea7c4d4937015671e9699ca9b74ef47

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a916f129aeb49b340fcb96c4933d2cfe90f14aca3a1efb4c23b692f3152d96b9
MD5 414563dd5dd8a3a51fd5e38f7184bfe6
BLAKE2b-256 e6045f78106a4f49f42d8367e34fe8f100a882b461b3ebf98e27ffa49fb076a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nle-1.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cb40e3fb9514ef91e736607575a2773dc81b2f84ec3930d4ca4f55104747cae6
MD5 05ed10b9c3759355d23d49a53b0cdb9a
BLAKE2b-256 402d6187278cb2cd74137b22f11e693f2056ee94bd39d59d7dff422eaa4698b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: test_and_deploy.yml on heiner/nle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page