This quantum kernel methods tutorial gives you a reusable workflow for testing whether a quantum feature map improves classification: establish a classical SVM baseline, construct and inspect the quantum kernel matrix, evaluate it on held-out data, and check how encoding choices and hardware noise affect the result.
Overview
A quantum support vector machine (QSVM) uses a quantum circuit to define a similarity function between data points. Instead of training a parameterized classifier end to end, the workflow usually computes a kernel matrix and passes it to a classical support vector machine. The quantum component supplies the feature-space similarity; the classical optimizer handles the SVM training.
For input vectors x and z, a fidelity-style quantum kernel commonly measures how closely the encoded states overlap:
K(x, z) = |<phi(x) | phi(z)>|^2
Here, phi is a quantum feature map that turns classical data into a quantum state. A projected quantum kernel takes a different route: it compares selected classical features extracted from quantum measurement results, rather than estimating a full state overlap. Both approaches can be useful, but neither is automatically better than a well-chosen classical kernel.
The right question is not “Is a quantum kernel quantum?” It is “Does this encoding produce a useful, stable similarity structure for this dataset under the available computational and hardware constraints?” Treat the quantum kernel as an experimental model component and compare it against strong baselines.
Fidelity and projected quantum kernels
| Criterion | Fidelity kernel | Projected quantum kernel |
|---|---|---|
| Similarity source | Estimated overlap or fidelity between encoded states | Distance or similarity between measured quantum features |
| Typical implementation | Overlap, inverse-feature-map, or related circuit evaluations | One or more measurement circuits followed by classical feature comparison |
| Strength | Directly represents similarity in the chosen quantum state space | Can expose interpretable measured features and offer flexible projections |
| Risk | Kernel estimation can require substantial circuit execution | Results depend on projection choices and measurement variance |
| Best use | Testing whether state overlap captures class structure | Testing whether selected observables create a useful intermediate representation |
The table is a design guide, not a ranking. Compare both against classical linear and nonlinear kernels using identical data splits and evaluation metrics.
Checklist by scenario
Before choosing a quantum kernel
- Define the task: confirm that the problem is supervised classification or another kernel-compatible task. Record the target labels, class balance, evaluation metric, and acceptable error trade-offs.
- Build a classical reference: evaluate at least a linear SVM and a classical nonlinear kernel such as an RBF kernel. A quantum method needs to beat or complement these references, not merely produce a working prediction.
- Reduce and scale features: remove leakage, handle missing values, and scale each feature using statistics from the training split only. Quantum angles are sensitive to numerical ranges, so document the mapping from normalized values to circuit parameters.
- Set a qubit budget: decide how many features will be encoded directly, whether features will be grouped across circuit layers, and whether a classical reduction step is required. Do not assume that adding more features improves the kernel.
When designing the feature map
- Choose an encoding that matches the data type. Angle encoding is often a practical starting point for continuous, reduced-dimensional data; basis or amplitude encodings require different assumptions and resource trade-offs.
- Start with a shallow circuit and a small number of entangling layers. Increase expressivity only when validation results justify the added depth.
- Test more than one entanglement pattern when connectivity and circuit depth matter. Keep the feature map fixed while comparing models so that improvements can be attributed to the kernel rather than changing multiple variables.
- Record the circuit definition, feature ordering, scaling rule, qubit count, depth, shots, backend, and software versions. These details are part of the model specification.
When implementing the experiment
Framework APIs change, so treat the following as a conceptual implementation template rather than a copy-and-run promise. Names for primitives, samplers, kernel classes, batching, and autodiff support should be checked against the installed version of Qiskit Machine Learning, PennyLane, or another selected SDK.
# Conceptual quantum-kernel SVM workflow
X_train, X_test, y_train, y_test = split_data(X, y, stratify=y)
scaler = fit_scaler(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
feature_map = build_feature_map(
n_qubits=n_features,
entanglement="chosen_pattern",
depth="small"
)
quantum_kernel = build_kernel(
feature_map=feature_map,
execution_backend="simulator_or_hardware",
shots="explicit_if_sampling"
)
K_train = quantum_kernel.evaluate(X_train, X_train)
K_test = quantum_kernel.evaluate(X_test, X_train)
assert is_approximately_symmetric(K_train)
inspect_kernel(K_train)
classifier = train_svm(kernel="precomputed", K=K_train, labels=y_train)
predictions = classifier.predict(K_test)
report_metrics(y_test, predictions)
For a precomputed SVM, the test matrix must align with the convention expected by the classifier: rows represent test examples and columns represent training examples. Check this explicitly; transposed or mismatched matrices can produce misleading failures.
When validating the model
- Inspect the training kernel matrix before fitting. Check its dimensions, symmetry, diagonal values, finite entries, duplicate rows, and value range.
- Compare the quantum kernel with linear, polynomial, and RBF SVM baselines under the same split or cross-validation procedure.
- Use a held-out test set only after feature-map and hyperparameter decisions are complete. If the dataset is small, use carefully controlled cross-validation and report the split strategy.
- Repeat the experiment with more than one seed or split where practical. A single favorable split is not sufficient evidence that the feature map helps.
- Measure execution cost as well as predictive quality. Track circuit evaluations, shots, runtime, depth, and backend details so that a claimed improvement has operational context.
What to double-check
Kernel validity and conditioning
An ideal kernel matrix is symmetric and positive semidefinite. Sampling noise, device noise, numerical error, or an inconsistent kernel-evaluation procedure can produce an apparently indefinite matrix. Inspect eigenvalues and the symmetry error rather than assuming the matrix is valid because the code completed.
If small negative eigenvalues arise from numerical noise, a documented regularization or projection step may be appropriate. Large or systematic violations require diagnosis first: verify that training and training evaluations use the same feature map, measurement settings, ordering, and shot configuration. Avoid silently repairing a matrix and presenting the repaired result as an unqualified quantum advantage.
Encoding and scaling
Feature scaling is part of the quantum model. If one feature produces angles far outside the intended range while another occupies only a narrow interval, the circuit may overemphasize one dimension or become difficult to compare across runs. Fit preprocessing on the training data, preserve the transformation for inference, and document whether values are standardized, bounded, clipped, or otherwise transformed.
For larger datasets, kernel construction can become the main bottleneck because every pair of examples may require one or more circuit evaluations. Consider a smaller representative training set, batching where the SDK supports it, approximate methods, or a projected kernel. These are engineering choices to benchmark, not automatic fixes.
Noise and backend behavior
Start with an ideal or high-fidelity simulator to verify the workflow, then test a noise model or hardware backend. Compare the resulting kernel matrix, classifier metrics, and stability—not only the final accuracy. Readout error and finite-shot fluctuations can alter similarities enough to affect the SVM decision boundary.
Keep noise mitigation separate from the baseline experiment. If you apply readout correction, zero-noise extrapolation, or another technique, record its settings and compare it with the unmitigated result. For reproducibility, retain job metadata and backend configuration alongside the trained model.
Common mistakes
- Skipping the classical baseline: A quantum kernel result has little meaning without comparable linear and nonlinear classical references.
- Using the test set during feature-map selection: This turns model selection into leakage and overstates generalization.
- Encoding too many raw features: High-dimensional input can force deeper circuits or arbitrary compression. Establish a compact, justified representation first.
- Confusing training performance with usefulness: A kernel that separates the training examples well may still generalize poorly.
- Ignoring matrix orientation: Precomputed SVM interfaces typically require a precise relationship between training and test kernel matrices.
- Treating every indefinite matrix as harmless: Diagnose evaluation inconsistencies and noise before applying a mathematical correction.
- Changing several variables at once: If qubit count, scaling, entanglement, shots, and classifier settings all change together, you cannot identify what caused the result.
- Assuming simulator results predict hardware results: Hardware noise, connectivity, compilation, and sampling can change the effective kernel.
When to revisit
Revisit this checklist whenever the dataset, feature engineering pipeline, SDK, primitive interface, backend, or feature-map implementation changes. Framework updates can affect kernel APIs, batching, autodiff behavior, sampler or primitive requirements, and compatibility between circuit objects and machine-learning components. Confirm the installed versions and rerun a small validation experiment before relying on an older notebook.
Also revisit the workflow before a new planning or pilot cycle. Recheck the classical baselines, data split, encoding range, kernel-matrix diagnostics, execution budget, and hardware-noise assumptions. The following compact release gate is practical:
- Baseline metrics and splits are recorded.
- Preprocessing is fitted only on training data.
- The feature map and qubit budget are documented.
- Training and test kernel matrices have the expected shapes.
- Symmetry, eigenvalues, diagonal values, and finite entries have been checked.
- Quantum and classical models use the same evaluation protocol.
- Simulator and hardware or noise-model results are clearly separated.
- Runtime, shots, circuit depth, and backend metadata are saved.
Use the quantum support vector classifier when the feature-map hypothesis is testable and the experiment can be compared fairly. If it does not improve validation performance, robustness, or a clearly defined operational objective, the classical model may remain the better engineering choice. For supporting workflows, see the guides on quantum machine-learning data pipelines, quantum data encoding methods, and quantum machine-learning experiment evaluation.