Estimators#
VQC Classifier#
- class VQCClassifier(n_qubits: int = 4, feature_map: FeatureMap | None = None, ansatz=None, measurement=None, optimizer='adam', learning_rate=0.01, n_iter=100, batch_size=None, random_state=None, device='default.qubit', verbose=False, log_every=10)[source]#
Bases:
QuantumEstimator,ClassifierMixinVariational Quantum Classifier.
A variational quantum classifier (VQC) is a quantum machine learning model that combines data encoding (feature map), a parameterized quantum circuit (ansatz), and measurement to perform binary or multi-class classification. The model is trained using gradient-based optimization.
This implementation follows the circuit-centric quantum classifier approach of Schuld et al. (2018, arXiv:1804.00633) and the broader variational quantum algorithm (VQA) paradigm. For multi-class problems, it uses a one-vs-rest (OvR) strategy.
The training process: 1. Encode classical data into quantum states using the feature map 2. Apply parameterized ansatz circuit 3. Measure expectation value (typically Pauli-Z on first qubit) 4. Minimize binary cross-entropy loss via gradient descent
The gradients are computed using the parameter shift rule, which provides exact gradients on quantum hardware (Mitarai et al., 2018, arXiv:1803.00745).
- Parameters:
n_qubits (int, default=4) – Number of qubits.
feature_map (FeatureMap, optional) – Data encoding. Default: AngleFeatureMap()
ansatz (Ansatz, optional) – Parameterized circuit. Default: StronglyEntanglingAnsatz(layers=2)
measurement (Measurement, optional) – Measurement operator. Default: PauliZExpectation()
optimizer (str or callable, default="adam") – Optimizer (adam or sgd from PennyLane).
learning_rate (float, default=0.01) – Learning rate for the optimizer.
n_iter (int, default=100) – Number of optimization iterations.
batch_size (int, optional) – Batch size for training. If None, uses full batch.
random_state (int, optional) – Random seed for weight initialization.
device (str, default="default.qubit") – PennyLane device for simulation.
- classes_#
Class labels.
- Type:
ndarray
- n_features_in_#
Number of features seen during fit.
- Type:
int
- n_classes_#
Number of classes.
- Type:
int
- model_#
The trained quantum model (binary case) or None (multiclass OvR).
- Type:
VariationalModel, optional
- estimators_#
One-vs-rest classifiers for multi-class.
- Type:
list[VQCClassifier]
- loss_history_#
Training loss per iteration.
- Type:
list[float]
- qnode_#
Cached QNode for inference (binary case only).
- Type:
callable, optional
- weights_#
Trained weights (binary case).
- Type:
ndarray, optional
References
Schuld, Bocharov, Svore, and Wiebe, “Circuit-centric quantum classifiers,” arXiv:1804.00633, 2018.
Mitarai et al., “Quantum circuit learning,” Phys. Rev. A 98, 032309, 2018. arXiv:1803.00745.
QSVC#
- class QSVC(*, n_qubits: int = 4, feature_map: FeatureMap | None = None, device: str = 'default.qubit', C: float = 1.0, shrinking: bool = True, probability: bool = False, tol: float = 0.001, cache_size: float = 200, class_weight=None, verbose: bool = False, max_iter: int = -1, decision_function_shape: str = 'ovr', break_ties: bool = False, random_state: int | None = None, kernel: str = 'precomputed')[source]#
Bases:
QuantumEstimator,ClassifierMixinQuantum Support Vector Classifier.
A support vector machine that uses a quantum kernel to implicitly map data into a high-dimensional quantum feature space. The kernel is computed as the fidelity (squared inner product) between quantum- encoded states, following the quantum kernel method of Havlíček et al. (2019, arXiv:1904.01567).
The implementation: 1. Encodes data using a quantum feature map 2. Computes the quantum kernel matrix (Gram matrix) 3. Trains a classical SVM with precomputed kernel
This hybrid approach leverages quantum computers to generate kernel matrices that may be classically intractable to compute, while using well-established classical SVM training.
- Parameters:
n_qubits (int, default=4) – Number of qubits for the quantum circuit.
feature_map (FeatureMap, optional) – Quantum feature map for data encoding. Default: AngleFeatureMap()
device (str, default="default.qubit") – PennyLane device for simulation.
C (float, default=1.0) – Regularization parameter. The strength of regularization is inversely proportional to C.
shrinking (bool, default=True) – Whether to use the shrinking heuristic.
probability (bool, default=False) – Whether to enable probability estimates.
tol (float, default=1e-3) – Tolerance for stopping criterion.
cache_size (float, default=200) – Kernel cache size in MB.
class_weight (dict or "balanced", optional) – Class weights for imbalanced datasets.
verbose (bool, default=False) – Enable verbose output.
max_iter (int, default=-1) – Maximum number of iterations (-1 for no limit).
decision_function_shape ({"ovr", "ovo"}, default="ovr") – Decision function shape (one-vs-rest or one-vs-one).
break_ties (bool, default=False) – Whether to break ties according to confidence.
random_state (int, optional) – Random seed.
- classes_#
Class labels.
- Type:
ndarray
- n_features_in_#
Number of features seen during fit.
- Type:
int
- n_classes_#
Number of classes.
- Type:
int
- kernel_#
The fitted quantum kernel.
- Type:
- X_train_#
Training data.
- Type:
ndarray
- K_train_#
Training kernel matrix.
- Type:
ndarray
- svc_#
The underlying scikit-learn SVM classifier.
- Type:
SVC
References
Havlicek et al., “Supervised learning with quantum-inspired kernel,” arXiv:1904.01567, 2019.
Scholkopf and Smola, “Learning with Kernels,” MIT Press, 2002.
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') QSVC#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.- Returns:
self – The updated object.
- Return type:
object
VQC Regressor#
- class VQCRegressor(n_qubits: int = 4, feature_map: FeatureMap | None = None, ansatz=None, measurement=None, optimizer='adam', learning_rate=0.01, n_iter=100, batch_size=None, random_state=None, device='default.qubit', verbose=False, log_every=10)[source]#
Bases:
QuantumEstimator,RegressorMixinVariational Quantum Regressor.
A variational quantum model for regression tasks that uses a quantum circuit to map inputs to continuous outputs. The model is trained to minimize mean squared error (MSE) using gradient-based optimization.
The implementation follows the variational quantum algorithm (VQA) paradigm where: 1. Classical features are encoded into quantum states (feature map) 2. A parameterized ansatz circuit processes the encoded states 3. Measurement (typically Pauli-Z expectation) provides continuous output 4. The target variable is scaled to match the measurement range [-1, 1] 5. Gradients computed via parameter shift rule optimize the parameters
This approach extends quantum neural networks to regression tasks as described in Schuld et al. (2018, arXiv:1804.00633) and Mitarai et al. (2018, arXiv:1803.00745).
- Parameters:
n_qubits (int, default=4) – Number of qubits in the quantum circuit.
feature_map (FeatureMap, optional) – Data encoding circuit. Default: AngleFeatureMap()
ansatz (Ansatz, optional) – Parameterized circuit. Default: StronglyEntanglingAnsatz(layers=2)
measurement (Measurement, optional) – Measurement operator. Default: PauliZExpectation()
optimizer (str or callable, default="adam") – Optimizer for training (adam or sgd).
learning_rate (float, default=0.01) – Learning rate.
n_iter (int, default=100) – Number of optimization iterations.
batch_size (int, optional) – Batch size for training.
random_state (int, optional) – Random seed.
device (str, default="default.qubit") – PennyLane device.
- n_features_in_#
Number of features seen during fit.
- Type:
int
- weights_#
Trained circuit parameters.
- Type:
ndarray
- feature_map_#
Fitted feature map.
- Type:
- ansatz_#
Ansatz instance.
- Type:
Ansatz
- scaler_#
Fitted scaler for target variable.
- Type:
StandardScaler
- loss_history_#
Training loss per iteration.
- Type:
list[float]
- qnode_#
Cached QNode for inference.
- Type:
callable
References
Schuld, Bocharov, Svore, and Wiebe, “Circuit-centric quantum classifiers,” arXiv:1804.00633, 2018.
Mitarai et al., “Quantum circuit learning,” Phys. Rev. A 98, 032309, 2018. arXiv:1803.00745.