Skip to main content

an open-source Python library that enables developers to implement combinatorial optimization models and execute them seamlessly on multiple classical and quantum devices using different quantum algorithms.

Project description

QPLEX

⚠️ This library is currently under development.

QPLEX is an open-source Python library that enables developers to implement combinatorial optimization models and execute them seamlessly on multiple classical and quantum devices (using different quantum algorithms). Our solution automatically handles the adaptation of the optimization model to the specific instructions of the target quantum device's SDK. The library supports unconstrained and constrained problems, as well as binary, discrete, and continuous variables. QPLEX uses DOcplex as a modeling API allowing the creation of optimization models using the exact same syntax as this base library.

The motivation and technical details about this project are presented in the following paper: https://arxiv.org/abs/2307.14308

Getting Started

QPLEX is not a self-managed solution, hence each user has to bring their own quantum provider access token in order to use quantum devices. All tokens must be associated with environment variables within the system.

For using devices from IBM Quantum the following env variable has to be created: IBMQ_API_TOKEN

For using devices from D-Wave the following env variable has to be created: D-WAVE_API_TOKEN

In Amazon Braket's case the user must have the AWS CLI configured properly and should have access to the AWS Braket service in the cloud. Follow this link for more information.

The QModel module provides all the necessary functionality for creating and executing a combinatorial optimization problem. The following example illustrates how to build and run the knapsack problem with QPLEX. More examples are provided within the "examples" folder.

from qplex import QModel
from qplex.model import Options
# Problem definition
weights = [4, 2, 5, 4, 5, 1, 3, 5]
values = [10, 5, 18, 12, 15, 1, 2, 8]
max_weight = 15
n = len(values)

# Build the model
knapsack_model = QModel('knapsack')
x = knapsack_model.binary_var_list(n, name="x")
knapsack_model.add_constraint(
    sum(weights[i] * x[i] for i in range(n)
        ) <= max_weight)
obj_fn = sum(values[i] * x[i] for i in range(n))
knapsack_model.set_objective('max', obj_fn)

It is worth noting that the syntax used by QPLEX is exactly the same as the one used by DOcplex. This facilitates the integration of our solution into classical workflows.

QPLEX provides a new functionality within the solve method; it allows the user to specify how the problem will be executed, either through classical or quantum resources. If nothing is passed to the method, classical resources will be used.

When calling the solve method with "quantum" resources, the software will automatically select the most appropriate algorithm and quantum hardware backend for the defined optimization model. However, the users have the option to specify, as kwargs, which algorithm, provider, and backend they want to use for the execution.

The following is the complete list of kwargs supported for the solve method:

Argument Description Default value
provider The quantum hardware provider "d-wave"
backend The specific quantum device Calculated
algorithm The quantum algorithm to use "qaoa"
ansatz The ansatz circuit for VQE Layered Ansatz
p The p value for the QAOA algorithm 2
layers The number of layers for the VQE algorithm 2
optimizer The classical optimizer "cobyla"
tolerance The tolerance value for the optimizer 1e − 10
max_iter The maximum number of optimizer iterations 1000
penalty The penalty constant used for the QUBO Calculated
shots The total number of shots 1024
seed The execution random seed 1

Supported Algorithms

QPLEX currently supports the following algorithms:

  • Quantum Annealing (QA)
  • The Variational Quantum Eigensolver (VQE)
  • The Quantum Approximate Optimization Algorithm (QAOA)

Each of these has its own set of hyperparameters that can be passed as kwargs to the solve method. Refer to the previous table for the complete list.

execution_params = {
        "provider": "braket",
        "backend": "simulator",
        "algorithm": "qaoa",
        "p": 4,
        "max_iter": 500,
        "shots": 10000
    }
knapsack_model.solve(solver='quantum', Options(**execution_params))

Algorithms to be supported in the future:

  • The Quantum Alternating Operator Ansatz (QAOAnsatz)
  • Warm-start QAOA (WSQAOA)
  • CVaR QAOA (CVar)

Supported Quantum Providers

The quantum providers supported by the library are:

  • D-Wave
  • IBMQ
  • AWS Braket

Each of these has its own set of backends (i.e., quantum computers) and can be selected by providing a value to the "backend" key-word argument in the solve method. If no argument is specified, the library will automatically select the backend with the shortest queue and enough qubits to handle the formulation. Additionally, it is possible to use the argument simulator as a backend to use each provider's local simulator.

knapsack_model.solve(solver='quantum', provider='ibmq', backend='ibm_perth')
knapsack_model.solve(solver='quantum', provider='braket', backend='device/qpu/ionq/Harmony')

Contributing

If you are interested in contributing, please check the issues page and select the one you want to address. Afterward, fork the repository and create a new branch with the issue's number. Make sure to push all you changes in a single commit with a descriptive message. If the issue description is not clear, feel free to create a comment requesting more information.

Feature requests, bug reports and feedback comments are highly appreciated! 😃

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uvic_qplex-0.1.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uvic_qplex-0.1.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file uvic_qplex-0.1.2.tar.gz.

File metadata

  • Download URL: uvic_qplex-0.1.2.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uvic_qplex-0.1.2.tar.gz
Algorithm Hash digest
SHA256 283b7f1c039272e534da26c3796cf14f83cb8f0f2472762f6e6cee2c8b94bd30
MD5 33b9bc01243b4539a10260b513dd3676
BLAKE2b-256 2f043bf16403485b89a3c3f64cbb1659582ba118e97b1e5a00e0aa9850281e17

See more details on using hashes here.

File details

Details for the file uvic_qplex-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: uvic_qplex-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uvic_qplex-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97eb19adbea2752cd0d8d8866fbb79d824fdb645a61c0851d7e067b362b75d1b
MD5 658042128dd24433ddd7ab71405231ed
BLAKE2b-256 e17c127db34b8874bea90b52005f0d9781a3806650293b9df1d3fe44a1175d71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page