VQR¶
- class VQR(num_qubits=None, feature_map=None, ansatz=None, observable=None, loss='squared_error', optimizer=None, warm_start=False, quantum_instance=None, initial_point=None, callback=None, *, estimator=None)[sorgente]¶
Basi:
NeuralNetworkRegressor
A convenient Variational Quantum Regressor implementation.
- Parametri:
num_qubits (int | None) – The number of qubits for the underlying QNN. If
None
then the number of qubits is derived from the feature map or ansatz, but if neither of these are given an error is raised. The number of qubits in the feature map and ansatz are adjusted to this number if required.feature_map (QuantumCircuit | None) – The (parametrized) circuit to be used as a feature map for the underlying QNN. If
None
theZZFeatureMap
is used if the number of qubits is larger than 1. For a single qubit regression problem theZFeatureMap
is used by default.ansatz (QuantumCircuit | None) – The (parametrized) circuit to be used as an ansatz for the underlying QNN. If
None
then theRealAmplitudes
circuit is used.observable (QuantumCircuit | OperatorBase | BaseOperator | PauliSumOp | None) – The observable to be measured in the underlying QNN. If
None
, use the default \(Z^{\otimes num\_qubits}\) observable. Ifquantum_instance
is set and theestimator
isNone
then the observable must be of typeQuantumCircuit
orOperatorBase
. Otherwise, the type must be eitherBaseOperator
orPauliSumOp
.loss (str | Loss) – A target loss function to be used in training. Default is squared error.
optimizer (Optimizer | None) – An instance of an optimizer to be used in training. When
None
defaults to SLSQP.warm_start (bool) – Use weights from previous fit to start next fit.
quantum_instance (QuantumInstance | None) – Deprecated: If a quantum instance is set and
estimator
isNone
, the underlying QNN will be of typeTwoLayerQNN
, and the quantum instance will be used to compute the neural network’s results. If an estimator instance is also set, it will override the quantum_instance parameter and aEstimatorQNN
will be used instead.initial_point (np.ndarray | None) – Initial point for the optimizer to start from.
callback (Callable[[np.ndarray, float], None] | None) – A reference to a user’s callback function that has two parameters and returns
None
. The callback can access intermediate data during training. On each iteration an optimizer invokes the callback and passes current weights as an array and a computed value as a float of the objective function being optimized. This allows to track how well optimization / training process is going on.estimator (BaseEstimator | None) – An estimator to be used to evaluate expectation values of the observable. If
None
theqiskit.primitives.BaseEstimator
is used. The underlying QNN isEstimatorQNN
.set (If an estimator instance is) –
EstimatorQNN
, and the estimator primitive will be used to compute the neural network’s results.type (the underlying QNN will be of) –
EstimatorQNN
, and the estimator primitive will be used to compute the neural network’s results.
- Solleva:
QiskitMachineLearningError – Needs at least one out of
num_qubits
,feature_map
oransatz
to be given. Or the number of qubits in the feature map and/or ansatz can’t be adjusted tonum_qubits
.ValueError – if the type of the observable is not compatible with
quantum_instance
orestimator
.
Attributes
Returns the used ansatz.
Returns the used feature map.
Returns the number of qubits used by ansatz and feature map.
Methods