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 ¶
- func KernelEntry(cfg KernelConfig, x1, x2 []float64) (float64, error)
- func KernelMatrix(ctx context.Context, cfg KernelConfig, dataX [][]float64) ([][]float64, error)
- func Predict(cfg Config, params []float64, dataX [][]float64) ([]int, error)
- type Config
- type FeatureMap
- type KernelConfig
- type Result
- type RotationType
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 ¶
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].
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 ¶
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 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 )