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.1.tar.gz (11.7 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.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gymnasium_sudoku-0.3.1.tar.gz
  • Upload date:
  • Size: 11.7 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.1.tar.gz
Algorithm Hash digest
SHA256 365f844d7ac4ff319099172bc8eee2fc0ddcee88a8c7779c6f5ed4e320dd607e
MD5 ebcb17ce0e55a22a50543c1419ad0114
BLAKE2b-256 e5559a43467be38d753bd992d83446f3ee64fda8f1a899624dfca88b89e425c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gymnasium_sudoku-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26b4ffab67511d6e93d68b817d128fee5b1079bff088324741d02bad4d529337
MD5 f81d4b568821f80b6fa512f7fbbe718b
BLAKE2b-256 b322bc9abeeffef7cb54727c4b67deae4be4561b5c1c80255bb68ff4d103d7d8

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