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.10, cmake>=3.28 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.10
$ 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/NetHack-LE/nle
$ 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.3.0.tar.gz (7.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nle-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nle-1.3.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nle-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nle-1.3.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nle-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nle-1.3.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

nle-1.3.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nle-1.3.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for nle-1.3.0.tar.gz
Algorithm Hash digest
SHA256 598871072652861541a1c1e56caf51851f311b062d7830d9ebf452119e53205d
MD5 1306f389693a27606c2db7a4be34ac15
BLAKE2b-256 2a36b8d5e7e394640a1d7aed2110b7911b3574f902158dadf04f1042f5f13ee5

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 20dc0ede2673ed0dd9a75195c784270f17c92a1ba83478c04a9d6d64c574774b
MD5 06b0f2a7882be365b4b7b92b9d9c3157
BLAKE2b-256 25b02c9e361dab02d1a9fe3e95f2ef541e1d8f80bce0eccd85b4b77a7b79754f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d59cf5795240d1e74a46141678fdf0a38e50e916bc9f0bc32eef6773df69a13a
MD5 00e8458b8a5db9c7356d8e777c623a03
BLAKE2b-256 0d9df4024f6c372fe807292fc7b78120cd182590c50f6fa43e4c7890aea436d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for nle-1.3.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a61797c4f37876c71b75dfd1462bbcdc5aba6dfd8f8357dce15e8a38a09430d1
MD5 af1bd3a0862880597306296cfa21ce9c
BLAKE2b-256 ff18e5a88a724297854510ea8df7d9e0de773b2cac78483bf2b922714fdb6bfb

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 0a69e54ff0758fd3a54d5233fec79b5a50a90a5d37c92991c25f9cdcc597f2c4
MD5 5417249cff4fc5442659668836c8c3a9
BLAKE2b-256 9bb1a58816b878a1837005a66bfed2673520f09849e097decad74f9eda2605d0

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 68b151d2b114f44dd4b8bf044bcb73e6f7e4e9e7e7a93c4a8310792a91967b8f
MD5 ece9aacbc0b04236f415dbe6b661a27f
BLAKE2b-256 58a009cc7289adf92db627acdc6fc3835a095f0f8bebfc56daa0673956c883ff

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 b2e4b705e822ca305da6314e93522031e01c094f6736ff46e90e5e7c0c9442e8
MD5 e1fdd2bdc6ddc29b96a34feeacf4ca9b
BLAKE2b-256 ae43bb1e9da4b02c822174b02501656be8938ada859ab564b572a57dae020b76

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 230966ad159ca8717ac77942d4cb0ca96b22058cb1d77715fc16608b9abf297c
MD5 df7b59d3763f037d8001baf30920b213
BLAKE2b-256 8140a76de664abc1992c208e81db6b96e7cec2fe464741551e2101852915f3cc

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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.3.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for nle-1.3.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 18849572f51f5ee9ad78a7c0518d4bf1736b66d8c0b451b958c2014bbd05a243
MD5 03bcf91e76b9fe029f5a42fcae416ecc
BLAKE2b-256 d10f3925407a5db42bac938ffc3ab93977f7149d1ef67bb9315eddf6050cee26

See more details on using hashes here.

Provenance

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

Publisher: test_and_deploy.yml on NetHack-LE/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 Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page