Skip to main content

A Sudoku environment for Reinforcement Learning research

Project description

pip install gymnasium_sudoku
import gymnasium_sudoku
import gymnasium as gym

env = gym.make("sudoku-v0",render_mode="human",horizon=150,render_delay=1.0,eval_mode=True)
env.reset() 
steps = 100

for n in range(steps):
    env.step(env.action_space.sample())
    env.render() 

And for training mode:

env = gym.make("sudoku-v0",horizon=150,eval_mode=False) # no rendering during  training  
  • 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]]

  • Eval mode/Training mode : By default, eval_mode is set to False, this is good for training since after each reset() call,the Sudoku board will be changed to add more diversity to the training data and try to prevent memorization, so that the policy learns a more general distribution...At least that is the intuition. During testing, eval_mode should be set to True to test the generalization capabilities of a trained policy or to test the environment with a random policy.This is important; otherwise,when testing a trained policy,it will be tested on states seen during training which would measure memorization rather than generalization.This makes it an invalid test of the policy's true capabilities.

  • Measuring learning & Inductive Biases:* 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. 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. That attribute of the current environment reflects the way broadly available Sudoku environments intended for human players are structured.

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.2.3.tar.gz (22.5 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.2.3-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gymnasium_sudoku-0.2.3.tar.gz
  • Upload date:
  • Size: 22.5 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.2.3.tar.gz
Algorithm Hash digest
SHA256 4502d6fed5766b2015f9d92e484edc18b3aac3d8e5207e1cc9529d2b98ecbfd7
MD5 75769f0a49899e7516a9da21cb9197f9
BLAKE2b-256 091c4cdcefef352094fbb12f5d25ba5d5fad34cb1f5fdc3607adfadd72d58883

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gymnasium_sudoku-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2c49b9809a86eed8f791916e975215aeeae06346ab2f45aa3fbb3f9f70979a
MD5 7b9d9d1472ecda223f8bc5c3a760abc2
BLAKE2b-256 3bda60556b829a2259444f0f33d9209b2a3b60a477b7c6dd00567335eceba22f

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