Skip to main content

A package for QAOA Maxcut calculations

Project description

qaoalib

Implementations of VQA simulations for combinatorial optimization (mainly with graph and Max-cut).

v0.2 works towards adapting the circuit simulations with new Qiskit primitives: Sampler and Estimator (starting from Qiskit 1.0).

How to install

You can install from the PyPI:

pip install --upgrade qaoalib

Usage

Solving Max-cut with VQE:

import networkx as nx
from qaoalib.solver import VQE
from qiskit_optimization.applications import Maxcut

G = nx.random_regular_graph(3, 6) # 3-regular graph wtih 6 nodes
qp = Maxcut(G).to_quadratic_program()
ansatz = # some preferred ansatz
solver = VQE(qp, ansatz)
result = solver.solve()
print(result)

Usage (legacy)

Calculate Max-cut expectation with Qmc or QmcFastKron (faster version):

import networkx as nx
from qaoalib.qaoa import Qmc, QmcFastKron

G = nx.fast_gnp_random_graph(10, 0.5)  # Random graph with 10 nodes
params = [0.2, 0.4, 0.3, 0.5]          # 4 params, depth = 2

qmc = Qmc(G, params) # or QmcFastKron(G, params)
qmc.run()
print(qmc.expectation)

Plot landscapes of the QAOA Max-cut expectation function:

import networkx as nx
from qaoalib.qaoa.landscape import HybridFast

G = nx.fast_gnp_random_graph(10, 0.5)
prev_params = [0.1, 0.2] # previous parameters (gamma1, beta1)

ins = HybridFast(G, prev_params) # plots the landscape wrt gamma2 and beta2 with previous parameters given.
ins.create_grid()
ins.show_landscape()

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

qaoalib-0.3.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

qaoalib-0.3.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file qaoalib-0.3.1.tar.gz.

File metadata

  • Download URL: qaoalib-0.3.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for qaoalib-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dbb573190f67218bdabcfcac9c7b6008ad1cd36ec1ffa399724cf4a2e2490b07
MD5 c98418075229cdc96970f22fef123ebe
BLAKE2b-256 9079ef4dfae5846b1390c6f434bd9438c4ce5a2edba253935e04ef93136e08d4

See more details on using hashes here.

File details

Details for the file qaoalib-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: qaoalib-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for qaoalib-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acb0c8930fa235adbac2a27d00d9263ff34aee8e939eb9c153f61214a8d13423
MD5 b71fbcd7e4ed4281cd29ce78fb6f394a
BLAKE2b-256 fd961e6ce2b272123a7da6f76d7759236059f40fe8b9b52858b77e0c6bce9b78

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