qaoa

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package qaoa implements the Quantum Approximate Optimization Algorithm.

QAOA solves combinatorial optimization problems by alternating cost and mixer layers parameterized by gamma and beta angles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxCutHamiltonian

func MaxCutHamiltonian(edges [][2]int, numQubits int) (pauli.PauliSum, error)

MaxCutHamiltonian encodes a graph as a cost Hamiltonian for the MaxCut problem. C = 0.5 * sum_{(i,j) in edges} (I - Z_i*Z_j) Minimizing -C maximizes the cut. The returned Hamiltonian is negated so that minimization yields the maximum cut.

Types

type Config

type Config struct {
	// CostHamiltonian is the objective to minimize.
	CostHamiltonian pauli.PauliSum
	// MixerHamiltonian is the mixer operator. Nil uses the default X-mixer.
	MixerHamiltonian *pauli.PauliSum
	// Layers is the number of QAOA layers (p). Default: 1.
	Layers int
	// Optimizer is the classical optimization method.
	Optimizer optim.Optimizer
	// InitialParams are the starting [gamma_1..gamma_p, beta_1..beta_p]. Nil means heuristic.
	InitialParams []float64
	// Shots for sampling the best bitstring. Default: 1024.
	Shots int
}

Config specifies the QAOA problem and solver.

type Result

type Result struct {
	OptimalValue  float64
	OptimalParams []float64
	BestBitstring string
	BestCost      float64
	NumIters      int
	Converged     bool
}

Result holds QAOA output.

func Run

func Run(ctx context.Context, cfg Config) (*Result, error)

Run executes QAOA.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL