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.0.tar.gz (11.9 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.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qaoalib-0.3.0.tar.gz
  • Upload date:
  • Size: 11.9 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.0.tar.gz
Algorithm Hash digest
SHA256 5f62c9c499a4cab6b6567a46126b311b2951cf5b3662d2e0e5b4fdfbec81d164
MD5 b462ac2761d9d2be6af43617737942fe
BLAKE2b-256 6e524ca88f489ea555556df1c63f60e2a31568d2c3c5fce7a7e8f90f9e7bdeb2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qaoalib-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf0b9588ff7f77ed823224a38666bd0a4987aa765584a6f4ed71d67d1cec2b78
MD5 f5cb693f633df28a03a4c0ef6df5dd97
BLAKE2b-256 83e451ac9b90e31e1201cd3757af427a5b7375a3b12b228ad99c718bf4f674a4

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