Accessing LunaSolve's Algorithms

In this tutorial, we'll explore how to access LunaSolve's optimization algorithms from LunaBench, providing access to a broad range of pre-implemented algorithms not directly available in the LunaBench SDK.

Before we begin, ensure you have installed the LunaBench Python SDK.
Please note that LunaBench is provided through a separate SDK from the luna-quantum SDK and is currently available only with academic and commercial plans.

Upon completing this tutorial, you will be able to:

  1. Connect to LunaSolve from within LunaBench.
  2. Select algorithms from LunaSolve to be used in your LunaBench pipeline.
  3. Run a benchmark pipeline with algorithms from various sources.

1. Creating the Dataset

To start, we'll begin with assembling a straightforward dataset. For the purposes of this tutorial, our focus will be on crafting a basic dataset comprised of QUBOs.

# Define the problem type as qubo
problem_name = "qubo"

# Define the dataset
dataset = {
    "qubo_00": {
        problem_name: [
            [2, 1],
            [1, 2]
        ]
    },
    "qubo_01": {
        problem_name: [
            [-2, 3],
            [3, -2]
        ]
    },
    "qubo_02": {
        problem_name: [
            [2, 1, 0],
            [1, 2, 1],
            [0, 1, 2]
        ]
    },
}

2. Connecting to LunaSolve

LunaBench allows you to use the algorithms from LunaSolve by accessing the platform as a backend and running the algorithms on its servers. To access LunaSolve, you will need an API key, which can be obtained by logging into the platform through LunaBench.

To access LunaSolve, simply provide an API Token.

from lunabench import solve_dataset

solved, result_id = solve_dataset(
    luna_token="YOUR_API_TOKEN",
    ...
)

In addition, you will also need an encryption key to use LunaSolve. For this you need to set the environment variable LUNA_ENCRYPTION_KEY. For more information, please refer the encryption documentation.

3. Adding LunaSolve's Algorithms to the Pipeline

After logging into LunaSolve you will have access to all of the available solvers. LunaBench will propagate all parameters you provide, allowing you to configure the algorithms in exactly the same way as you do in LunaSolve, including how you manage QPU tokens. LunaSolve offers the flexibility to either store tokens on our platform or send them inline. If you store tokens, you can access them in the same manner here. For detailed instructions on using solvers and quantum hardware from LunaSolve, you can find a specific tutorial here.

In this example, we will access the version o Simulated Annealing hosted on our platform as well as D-Wave's Quantum Annealer.

from lunabench import solve_dataset

# Specify the algorithms from LunaSolve
algorithms = {
   "SA": {
        "location": "cloud",
        "n_iter": 1,
        "provider": "dwave"
    },
    "QA": {
        "location": "cloud",
        "provider": "dwave",
        "qpu_tokens": {
            "dwave": {
                "source": "inline",
                "token": "<TOKEN>"
            }
        }
    }
}

# Define the number of runs for each algorithm
n_runs = 2

# Solve the complete dataset
solved, result_id = solve_dataset(
    problem_name=problem_name,
    dataset=dataset,
    solve_algorithms=algorithms,
    n_runs=n_runs,
    luna_token=luna_token
)

Was this page helpful?