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

Uploaded Python 3

File details

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

File metadata

  • Download URL: gymnasium_sudoku-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 dea6165a9f0d7132a9635081222e20ab38dfed69fef8ee406499a440bea629f6
MD5 81f482b4b6733821b25a7876c65e52d0
BLAKE2b-256 f03c3079ea5ae21fdef6310b9fac0f98bfd937b9a4e39beb51ee820ad4267ccd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gymnasium_sudoku-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 eb45fe3096c89cb3ffaa4b339ca6b124bbe08b4cb7e2e75609fee5db3afec877
MD5 2c87b77c64a40462bc092523418af2d5
BLAKE2b-256 c3bcb7645a8879fb1150840f1560f20257f18ec3ccca55f0e7db8820bf3c629b

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