Skip to main content

Gymnasium Mars Lander

pre-commit Ruff ty

Gymnasium environment for the Mars Lander CodinGame puzzles:

Demo

Action Space Box(-1, 1, (2,), float32)
Observation Space Box(-1, 1, (12,), float32)
Import gymnasium.make("gymnasium_mars_lander:gymnasium_mars_lander/MarsLander-v0")

This package is inspired by the article of Antoine Broyelle: Learning to Land on Mars with Reinforcement Learning.

Installation

To install gymnasium-mars-lander with pip, execute:

pip install gymnasium_mars_lander

From source:

git clone https://github.com/Quentin18/gymnasium-mars-lander
cd gymnasium-mars-lander/
pip install -e .

For running on CPU with extras:

pip install -e .[training,testing,quality] --extra-index-url https://download.pytorch.org/whl/cpu

Environment

Action Space

The action is a ndarray with two continuous variables:

  • The rotation change between -15 and 15 degrees.
  • The thrust change between -1 and 1.

The values are normalized between -1 and 1.

Observation Space

The observation is a ndarray of 12 continuous variables:

  • The distances in six directions from the current position.
  • The rower horizontal and vertical speed, angle and thrust.
  • The horizontal and vertical distances to the middle of the landing area.

The values are normalized between -1 and 1.

The following figure shows the sensors used:

Sensors

Rewards

The rewards are described by the following table:

Condition Reward
The rover leaves the frame -150
The rover runs out of fuel -150
The rover crashes outside flat ground with incorrect angle and speed -100
The rover crashes with correct angle and speed -75
The rover crashes on flat ground -50
The rover approaches the landing area 0.01
The rover lands successfully 200 + Amount of remaining propellant

Starting State

The starting state is generated by choosing a random CodinGame test case. When the eval_env argument is False, some random augmentations are applied to the test case. For each test case, there are five starting positions in increasing order of difficulty. The starting position can be set with the start argument.

The following figure shows the starting positions:

Starts

Episode End

The episode ends if either of the following happens:

  1. Termination: The rower lands on the landing area or runs out of fuel or crashes.
  2. Truncation: Episode length is greater than 2000.

Arguments

  • episode: episode number between 1 and 3. The default value is 2.
  • start: starting position between -1 and 4. The default value is -1.
  • eval_env: if True, the random augmentations are disabled. The default value is False.
  • sequential_maps: if True, the maps are generated sequentially. The default value is False.
import gymnasium as gym

gym.make(
    "gymnasium_mars_lander:gymnasium_mars_lander/MarsLander-v0",
    episode=2,
    start=-1,
    eval_env=False,
    sequential_maps=False,
)

Trained agents

There is one trained agent for each episode:

Path Episode
rl-trained-agents/ppo/gymnasium_mars_lander-MarsLander-v0_1/best_model.zip 1
rl-trained-agents/ppo/gymnasium_mars_lander-MarsLander-v0_2/best_model.zip 2

Usage

You can use RL Baselines3 Zoo to train and evaluate agents:

pip install rl_zoo3

Train an Agent

The hyperparameters are defined in hyperparams/ppo.yml.

To train a PPO agent for the Mars Lander game, execute:

python -m rl_zoo3.train \
  --algo ppo \
  --env gymnasium_mars_lander/MarsLander-v0 \
  --tensorboard-log logs \
  --trained-agent rl-trained-agents/ppo/gymnasium_mars_lander-MarsLander-v0_2/best_model.zip \
  --n-timesteps 10000000 \
  --log-interval 100 \
  --eval-freq 10000 \
  --eval-episodes 100 \
  --seed 42 \
  --gym-packages gymnasium_mars_lander \
  --conf-file hyperparams/ppo.yml \
  --progress \
  --env-kwargs "episode:int(2)" "start:int(-1)" "sequential_maps:True"

Enjoy a Trained Agent

To see a trained agent in action on random test cases, execute:

python -m rl_zoo3.enjoy \
  --algo ppo \
  --env gymnasium_mars_lander/MarsLander-v0 \
  --n-timesteps 1000 \
  --deterministic \
  --seed 42 \
  --gym-packages gymnasium_mars_lander \
  --load-best \
  --progress \
  --env-kwargs "episode:int(2)" "start:int(-1)" "sequential_maps:True"

To see a trained agent in action on CodinGame test cases, execute:

python -m scripts.enjoy --path rl-trained-agents/ppo/gymnasium_mars_lander-MarsLander-v0_2/best_model.zip

To record videos of a trained agent in action on CodinGame test cases, execute:

python -m scripts.enjoy \
  --path rl-trained-agents/ppo/gymnasium_mars_lander-MarsLander-v0_2/best_model.zip \
  --record-video

Tests

To run tests, execute:

pytest

Citing

To cite the repository in publications:

@misc{gymnasium-mars-lander,
  author = {Quentin Deschamps},
  title = {Gymnasium Mars Lander},
  year = {2026},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/Quentin18/gymnasium-mars-lander}},
}

References

Author

Quentin Deschamps

Download files

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

Source Distribution

gymnasium_mars_lander-1.0.0.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

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

gymnasium_mars_lander-1.0.0-py3-none-any.whl (57.0 kB view details)

Uploaded Python 3

File details

Details for the file gymnasium_mars_lander-1.0.0.tar.gz.

File metadata

  • Download URL: gymnasium_mars_lander-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gymnasium_mars_lander-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6a270998060166dfd73c780b7c8bef41796f8045ce6b24da20d4d11851fa9357
MD5 eb06b88e87a8d6816afa04c24c428a5c
BLAKE2b-256 80a638a740160fa36cde5c1aa7d2cd50a4f8bbfad5195724eaed17e8badd56b3

See more details on using hashes here.

File details

Details for the file gymnasium_mars_lander-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gymnasium_mars_lander-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35b3284fb18830c95e1959f962822a69ac9ff64e130b05bc419a3362b6b3ab0f
MD5 ff8d748ffb7a8e894ad0fa5dc0bd2add
BLAKE2b-256 1e006a1db93a7c3aca67057999248405f4b82538c8d3026819d2cd630581b20e

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.0

2 files

2.0.0

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page