DataBindingMixin

class DataBindingMixin[source]

Bases: object

Shared data-axis behavior for VQA subclasses that fan a feature batch out.

Mixed in before VariationalQuantumAlgorithm so its _build_cost_pipeline() cooperatively wraps the base one (mirroring how ObservableMeasuringMixin sits ahead of QuantumProgram). It owns the orchestration common to QNN and CustomVQA; each subclass still constructs the _data_symbols / _weight_symbols split and the _composed_circuit itself and sets the attributes build_data_binding_stage reads.

The mixin declares no __init__: the data-binding state is populated during each subclass’s own construction, so there is no init ordering to coordinate.

Methods Summary

predict(features[, params, return_scores])

Predict for a feature batch with trained weights.

Methods Documentation

predict(features, params=None, *, return_scores=False)[source]

Predict for a feature batch with trained weights.

Each row of features is bound into the composed circuit alongside the weights and the cost observable’s expectation is estimated from shots — the same score the loss optimizes, including loss_constant so it matches the full observable. By default the sign of that score is the class label: +1 for a non-negative score, -1 otherwise. Pass return_scores=True to get the continuous scores instead (e.g. for a custom decision threshold or a regression-style output).

This works for any observable (the expectation is measured directly, with no computational-basis decoding), and shares the measurement machinery the rest of the program uses.

Parameters:
  • features (TypeAliasType) – Shape (n_samples, n_data_params) (or a single (n_data_params,) row) feature batch.

  • params (ndarray[tuple[Any, ...], dtype[double]] | None) – Trained weights of shape (n_layers * n_params_per_layer,). Defaults to self.best_params.

  • return_scores (bool) – When True, return the continuous per-sample score ⟨H⟩ + loss_constant instead of the sign-thresholded label.

Returns:

Shape (n_samples,) — class labels in

{-1.0, +1.0} by default, or continuous scores when return_scores is True.

Return type:

ndarray

Raises:
  • RuntimeError – If the program has no data axis, or if params is None and the program has not been trained yet.

  • ValueError – On a feature-column or weight-length mismatch.