Bengali
ভাষাসমূহ
English
Bengali
French
Hindi
Italian
Japanese
Korean
Malayalam
Russian
Spanish
Tamil
Turkish
Vietnamese



EstimatorQNN

class EstimatorQNN(*, circuit, estimator=None, observables=None, input_params=None, weight_params=None, gradient=None, input_gradients=False)[source]

Bases: NeuralNetwork

A neural network implementation based on the Estimator primitive.

The EstimatorQNN is a neural network that takes in a parametrized quantum circuit with designated parameters for input data and/or weights, an optional observable(s) and outputs their expectation value(s). Quite often, a combined quantum circuit is used. Such a circuit is built from two circuits: a feature map, it provides input parameters for the network, and an ansatz (weight parameters).

Example:

from qiskit import QuantumCircuit
from qiskit.circuit.library import ZZFeatureMap, RealAmplitudes

from qiskit_machine_learning.neural_networks import EstimatorQNN

num_qubits = 2
feature_map = ZZFeatureMap(feature_dimension=num_qubits)
ansatz = RealAmplitudes(num_qubits=num_qubits, reps=1)

qc = QuantumCircuit(num_qubits)
qc.compose(feature_map, inplace=True)
qc.compose(ansatz, inplace=True)

qnn = EstimatorQNN(
    circuit=qc,
    input_params=feature_map.parameters,
    weight_params=ansatz.parameters
)

qnn.forward(input_data=[1, 2], weights=[1, 2, 3, 4])

The following attributes can be set via the constructor but can also be read and updated once the EstimatorQNN object has been constructed.

estimator

The estimator primitive used to compute the neural network's results.

Type:

BaseEstimator

gradient

The estimator gradient to be used for the backward pass.

Type:

BaseEstimatorGradient

প্যারামিটার:
  • estimator (BaseEstimator | None) -- The estimator used to compute neural network's results. If None, a default instance of the reference estimator, Estimator, will be used.

  • circuit (QuantumCircuit) -- The quantum circuit to represent the neural network.

  • observables (Sequence[BaseOperator | PauliSumOp] | BaseOperator | PauliSumOp | None) -- The observables for outputs of the neural network. If None, use the default \(Z^{\otimes num\_qubits}\) observable.

  • input_params (Sequence[Parameter] | None) -- The parameters that correspond to the input data of the network. If None, the input data is not bound to any parameters.

  • weight_params (Sequence[Parameter] | None) -- The parameters that correspond to the trainable weights. If None, the weights are not bound to any parameters.

  • gradient (BaseEstimatorGradient | None) -- The estimator gradient to be used for the backward pass. If None, a default instance of the estimator gradient, ParamShiftEstimatorGradient, will be used.

  • input_gradients (bool) -- Determines whether to compute gradients with respect to input data. Note that this parameter is False by default, and must be explicitly set to True for a proper gradient computation when using TorchConnector.

রেইজেস:

QiskitMachineLearningError -- Invalid parameter values.

Attributes

circuit

The quantum circuit representing the neural network.

input_gradients

Returns whether gradients with respect to input data are computed by this neural network in the backward method or not.

input_params

The parameters that correspond to the input data of the network.

observables

Returns the underlying observables of this QNN.

weight_params

The parameters that correspond to the trainable weights.

Methods