Skip to content

Results are limited to the current section: Application solving tools

Product news

Solving a QUBO problem easily

Solving a QUBO problem is straightforward with qubo-solver. We can directly use the Solver class by providing an Instance with a given SolverConfig configuration. SolverConfig specifies whether to use a classical approach or a quantum one. Note that SolverConfig comes with many options but the default ones can be used straightforwardly. We have however more advanced tutorials on the quantum-related components to dive deeper into these advanced concepts.

To use a quantum approach, several choices have to be made regarding the configuration, explained in more details in the Solving QUBOs section of the documentation (external).

One main decision is about the backend (external), that is how we choose to perform quantum runs. We can decide to either perform our on emulators (locally, or remotely) or using a real quantum processing unit (QPU). Our QPU, based on the Rydberg Analog Model, is accessible remotely.

The supported backends are available via qoolqit (external), a Python package designed for algorithm development in the Rydberg Analog Model.

The backends can be divided into 3 main categories:

A backend will use device specifications to perform quantum computations. The list of supported devices can be found in the QoolQit devices documentation (external).

We can perform quantum simulations locally via an emulator.

from __future__ import annotations
from qubosolver import (
Instance,
LocalEmulator,
QuantumSolvingConfig,
Solver,
SolverConfig,
analysis,
matrix,
)
Q = matrix.tensor(
[
[-0.2, 0.0, 1.0],
[0.0, -1.0, 1.5],
[1.0, 1.5, -0.1],
]
)
instance = Instance(Q)
# Create a SolverConfig to use a quantum backend.
quantum_config = QuantumSolvingConfig(backend=LocalEmulator())
config = SolverConfig(solving=quantum_config)
solver = Solver(instance, config)
solution = solver.solve()
print(analysis.to_dataframe([solution]))

We can decide to perform our runs remotely via pasqal_cloud (external). To do so, we have to provide several information after setting up an account (external).

The code above can be modified to solve the QUBO instance using our real QPU remotely as follows (run only with your pasqal_cloud information):

import qoolqit
from pasqal_cloud import PasqalCloudConnection
from qoolqit.execution import QPU
from qubosolver import (
Instance,
QuantumSolvingConfig,
Solver,
SolverConfig,
analysis,
matrix,
)
# Replace with your username, project id and password on the Pasqal Cloud.
USERNAME = "#TO_PROVIDE"
PROJECT_ID = "#TO_PROVIDE"
PASSWORD = None
Q = matrix.tensor(
[
[-0.2, 0.0, 1.0],
[0.0, -1.0, 1.5],
[1.0, 1.5, -0.1],
]
)
instance = Instance(Q)
if PASSWORD is not None:
# Setup connection
connection = PasqalCloudConnection(
username=USERNAME,
password=PASSWORD,
project_id=PROJECT_ID,
)
# Get available devices
print(f"Available devices: {connection.fetch_available_devices()}")
# Choose a device, and use a quantum backend
device = qoolqit.Device.from_connection(connection, "FRESNEL_CAN1")
qpu_backend = QPU(connection=connection, num_shots=1000)
else:
# Use a mock local connection for the tutorial
from qubosolver import RemoteEmulator
from qubosolver.utils._local_connection import LocalConnection
connection = LocalConnection()
device = qoolqit.AnalogDevice()
qpu_backend = RemoteEmulator(connection=connection)
quantum_config = QuantumSolvingConfig(device=device, backend=qpu_backend)
config = SolverConfig(solving=quantum_config)
solver = Solver(instance, config)
solution = solver.solve()
print(analysis.to_dataframe([solution]))

Emulators are also available remotely via pasqal_cloud:

from pasqal_cloud import PasqalCloudConnection
from qubosolver import (
Instance,
QuantumSolvingConfig,
RemoteEmulator,
Solver,
SolverConfig,
analysis,
matrix,
)
# Replace with your username, project id and password on the Pasqal Cloud.
USERNAME = "#TO_PROVIDE"
PROJECT_ID = "#TO_PROVIDE"
PASSWORD = None
Q = matrix.tensor(
[
[-0.2, 0.0, 1.0],
[0.0, -1.0, 1.5],
[1.0, 1.5, -0.1],
]
)
instance = Instance(Q)
if PASSWORD is not None:
# Setup connection
connection = PasqalCloudConnection(
username=USERNAME,
password=PASSWORD,
project_id=PROJECT_ID,
)
else:
# Use a mock local connection for tutorial
from qubosolver.utils._local_connection import LocalConnection
connection = LocalConnection()
# Use a remote emulator backend
remote_emulator_backend = RemoteEmulator(connection=connection)
quantum_config = QuantumSolvingConfig(device=device, backend=remote_emulator_backend)
config = SolverConfig(solving=quantum_config)
solver = Solver(instance, config)
solution = solver.solve()
print(analysis.to_dataframe([solution]))

We show below an example of solving a QUBO using Tabu search. More information on classical approaches can be found in the Classical solvers section of the documentation (external).

from qubosolver import (
ClassicalSolvingConfig,
Instance,
Solver,
SolverConfig,
analysis,
matrix,
)
Q = matrix.tensor(
[
[-0.2, 0.0, 1.0],
[0.0, -1.0, 1.5],
[1.0, 1.5, -0.1],
]
)
instance = Instance(Q)
# Create a SolverConfig with a classical solver.
classical_config = ClassicalSolvingConfig(
algorithm="tabu_search",
time_limit=10.0,
)
config = SolverConfig(solving=classical_config)
solver = Solver(instance, config)
solution = solver.solve()
print(analysis.to_dataframe([solution]))