ampest

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 ampest implements Quantum Amplitude Estimation.

Standard AE uses Quantum Phase Estimation on the Grover iterate Q = A S_0 A^dag S_f to estimate the amplitude a = sin(pi * theta) of the "good" subspace prepared by a state-preparation circuit A.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// StatePrep is the circuit A that prepares the state whose amplitude
	// we want to estimate. It acts on NumQubits qubits.
	StatePrep *ir.Circuit
	// Oracle marks the "good" states by flipping their phase.
	Oracle grover.Oracle
	// NumQubits is the number of working qubits used by StatePrep.
	NumQubits int
	// NumPhaseBits is the number of ancilla qubits controlling precision.
	NumPhaseBits int
	// Shots is the number of measurement shots. Default: 1024.
	Shots int
}

Config specifies parameters for standard Amplitude Estimation.

type IterativeConfig

type IterativeConfig struct {
	// StatePrep is the circuit A that prepares the state.
	StatePrep *ir.Circuit
	// Oracle marks good states by flipping their phase.
	Oracle grover.Oracle
	// NumQubits is the number of working qubits.
	NumQubits int
	// MaxIters is the maximum number of doubling rounds. Default: 10.
	MaxIters int
	// ConfLevel is the confidence level (unused in statevector mode,
	// reserved for shot-based implementations). Default: 0.05.
	ConfLevel float64
	// Shots is the number of measurement shots (unused in the current
	// statevector-based implementation). Default: 1024.
	Shots int
}

IterativeConfig specifies parameters for Iterative Amplitude Estimation.

type IterativeResult

type IterativeResult struct {
	// Amplitude is the estimated amplitude a.
	Amplitude float64
	// Probability is a^2.
	Probability float64
	// NumIters is the number of refinement rounds performed.
	NumIters int
	// ConfInterval is a conservative [lo, hi] confidence interval on the amplitude.
	ConfInterval [2]float64
}

IterativeResult holds the output of Iterative Amplitude Estimation.

func RunIterative

func RunIterative(ctx context.Context, cfg IterativeConfig) (*IterativeResult, error)

RunIterative executes Iterative Amplitude Estimation.

The algorithm uses statevector simulation to compute the "good" subspace probability at increasing Grover powers. For k=0, it runs A alone; for k=2^i, it runs A*Q^k. The good-state probability follows P_good(k) = sin^2((2k+1)*theta) where a = sin(theta) is the target amplitude. Higher Grover powers amplify small differences in theta, enabling progressively finer estimates.

Good states are identified by applying the oracle to the statevector and detecting which amplitudes change sign.

type Result

type Result struct {
	// Circuit is the full QPE-on-Grover circuit that was executed.
	Circuit *ir.Circuit
	// Amplitude is the estimated amplitude a = sin(pi * theta).
	Amplitude float64
	// Probability is a^2.
	Probability float64
	// Phase is the raw phase theta from QPE.
	Phase float64
	// Counts is the measurement histogram.
	Counts map[string]int
}

Result holds the output of standard Amplitude Estimation.

func Run

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

Run executes standard Quantum Amplitude Estimation.

The algorithm builds the Grover iterate Q = A * S_0 * A^dag * S_f, applies QPE to estimate the phase theta of Q, then computes amplitude a = sin(pi * theta).

Jump to

Keyboard shortcuts

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