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.3.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.3-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gymnasium_sudoku-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 7b0e9f8dc5b452947910ce6447e236ebd96d35b4424503ea23d29b2a80b47d64
MD5 3421459ff17ca5325a2f0e5d19f314ea
BLAKE2b-256 8dce9ce16970bfd095a2784ac2ada412ae8d389cdf9760390503190b33bc277a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gymnasium_sudoku-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d3f5591693d80d651c5cc751181970f226f1d5154209b4257191d6aa202f026f
MD5 c3483f282d0d79c93d3806f54a08cc82
BLAKE2b-256 6279b3c292a8da4350355371d8c189c5392ca9213dfbc3b858ed6ba8da5eb899

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