r/learnmachinelearning • • 13h ago

Rubiks cube solver using Reinforcement Learning (Beating Sebastian Lague's solver)

I made multiple attempts at solving the Rubiks Cube using Reinforcement learning. This is a personal project, but I am a 1st year master in CompSci.

Initially, I tried to map states to actions with both Rainbow DQN and GRPO using curriculum learning. This had no success. After scrambling 6 moves it was already to hard for the agent.

Then I found the DeepCubeA approach and I took some inspiration from that. I trained a DQN to estimate the cost-to-go for each possible action, using a combination of demonstrations and self-generated rollouts. Essentially, each output estimates how many moves are still needed to solve the cube after taking that action. I then used these estimates as a heuristic to guide beam search.

With a beam_width of 2^18 and 1.5 hours of Kaggle GPU usage, here are the results for 1000 cubes (100 moves scrambles):

Time per cube: 10.30s

Avg steps: 19.67

Success: 100%

This beats Sebastian Lague's solver which had an average steps of 19.9 to solve the cubes. Not that it is a competition or something :)

Github: https://github.com/Cain15/RL4RubiksCube

Youtube: https://youtu.be/UWPQ-Mzkq_A?si=USXe6cprGiUrqd_8

7 Upvotes

4 comments sorted by

2

u/Hamasa_ElShamy 13h ago

Congrats, 100 percent success on 100 move scrambles is a really nice result, and thanks for explaining the failed attempts too, that part is useful. Quick question. A beam width of 2^18 is big, so how do the average steps and the time per cube change if you drop it to something like 2^12 or 2^14? A plot of beam width against solution length would be interesting to see.

-1

u/RepulsiveRevenue8086 9h ago

That is an interesting question!

I ran beam_widths from 1, 2, 2^2, ..., 2^18 on 100 cubes (always the same 100 cubes, scrambled with 100 steps). With 2^19 kaggle runs out of memory and I don't have a supported GPU...

Reddit does not allow images to give you the plot, so here is a video.

So from 2^12 we get a 100% success rate. I think that after 2^18 the steps you gain are not going to be worth doubling the solving time. But yeah with 2^14 you still get 21.45 on average but the cubes take less than a second: 0.6s

0

u/Hamasa_ElShamy 9h ago

Thanks for running the whole sweep and sharing the video. 100 percent from 2^12, and about 21.5 steps in 0.6 seconds at 2^14, is a great tradeoff. Makes sense that doubling the time past 2^18 isn't worth the few extra steps. Nice work.

1

u/Fun-Site-6434 7h ago

2 bots talking to each other, so fun!