kyo-takano / efficientcube

State-of-the-Art method for solving the Rubik's Cube

Home Page:https://openreview.net/forum?id=bnBeNFB27b

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧩 Self-Supervision is All You Need for Solving Rubik's Cube

arXiv TMLR

This repository contains the code, models, and solutions as reported in the following paper:

K. Takano. Self-Supervision is All You Need for Solving Rubik's Cube. Transactions on Machine Learning Research, ISSN 2835-8856, 2023. URL: https://openreview.net/forum?id=bnBeNFB27b.

Abstract:
Existing combinatorial search methods are often complex and require some level of expertise. This work introduces a simple and efficient deep learning method for solving combinatorial problems with a predefined goal, represented by Rubik's Cube. We demonstrate that, for such problems, training a deep neural network on random scrambles branching from the goal state is sufficient to achieve near-optimal solutions. When tested on Rubik's Cube, 15 Puzzle, and 7×7 Lights Out, our method outperformed the previous state-of-the-art method DeepCubeA, improving the trade-off between solution optimality and computational cost, despite significantly less training data. Furthermore, we investigate the scaling law of our Rubik's Cube solver with respect to model size and training data volume.

Important

The compute-optimal models trained using Half-Turn Metric (Section 7: Scaling Law) are available in AlphaCube, a dedicated Rubik's Cube solver based on this study.

Code

Jupyter Notebooks

We provide standalone Jupyter Notebooks for you to train DNNs & solve the problems we addressed in the paper.

Problem File Launch
Rubik's Cube ./notebooks/Rubik's_Cube.ipynb Open In Colab
Kaggle
15 Puzzle ./notebooks/15_Puzzle.ipynb Open In Colab
Kaggle
7×7 Lights Out ./notebooks/Lights_Out.ipynb Open In Colab
Kaggle

To fully replicate our study, you will need to modify hyperparameters.

Package

We also provide a Python package at ./efficientcube to solve a given problem. Please make sure that you have torch>=1.12 installed.

Installation:

git clone https://github.com/kyo-takano/EfficientCube

Example usage (Rubik's Cube):

from efficientcube import EfficientCube

""" Specify scramble & search parameter """
scramble = "D U F F L L U' B B F F D L L U R' F' D R' F' U L D' F' D R R"
beam_width = 1024 # This parameter controls the trade-off between speed and quality

""" Set up solver, apply scramble, & solve """
solver = EfficientCube(
    env ="Rubik's Cube",    # "Rubik's Cube", "15 Puzzle", or "Lights Out"
    model_path="auto",      # Automatically finds by `env` name
)
solver.apply_moves_to_env(scramble)
result = solver.solve(beam_width)

""" Verify the result """
if result is not None:
    print('Solution:', ' '.join(result['solutions']))
    print('Length:', len(result['solutions']))
    solver.reset_env()
    solver.apply_moves_to_env(scramble.split() + result['solutions'])
    assert solver.env_is_solved()
else:
    print('Failed')

Data

Models

Included in the package are the TorchScript models for the three problems. They can be specified as ./efficientcube/models/{cube3|puzzle15|lightsout7}.pth.

Solutions

The solutions reported in the paper are located under ./results/, and each problem has its own subdirectory containing Pickle file(s) (./results/{cube3|puzzle15|lightsout7}/beam_width_{beam_width}.pkl). Please see results/README.md for more details.

Dataset

The DeepCubeA dataset we used for evaluation is available from either Code Ocean or GitHub.

Citation

@article{
    takano2023selfsupervision,
    title={Self-Supervision is All You Need for Solving Rubik's Cube},
    author={Kyo Takano},
    journal={Transactions on Machine Learning Research},
    issn={2835-8856},
    year={2023},
    url={https://openreview.net/forum?id=bnBeNFB27b}
}

License

All materials are licensed under the Creative Commons Attribution 4.0 International License (CC-BY-4.0). You may obtain a copy of the license at: https://creativecommons.org/licenses/by/4.0/legalcode

Contact

Please contact the author at kyo.takano@mentalese.co for any questions.

About

State-of-the-Art method for solving the Rubik's Cube

https://openreview.net/forum?id=bnBeNFB27b

License:Creative Commons Attribution 4.0 International


Languages

Language:Jupyter Notebook 95.6%Language:Python 4.4%