Skip to main content

core

This module provides the core class Solver, which loads a mode and finds Rubik's Cube solutions using a beam search algorithm.

Class:

  • Solver: A class for managing Rubik's Cube configuration, solving model, and search function.

Solver

class Solver()

A solver class for managing environment, model, and search configurations.

This class orchestrates the cube environment, the neural network model, and the beam search algorithm to find solutions.

Methods:

  • load: Load the solver model and optimize it for CPU or GPU.
  • __call__ (or solve): Set up the cube state and find solutions using beam search.
  • benchmark: Evaluate the solver's search efficiency.
  • evaluate_temporal_performance: (Deprecated) Evaluate solution length vs. time.

load

def load(
model_id: str = dict(cpu="small").get(device.type, "large"),
prefer_gpu: bool = True,
quantize_on_cpu: bool = True,
jit_mode: bool = False,
cache_dir: str = os.path.expanduser("~/.cache/alphacube")
)

Load the Rubik's Cube solver model and optimize it for CPU or GPU.

Arguments:

  • model_id str - Identifier for the model variant to load ("small", "base", or "large").
  • prefer_gpu bool - Whether to prefer GPU if available.
  • quantize_on_cpu bool - Whether to quantize the model for CPU optimization.
  • jit_mode bool - Whether to enable JIT mode for potentially faster execution.
  • cache_dir str - Directory to cache the model files.

Returns:

  • None

__call__

def __call__(
scramble,
format="moves",
allow_wide=True,
beam_width: int = 1024,
extra_depths: int = 0,
ergonomic_bias: dict | None = None
)

Set up the cube state and find solutions using beam search.

Arguments:

  • scramble list or str - A sequence of moves or a sticker representation of the initial cube state.
  • format str - Input format of the scramble: "moves" or "stickers".
  • allow_wide bool - Whether to allow wide moves in the search space.
  • Note - This is often controlled automatically by ergonomic_bias.
  • beam_width int - The beam width for the search algorithm.
  • extra_depths int - Number of extra depths to search after finding a solution.
  • ergonomic_bias dict, optional - A dictionary to bias the search towards certain moves based on ergonomic preference.

Returns:

  • dict | None: A dictionary containing the solution(s) and search metadata, or None if no solution is found.

benchmark

A shortcut method alphacube.solver.benchmark(...) functionally equivalent to alphacube._evaluator.benchmark(alphacube.solver, ...). evaluate_search_efficiency redirects to this method for backward compatibility.

evaluate_temporal_performance

Deprecated. A shortcut alphacube._evaluator.evaluate_temporal_performance