Skip to main content

A Sudoku environment for Reinforcement Learning research

Project description

pip install gymnasium_sudoku

Observation space : The state returned after each .reset() or .step() is a raw sudoku board shape [9,9].This observation can be converted into an image.

Action space: The action space is shaped [x,y,z],representing : x = row position of the cell, y = column position of the cell and value that should go into that cell.When vectorizing, the current version of the environment do not handle action reshaping, so for n environments, the action's shape should be : [[x0...xn],[y0...yn],[z0...zn]]

Horizon: This parameter controls the number of steps after which Truncated is set to True and the environment is reset. Otherwise, early in training (when the policy is still mostly random and the exploration incentive is high), the policy may corrupt the board and either make it unsolvable or push it into a local minimum. The default value for this parameter is set to 400 for no specific reason and should probably be adjusted during initialization.

Eval mode/Training mode : By default, eval_mode in the init method is set to False. This is used for training, where the environment is reset with one of 50 different boards after eacg .reset() call. During testing, eval_mode should be set to True in order to evaluate the agent on boards that were never seen during the training phase.

Sudoku-v0 (biased version)

import gymnasium as gym

env = gym.make("sudoku-v0",mode="biased"render_mode="human",horizon=600,eval_mode=True)
env.reset() 

for n in range(int(6e3)):
    env.step(env.action_space.sample())
    env.render() 

Bias : Among the induced biases that immensely help guide that learning is the fact that the policy cannot modify a cell that was already correctly filled, on top of the existing untouchable cells present in the beginning.

Measuring learning for this version of the environment:* The current structure of the environment allows a completely random policy to solve it (this is true for easy boards in the current version of the environment), so a good way to measure learning might be to use the number of steps over N episodes under a random policy as a baseline. This implies that a policy able to consistently solve the test boards in fewer steps over the same N episodes used to run a random policy is, in theory, displaying some sort of learning.

Sudoku-v1

import gymnasium as gym

env = gym.make("sudoku-v1",mode="easy",render_mode="human",horizon=600,eval_mode=True)
env.reset() 

for n in range(int(6e3)):
    env.step(env.action_space.sample())
    env.render() 

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

gymnasium_sudoku-0.3.2.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

gymnasium_sudoku-0.3.2-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file gymnasium_sudoku-0.3.2.tar.gz.

File metadata

  • Download URL: gymnasium_sudoku-0.3.2.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gymnasium_sudoku-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f08fb4bf3e1081c343deae9956730cec7ea7ba66f93abd7b84855f04adbe176b
MD5 765ca3b1261195a5bf2de299d1d4bf7c
BLAKE2b-256 69255d54aa89751b60e24be27ad686aa53b80a20991db69c8079abf3dbf90ff8

See more details on using hashes here.

File details

Details for the file gymnasium_sudoku-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gymnasium_sudoku-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c5bb8be436ced114ac393c7776854d6c27896dde756f28473361322a3a03afb
MD5 d7dc080af72ae3a227ea4a815863da39
BLAKE2b-256 66fe4551021604293bb56a148285d9dea31790fde9e6b3b5883c25416f148139

See more details on using hashes here.

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