French
Langues
English
Bengali
French
Hindi
Japanese
Korean
Russian
Spanish
Tamil
Turkish



TwoLayerQNN

class TwoLayerQNN(num_qubits=None, feature_map=None, ansatz=None, observable=None, exp_val=None, quantum_instance=None, input_gradients=False)[source]

Bases : OpflowQNN

Pending deprecation: Two Layer Quantum Neural Network consisting of a feature map, a ansatz, and an observable.

Obsolète depuis la version unknown: The TwoLayerQNN class is pending deprecation and has no direct replacement. Make use of qiskit_machine_learning.neural_networks.EstimatorQNN instead.This class will be deprecated in a future release and subsequently removed after that.

Paramètres:
  • num_qubits (int | None) – The number of qubits to represent the network. If None is given, the number of qubits is derived from the feature map or ansatz. If neither of those is given, raises an exception. 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. If None is given, the ZZFeatureMap is used if the number of qubits is larger than 1. For a single qubit two-layer QNN the ZFeatureMap circuit is used per default.

  • ansatz (QuantumCircuit | None) – The (parametrized) circuit to be used as an ansatz. If None is given, the RealAmplitudes circuit is used.

  • observable (OperatorBase | QuantumCircuit | None) – observable to be measured to determine the output of the network. If None is given, the \(Z^{\otimes num\_qubits}\) observable is used.

  • exp_val (ExpectationBase | None) – The Expected Value converter to be used for the operator obtained from the feature map and ansatz.

  • quantum_instance (QuantumInstance | Backend | None) – The quantum instance to evaluate the network.

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

Lève:

QiskitMachineLearningError – Needs at least one out of num_qubits, feature_map or ansatz to be given. Or the number of qubits in the feature map and/or ansatz can’t be adjusted to num_qubits.

Attributes

ansatz

Returns the used ansatz.

circuit

Returns the underlying quantum circuit.

feature_map

Returns the used feature map.

input_gradients

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

num_inputs

Returns the number of input features.

num_qubits

Returns the number of qubits used by ansatz and feature map.

num_weights

Returns the number of trainable weights.

operator

Returns the underlying operator of this QNN.

output_shape

Returns the output shape.

quantum_instance

Returns the quantum instance to evaluate the operator.

sparse

Returns whether the output is sparse or not.

Methods

backward(input_data, weights)

Backward pass of the network.

forward(input_data, weights)

Forward pass of the network.