vqc

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package vqc implements the Variational Quantum Classifier.

VQC trains a parameterized quantum circuit to classify classical data. Each sample is encoded via a feature map, then processed by a variational ansatz whose parameters are optimized to minimize classification loss.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KernelEntry

func KernelEntry(cfg KernelConfig, x1, x2 []float64) (float64, error)

KernelEntry computes the fidelity |<0|V†(x2)·V(x1)|0>|² for two data points.

func KernelMatrix

func KernelMatrix(ctx context.Context, cfg KernelConfig, dataX [][]float64) ([][]float64, error)

KernelMatrix computes the pairwise quantum kernel matrix for the given data. K[i][j] = |<0|V†(x_j)·V(x_i)|0>|² where V is the feature map circuit. The matrix is symmetric: K[i][j] = K[j][i].

func Predict

func Predict(cfg Config, params []float64, dataX [][]float64) ([]int, error)

Predict classifies each sample in dataX using trained parameters. Returns a slice of predicted labels (0 or 1).

Types

type Config

type Config struct {
	// NumQubits is the number of qubits in the circuit.
	NumQubits int
	// FeatureMap encodes classical features into the quantum state.
	FeatureMap FeatureMap
	// Ansatz is the parameterized circuit template.
	Ansatz ansatz.Ansatz
	// Optimizer is the classical optimization method.
	Optimizer optim.Optimizer
	// Gradient is the gradient function. Nil means gradient-free.
	Gradient optim.GradientFunc
	// TrainX holds the training feature vectors.
	TrainX [][]float64
	// TrainY holds the training labels (0 or 1).
	TrainY []int
	// InitialParams are the starting parameters. Nil means zeros.
	InitialParams []float64
}

Config specifies the VQC problem and solver.

type FeatureMap

type FeatureMap func(b *builder.Builder, features []float64, qubits []int)

FeatureMap encodes classical data into a quantum state.

func AmplitudeEmbedding

func AmplitudeEmbedding() FeatureMap

AmplitudeEmbedding returns a feature map that encodes a feature vector into quantum state amplitudes using the StatePrep gate. Features are zero-padded to length 2^n and normalized to unit L2 norm.

func AngleEmbedding

func AngleEmbedding(rot RotationType) FeatureMap

AngleEmbedding returns a feature map that encodes each feature as a rotation angle on the corresponding qubit. If there are fewer features than qubits, the remaining qubits receive no gate.

func ZFeatureMap

func ZFeatureMap(depth int) FeatureMap

ZFeatureMap returns a feature map that applies H and RZ(feature) on each qubit. The encoding is repeated depth times.

func ZZFeatureMap

func ZZFeatureMap(depth int) FeatureMap

ZZFeatureMap returns a feature map like ZFeatureMap but with entangling RZZ(f_i * f_j) gates between adjacent qubit pairs.

type KernelConfig

type KernelConfig struct {
	// NumQubits is the number of qubits used by the feature map.
	NumQubits int
	// FeatureMap encodes classical features into a quantum state.
	FeatureMap FeatureMap
}

KernelConfig specifies the quantum kernel parameters.

type Result

type Result struct {
	OptimalParams []float64
	TrainAccuracy float64
	NumIters      int
	Converged     bool
}

Result holds VQC output.

func Run

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

Run executes the VQC training loop.

type RotationType

type RotationType int

RotationType specifies the rotation gate for AngleEmbedding.

const (
	// RotRX uses RX gates (default, matches PennyLane).
	RotRX RotationType = iota
	// RotRY uses RY gates.
	RotRY
	// RotRZ uses RZ gates.
	RotRZ
)

Jump to

Keyboard shortcuts

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