Skip to main content

__init__

alphacube package provides a few functions for different purposes:

  • load(*args, **kwargs): Load a trained DNN.
  • solve(*args, **kwargs): Solve a Rubik's Cube using the loaded solver.
  • set_verbose(loglevel=logging.INFO): Set the verbosity level of the logger.
  • cli(): Command-line utility for solving a Rubik's Cube using AlphaCube.

See Getting Started for the basic usage.

load

def load(model_id: str = "small" if device.type == "cpu" else "large", *args, **kwargs)

Load the Rubik's Cube solver model.

Arguments:

  • model_id - Identifier for the model variant to load ("small", "base", or "large"). Default to small on CPU; large on GPU/MPS.
  • *args - Additional positional arguments to configure model loading.
  • **kwargs - Additional keyword arguments to configure model loading.

Returns:

  • None

solve

def solve(*args, **kwargs)

Solve a Rubik's Cube puzzle using the loaded solver model.

Arguments:

*args, **kwargs: Arguments to configure puzzle solving; passed down to alphacube.core.Solver.__call__() and alphacube.search.beam_search.

Returns:

  • dict | None: A dictionary containing solutions and performance metrics. None if failed.

list_models

def list_models()

List the available model IDs.

Returns:

  • list - A list of available model IDs.

cli

def cli()

Command-line utility for solving a Rubik's Cube using AlphaCube.

Arguments:

  • --model_id/-m (str): Choose a specific model for solving (default: 'small' on CPU, otherwise large; another choice is `base``).
  • --format/-f (str): Specify the input format ('moves' or 'stickers').
  • --scramble/-s (str): Define the initial cube state using either a sequence of moves or a stringify JSON dictionary.
  • --beam_width/-bw (int): Set the beam width for search (default: 1024).
  • --extra_depths/-ex (int): Specify additional depths for exploration (default: 0).
  • --verbose/-v: Enable verbose output for debugging and tracking progress.

Returns:

  • None

Example Usages:

Syntax
alphacube [--model_id MODEL_ID] [--format FORMAT] [--scramble SCRAMBLE]
[--beam_width BEAM_WIDTH] [--extra_depths EXTRA_DEPTHS]
1. Solve a cube using default settings
alphacube --scramble "R U R' U'"
2. Solve a cube with custom settings
alphacube --model_id large --beam_width 128 --extra_depths 2 \
--scramble "R U2 F' R2 B R' U' L B2 D' U2 R F L"
3. Solve a cube using a sticker representation
alphacube --format stickers \
--scramble '{ \
"U": [0, 0, 5, 5, 0, 5, 5, 4, 0], \
"D": [1, 3, 3, 4, 1, 1, 4, 1, 3], \
"L": [4, 5, 1, 0, 2, 2, 0, 1, 4], \
"R": [5, 2, 0, 2, 3, 3, 2, 0, 2], \
"F": [4, 3, 2, 4, 5, 1, 1, 4, 3], \
"B": [1, 5, 5, 0, 4, 3, 3, 2, 2] \
}' \
--beam_width 64