alphacube


Namealphacube JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryA powerful & flexible Rubik's Cube solver
upload_time2024-04-16 06:25:03
maintainerNone
docs_urlNone
authorKyo Takano
requires_python>=3.6
licenseMIT License Copyright (c) 2023 Kyo Takano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords rubiks-cube solver ai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AlphaCube

AlphaCube is a powerful & flexible Rubik's Cube solver that extends [EfficientCube](https://github.com/kyo-takano/efficientcube). It uses a Deep Neural Network (DNN) to find optimal/near-optimal solutions for a given scrambled state.

> [!NOTE]
> **🎮 Try the interactive demo: [alphacube.dev](https://alphacube.dev)**

## Use Cases

- Solve any scrambled Rubik's Cube configuration with ease
- Find efficient algorithms/solutions, optimizing for either computation speed or ergonomics of the move sequence
- Incorporate into Rubik's Cube apps and tools to provide solving capabilities
- Analyze and study the statistical properties and solution space of the Rubik's Cube puzzle
- Illustrate AI/ML concepts to students. Topics include:
  - discrete diffusion model
  - self-supervised learning
  - combinatorial search with probabilities

---

## Table of Contents

- [AlphaCube](#alphacube)
  - [Use Cases](#use-cases)
  - [Table of Contents](#table-of-contents)
  - [Installation](#installation)
  - [Usage](#usage)
    - [Basic](#basic)
    - [Better Solutions](#better-solutions)
    - [Applying Ergonomic Bias](#applying-ergonomic-bias)
    - [GPU Acceleration](#gpu-acceleration)
  - [How It Works](#how-it-works)
  - [Contributing](#contributing)
  - [License](#license)

## Installation

Open a terminal and execute the following command:

```sh
pip install -U alphacube
```

## Usage

### Basic

```python
import alphacube

# Load a trained DNN (default is "small" model)
alphacube.load()

# Solve the cube using a given scramble sequence
result = alphacube.solve(
    scramble="D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2",
    beam_width=1024, # Number of candidate solutions to consider at each depth of search
)
print(result)
```

> **Output**
>
> ```python
> {
>     'solutions': [
>         "D L D2 R' U2 D B' D' U2 B U2 B' U' B2 D B2 D' B2 F2 U2 F2"
>     ],
>     'num_nodes': 19744, # Total search nodes explored
>     'time': 1.4068585219999659 # Wall-clock time in seconds
> }
> ```

### Better Solutions

Increasing `beam_width` explores more candidate solutions, producing shorter (better) solve sequences at the cost of increased computation:

```python
result = alphacube.solve(
    scramble="D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2",
    beam_width=65536,
)
print(result)
```

> **Output**
>
> ```python
> {
>     'solutions': [
>         "D' R' D2 F' L2 F' U B F D L D' L B D2 R2 F2 R2 F'",
>         "D2 L2 R' D' B D2 B' D B2 R2 U2 L' U L' D' U2 R' F2 R'"
>     ],
>     'num_nodes': 968984,
>     'time': 45.690575091997744
> }
> ```

`beam_width` values between 1024-65536 typically offer a good trade-off between solution quality and speed. Tune according to your needs.

### Applying Ergonomic Bias

The `ergonomic_bias` parameter lets you specify the desirability of each move type, influencing the solver to favor certain moves over others:

```python
# Desirability scale: 0 (lowest) to 1 (highest)
ergonomic_bias = {
    "U": 0.9,   "U'": 0.9,  "U2": 0.8,
    "R": 0.8,   "R'": 0.8,  "R2": 0.75,
    "L": 0.55,  "L'": 0.4,  "L2": 0.3,
    "F": 0.7,   "F'": 0.6,  "F2": 0.6,
    "D": 0.3,   "D'": 0.3,  "D2": 0.2,
    "B": 0.05,  "B'": 0.05, "B2": 0.01,
    "u": 0.45,  "u'": 0.45, "u2": 0.4,
    "r": 0.3,   "r'": 0.3,  "r2": 0.25,
    "l": 0.2,   "l'": 0.2,  "l2": 0.15,
    "f": 0.35,  "f'": 0.3,  "f2": 0.25,
    "d": 0.15,  "d'": 0.15, "d2": 0.1,
    "b": 0.03,  "b'": 0.03, "b2": 0.01
}

result = alphacube.solve(
    scramble="D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2",
    beam_width=65536,
    ergonomic_bias=ergonomic_bias
)
print(result)
```

> **Output**
>
> ```python
> {
>     'solutions': [
>         "u' U' f' R2 U2 R' L' F' R D2 f2 R2 U2 R U L' U R L",
>         "u' U' f' R2 U2 R' L' F' R D2 f2 R2 U2 R d F' U f F",
>         "u' U' f' R2 U2 R' L' F' R u2 F2 R2 D2 R u f' l u U"
>     ],
>     'num_nodes': 1078054,
>     'time': 56.13087955299852
> }
> ```

### GPU Acceleration

For maximum performance, use the `"large"` model on a CUDA-enabled GPU (requires [PyTorch](https://pytorch.org/get-started/locally/)):

```python
alphacube.load("large")
result = alphacube.solve(
    scramble="D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2",
    beam_width=65536,
)
print(result)
```

> **Output**
>
> ```python
> {
>     'solutions': ["D F L' F' U2 B2 U F' L R2 B2 U D' F2 U2 R D'"],
>     'num_nodes': 903448,
>     'time': 20.46845487099995
> }
> ```

Using a GPU provides an order of magnitude speedup over CPUs, especially for larger models.

> [!IMPORTANT]
> When running AlphaCube _on a CPU_, it's generally recommended to stick with the `"small"` model, as the larger `"base"` and `"large"` models would take considerably more time to find solutions.

Please refer to our [documentation](https://alphacube.dev/docs) for more, especially ["Getting Started"](https://alphacube.dev/docs/getting-started/index.html)

## How It Works

At the heart of AlphaCube lies a deep learning method described in ["Self-Supervision is All You Need for Solving Rubik's Cube" (TMLR'23)](https://openreview.net/forum?id=bnBeNFB27b), the official code of which is also available as [EfficientCube](https://github.com/kyo-takano/efficientcube).

The 3 provided models (`"small"`, `"base"`, and `"large"`) are **_compute-optimally trained_** in the Half-Turn Metric, This means the model sizes are scaled in tandem with the amount of training data to maximize prediction accuracy for a given computational budget. See Section 7 of the above-mentioned paper for details.

> [!NOTE]
> **📖 Read more: ["How It Works"](https://alphacube.dev/docs/how-it-works/index.html)**

## Contributing

You are more than welcome to collaborate on AlphaCube. Please read our [Contributing Guide](https://github.com/kyo-takano/alphacube/blob/main/CONTRIBUTING.md) to get started.

## License

AlphaCube is open source under the [MIT License](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "alphacube",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "rubiks-cube, solver, ai",
    "author": "Kyo Takano",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# AlphaCube\n\nAlphaCube is a powerful & flexible Rubik's Cube solver that extends [EfficientCube](https://github.com/kyo-takano/efficientcube). It uses a Deep Neural Network (DNN) to find optimal/near-optimal solutions for a given scrambled state.\n\n> [!NOTE]\n> **\ud83c\udfae Try the interactive demo: [alphacube.dev](https://alphacube.dev)**\n\n## Use Cases\n\n- Solve any scrambled Rubik's Cube configuration with ease\n- Find efficient algorithms/solutions, optimizing for either computation speed or ergonomics of the move sequence\n- Incorporate into Rubik's Cube apps and tools to provide solving capabilities\n- Analyze and study the statistical properties and solution space of the Rubik's Cube puzzle\n- Illustrate AI/ML concepts to students. Topics include:\n  - discrete diffusion model\n  - self-supervised learning\n  - combinatorial search with probabilities\n\n---\n\n## Table of Contents\n\n- [AlphaCube](#alphacube)\n  - [Use Cases](#use-cases)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Basic](#basic)\n    - [Better Solutions](#better-solutions)\n    - [Applying Ergonomic Bias](#applying-ergonomic-bias)\n    - [GPU Acceleration](#gpu-acceleration)\n  - [How It Works](#how-it-works)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Installation\n\nOpen a terminal and execute the following command:\n\n```sh\npip install -U alphacube\n```\n\n## Usage\n\n### Basic\n\n```python\nimport alphacube\n\n# Load a trained DNN (default is \"small\" model)\nalphacube.load()\n\n# Solve the cube using a given scramble sequence\nresult = alphacube.solve(\n    scramble=\"D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2\",\n    beam_width=1024, # Number of candidate solutions to consider at each depth of search\n)\nprint(result)\n```\n\n> **Output**\n>\n> ```python\n> {\n>     'solutions': [\n>         \"D L D2 R' U2 D B' D' U2 B U2 B' U' B2 D B2 D' B2 F2 U2 F2\"\n>     ],\n>     'num_nodes': 19744, # Total search nodes explored\n>     'time': 1.4068585219999659 # Wall-clock time in seconds\n> }\n> ```\n\n### Better Solutions\n\nIncreasing `beam_width` explores more candidate solutions, producing shorter (better) solve sequences at the cost of increased computation:\n\n```python\nresult = alphacube.solve(\n    scramble=\"D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2\",\n    beam_width=65536,\n)\nprint(result)\n```\n\n> **Output**\n>\n> ```python\n> {\n>     'solutions': [\n>         \"D' R' D2 F' L2 F' U B F D L D' L B D2 R2 F2 R2 F'\",\n>         \"D2 L2 R' D' B D2 B' D B2 R2 U2 L' U L' D' U2 R' F2 R'\"\n>     ],\n>     'num_nodes': 968984,\n>     'time': 45.690575091997744\n> }\n> ```\n\n`beam_width` values between 1024-65536 typically offer a good trade-off between solution quality and speed. Tune according to your needs.\n\n### Applying Ergonomic Bias\n\nThe `ergonomic_bias` parameter lets you specify the desirability of each move type, influencing the solver to favor certain moves over others:\n\n```python\n# Desirability scale: 0 (lowest) to 1 (highest)\nergonomic_bias = {\n    \"U\": 0.9,   \"U'\": 0.9,  \"U2\": 0.8,\n    \"R\": 0.8,   \"R'\": 0.8,  \"R2\": 0.75,\n    \"L\": 0.55,  \"L'\": 0.4,  \"L2\": 0.3,\n    \"F\": 0.7,   \"F'\": 0.6,  \"F2\": 0.6,\n    \"D\": 0.3,   \"D'\": 0.3,  \"D2\": 0.2,\n    \"B\": 0.05,  \"B'\": 0.05, \"B2\": 0.01,\n    \"u\": 0.45,  \"u'\": 0.45, \"u2\": 0.4,\n    \"r\": 0.3,   \"r'\": 0.3,  \"r2\": 0.25,\n    \"l\": 0.2,   \"l'\": 0.2,  \"l2\": 0.15,\n    \"f\": 0.35,  \"f'\": 0.3,  \"f2\": 0.25,\n    \"d\": 0.15,  \"d'\": 0.15, \"d2\": 0.1,\n    \"b\": 0.03,  \"b'\": 0.03, \"b2\": 0.01\n}\n\nresult = alphacube.solve(\n    scramble=\"D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2\",\n    beam_width=65536,\n    ergonomic_bias=ergonomic_bias\n)\nprint(result)\n```\n\n> **Output**\n>\n> ```python\n> {\n>     'solutions': [\n>         \"u' U' f' R2 U2 R' L' F' R D2 f2 R2 U2 R U L' U R L\",\n>         \"u' U' f' R2 U2 R' L' F' R D2 f2 R2 U2 R d F' U f F\",\n>         \"u' U' f' R2 U2 R' L' F' R u2 F2 R2 D2 R u f' l u U\"\n>     ],\n>     'num_nodes': 1078054,\n>     'time': 56.13087955299852\n> }\n> ```\n\n### GPU Acceleration\n\nFor maximum performance, use the `\"large\"` model on a CUDA-enabled GPU (requires [PyTorch](https://pytorch.org/get-started/locally/)):\n\n```python\nalphacube.load(\"large\")\nresult = alphacube.solve(\n    scramble=\"D U F2 L2 U' B2 F2 D L2 U R' F' D R' F' U L D' F' D R2\",\n    beam_width=65536,\n)\nprint(result)\n```\n\n> **Output**\n>\n> ```python\n> {\n>     'solutions': [\"D F L' F' U2 B2 U F' L R2 B2 U D' F2 U2 R D'\"],\n>     'num_nodes': 903448,\n>     'time': 20.46845487099995\n> }\n> ```\n\nUsing a GPU provides an order of magnitude speedup over CPUs, especially for larger models.\n\n> [!IMPORTANT]\n> When running AlphaCube _on a CPU_, it's generally recommended to stick with the `\"small\"` model, as the larger `\"base\"` and `\"large\"` models would take considerably more time to find solutions.\n\nPlease refer to our [documentation](https://alphacube.dev/docs) for more, especially [\"Getting Started\"](https://alphacube.dev/docs/getting-started/index.html)\n\n## How It Works\n\nAt the heart of AlphaCube lies a deep learning method described in [\"Self-Supervision is All You Need for Solving Rubik's Cube\" (TMLR'23)](https://openreview.net/forum?id=bnBeNFB27b), the official code of which is also available as [EfficientCube](https://github.com/kyo-takano/efficientcube).\n\nThe 3 provided models (`\"small\"`, `\"base\"`, and `\"large\"`) are **_compute-optimally trained_** in the Half-Turn Metric, This means the model sizes are scaled in tandem with the amount of training data to maximize prediction accuracy for a given computational budget. See Section 7 of the above-mentioned paper for details.\n\n> [!NOTE]\n> **\ud83d\udcd6 Read more: [\"How It Works\"](https://alphacube.dev/docs/how-it-works/index.html)**\n\n## Contributing\n\nYou are more than welcome to collaborate on AlphaCube. Please read our [Contributing Guide](https://github.com/kyo-takano/alphacube/blob/main/CONTRIBUTING.md) to get started.\n\n## License\n\nAlphaCube is open source under the [MIT License](LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Kyo Takano  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A powerful & flexible Rubik's Cube solver",
    "version": "0.1.4",
    "project_urls": {
        "Documentation": "https://alphacube.dev/docs/index.html",
        "Source": "https://github.com/kyo-takano/alphacube"
    },
    "split_keywords": [
        "rubiks-cube",
        " solver",
        " ai"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d6085ec5ccf74f53fec7a7ad6440010dec75f80aa38b35e10cc3168723c91aa8",
                "md5": "9fefe61ae26c2b8450d4b6b642e00251",
                "sha256": "16603492445d427daf76426eae1aa6b2a9aebf393929ae5489b51e3bc9490c70"
            },
            "downloads": -1,
            "filename": "alphacube-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9fefe61ae26c2b8450d4b6b642e00251",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 24779,
            "upload_time": "2024-04-16T06:25:03",
            "upload_time_iso_8601": "2024-04-16T06:25:03.834562Z",
            "url": "https://files.pythonhosted.org/packages/d6/08/5ec5ccf74f53fec7a7ad6440010dec75f80aa38b35e10cc3168723c91aa8/alphacube-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 06:25:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyo-takano",
    "github_project": "alphacube",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "alphacube"
}
        
Elapsed time: 2.30657s