VQCRegressor#

The VQCRegressor is a variational quantum regressor.

class VQCRegressor(n_qubits: int = 4, encoder: BaseEncoder | None = None, ansatz: BaseAnsatz | None = None, optimizer: str | Callable = 'adam', learning_rate: float = 0.01, n_iter: int = 100, batch_size: int | None = None, random_state: int | None = None, device: str = 'default.qubit')[source]#

Bases: QuantumEstimator, RegressorMixin

Variational Quantum Regressor.

A quantum regressor that uses a parameterized quantum circuit to make continuous predictions. Follows the scikit-learn API.

This implements the variational quantum regressor from:

  • Mitarai et al. (2018), “Quantum circuit learning” (arXiv:1803.00745). Introduces parameterized quantum circuits for continuous prediction using Pauli expectation values and MSE loss.

  • Farhi & Neven (2018), “Classification with Quantum Neural Networks on Near Term Processors” (arXiv:1802.06002). Framework for variational quantum circuits with Pauli-Z measurements.

  • Schuld, Bocharov, Svore & Wiebe (2018), “Circuit-centric quantum classifiers” (arXiv:1804.00633). Circuit-centric approach applicable to regression with MSE loss.

Mathematically, for input \(\mathbf{x}\):

\[f(\mathbf{x}) = \langle \phi(\mathbf{x}) | U_{\text{ansatz}}^{\dagger}(\mathbf{w}) Z_0 U_{\text{ansatz}}(\mathbf{w}) |\phi(\mathbf{x}) \rangle\]

The target values are scaled to [-1, 1] and training minimizes MSE:

\[\mathcal{L} = \frac{1}{N} \sum_{i=1}^N (y_i^{\text{scaled}} - f(\mathbf{x}_i))^2\]
Parameters:
  • n_qubits (int, default=4) – Number of qubits in the quantum circuit.

  • encoder (BaseEncoder, optional) – Data encoding circuit. If None, defaults to AngleEncoder().

  • ansatz (BaseAnsatz, optional) – Parameterized circuit. If None, defaults to StronglyEntanglingAnsatz(layers=2).

  • optimizer ({"adam", "sgd"} or callable, default="adam") – Optimization algorithm.

  • 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 reproducibility.

  • device (str, default="default.qubit") – PennyLane device to use.

n_features_in_#

Number of features seen during fit.

Type:

int

weights_#

Trained circuit parameters.

Type:

ndarray

encoder_#

Fitted encoder.

Type:

BaseEncoder

ansatz_#

Fitted ansatz.

Type:

BaseAnsatz

scaler_#

Fitted scaler for y values.

Type:

StandardScaler

loss_history_#

Training MSE at each iteration.

Type:

list[float]

qnode_#

Cached QNode for inference, set after fit(). Advanced users can call this directly for debugging or custom measurements.

Type:

callable

fit(X, y)[source]#

Fit the quantum regressor.

Parameters:
  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,)) – Target values.

Returns:

self – Returns the fitted estimator.

Return type:

VQCRegressor

predict(X)[source]#

Predict continuous target values for samples.

Parameters:

X (array-like, shape (n_samples, n_features)) – Input samples.

Returns:

y – Predicted target values.

Return type:

ndarray, shape (n_samples,)

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') VQCRegressor#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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_weight parameter in score.

Returns:

self – The updated object.

Return type:

object

The regressor uses MSE loss and StandardScaler for target scaling. Output is Pauli-Z expectation value from the final quantum circuit.