Skip to main content

Sudoku-SMT-Solvers

Pytest + CI/CD Coverage Status Docs Build Deployment Documentation

About

This repository contains the code for the study "Evaluating SMT-Based Solvers on Sudoku". Created by Liam Davis (@liamjdavis) and Tairan "Ryan" Ji (@TairanJ) as their for COSC-241 Artificial Intelligence at Amherst College, it evaluates the efficacy of SMT-Based Solvers by benchmarking three modern SMT solvers (DPLL(T), Z3, and CVC5) against the DPLL algorithm on a collection of 100 25x25 Sudoku puzzles of varying difficulty. The corresponding paper can be found here.

Along with the study, we also published sudoku-smt-solvers, a Python package that provides the various SMT-based Sudoku solvers and benchmarking tools we built for this study. The package features DPLL(T), Z3, and CVC5 solvers optimized for 25x25 Sudoku puzzles, a puzzle generator for creating test cases, and a comprehensive benchmarking suite. Available through pip, it offers a simple API for solving Sudoku puzzles using state-of-the-art SMT solvers while facilitating performance comparisons between different solving approaches.

The study aims to answer three research questions:

  1. How have logical solvers evolved over time in terms of performance and capability?
  2. How do different encodings of Sudoku affect the efficiency and scalability of these solvers?
  3. Are there specific features or optimizations in SMT solvers that provide a significant advantage over traditional SAT solvers for this class of problem?

Getting started

Installation

To run the code locally, you can install with pip

pip install sudoku-smt-solvers

Solvers

This package includes the DPLL solver and three modern SMT solvers:

  • DPLL(T)
  • CVC5
  • Z3

To run any of the solvers on a 25x25 Sudoku puzzle, you can create an instance of the solver class and call the solve method in a file at the root (Sudoku-smt-solvers). Here is an example using Z3:

from sudoku_smt_solvers import Z3Solver

# Example grid (25x25)
grid = [[0] * 25 for _ in range(25)]
solver = Z3Solver(grid)
solution = solver.solve()

if solution:
    print(f"Solution:\n\n{solution}")
else:
    print("No solution exists.")

Sudoku Generator

This package also includes a generator for creating Sudoku puzzles to be used as benchmarks. To generate a puzzle, create an instance of the SudokuGenerator class and call the generate method. Here is an example:

from sudoku_smt_solvers import SudokuGenerator

generator = SudokuGenerator(size = 25, givens = 80, timeout = 5, difficulty = "Medium", puzzles_dir = "benchmarks/puzzles", solutions_dir = "benchmarks/solutions")

generator.generate()

Due to the computational complexity of generating large sudoku puzzles, it is recommended that you run multiple generator instances in parallel to create benchmarks.

Benchmark Runner

To run the benchmarks you created on all four solvers, create an instance of the BenchmarkRunner class and call the run_benchmarks method. Here is an example:

from sudoku_smt_solvers import BenchmarkRunner

runner = BenchmarkRunner(
    puzzles_dir='resources/benchmarks/puzzles/',
    results_dir='results/'
)
runner.run_benchmarks()

Contributing

We welcome contributions in the form of new solvers, additions to our benchmark suite, or anything that improves the tool! Here's how to get started:

Development Setup

  1. Fork and Clone:
    Begin by forking the repository and cloning your fork locally:

    git clone https://github.com/yourusername/Sudoku-SMT-Solvers.git
    cd Sudoku-SMT-Solvers
    
  2. Create and Activate a Virtual Environment:
    Set up a Python virtual environment to isolate your dependencies:

    python3 -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    
  3. Install Dependencies:
    Install the required dependencies from the requirements.txt file:

    pip install -r requirements.txt
    
  4. Set Up Pre-Commit Hooks:
    Install and configure pre-commit hooks to maintain code quality:

    pip install pre-commit
    pre-commit install
    

    To manually run the hooks and verify code compliance, use:

    pre-commit run
    
  5. Testing and Coverage Requirements:

    • Write tests for any new code or modifications.
    • Use pytest for running tests:
      pytest
      
    • Ensure the test coverage is at least 90%:
  6. Add and Commit Your Changes:

    • Follow the existing code style and structure.
    • Verify that all pre-commit hooks pass and the test coverage meets the minimum requirement.
    git add .
    git commit -m "Description of your changes"
    
  7. Push Your Branch: Push your changes to your forked repository:

    git push origin your-branch-name
    
  8. Open a PR for us to review


Thank you for your interest in contributing to Sudoku-SMT-Solvers! Your efforts help make this project better for everyone.

Contact Us

For any questions or support, please reach out to Liam at ljdavis27 at amherst.edu and Ryan at tji26 at amherst.edu

Metadata

Release files for sudoku-smt-solvers 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sudoku-smt-solvers 1.0.0
File Size Uploaded Provenance Actions
sudoku_smt_solvers-1.0.0.tar.gz 25.5 kB With provenance Details for sudoku_smt_solvers-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sudoku-smt-solvers 1.0.0
File Interpreter ABI Platform Actions
sudoku_smt_solvers-1.0.0-py3-none-any.whl Python 3 none any Details for sudoku_smt_solvers-1.0.0-py3-none-any.whl

Total release size: 48.5 kB

Release files / sudoku_smt_solvers-1.0.0.tar.gz

Download URL sudoku_smt_solvers-1.0.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a8562ff49678b12c51bb9e1e39b7aaa7a8f4c93f4156057c7cc6ebb438110a31
BLAKE2b-256 checksum
How to use checksums
71a5c17e8b63ef09217a263089eb3bee43c80e5e9964e00c3fdd56dfb9e646c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 16, 2025.

Transparency log

Release files / sudoku_smt_solvers-1.0.0-py3-none-any.whl

Download URL sudoku_smt_solvers-1.0.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efb69126c3a72ea74e9fa0aafda35f0ef7f78c57234d3d262f3e114060f29359
BLAKE2b-256 checksum
How to use checksums
665e62a45979075cff678eca0ce39abdbc434b3e83307f4228f3ec6caa5f29ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 16, 2025.

Transparency log

Security for sudoku-smt-solvers 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sudoku_smt_solvers-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 16, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page