class CircuitQNN(circuit, input_params=None, weight_params=None, sparse=False, sampling=False, interpret=None, output_shape=None, gradient=None, quantum_instance=None, input_gradients=False)[source]

Bases: SamplingNeuralNetwork

Pending deprecation: A sampling neural network based on a given quantum circuit.

unknown ভার্সন থেকে ডেপ্রিকেটেড: The CircuitQNN class has been superseded by the qiskit_machine_learning.neural_networks.SamplerQNN This class will be deprecated in a future release and subsequently removed after that.

  • circuit (QuantumCircuit) -- The parametrized quantum circuit that generates the samples of this network. There will be an attempt to transpile this circuit and cache the transpiled circuit for subsequent usages by the network. If for some reasons the circuit can't be transpiled, e.g. it originates from RawFeatureVector, the circuit will be transpiled every time it is required to be executed and only when all parameters are bound. This may impact overall performance on the network.

  • input_params (List[Parameter] | None) -- The parameters of the circuit corresponding to the input.

  • weight_params (List[Parameter] | None) -- The parameters of the circuit corresponding to the trainable weights.

  • sparse (bool) -- Returns whether the output is sparse or not.

  • sampling (bool) -- Determines whether the network returns a batch of samples or (possibly sparse) array of probabilities in its forward pass. In case of probabilities, the backward pass returns the probability gradients, while it returns (None, None) in the case of samples. Note that sampling==True will always result in a dense return array independent of the other settings.

  • interpret (Callable[[int], int | Tuple[int, ...]] | None) -- A callable that maps the measured integer to another unsigned integer or tuple of unsigned integers. These are used as new indices for the (potentially sparse) output array. If this is used, and sampling==False, the output shape of the output needs to be given as a separate argument. If no interpret function is passed, then an identity function will be used by this neural network.

  • output_shape (int | Tuple[int, ...]) -- The output shape of the custom interpretation, only used in the case where an interpret function is provided and sampling==False. Note that in the remaining cases, the output shape is automatically inferred by: 2^num_qubits if sampling==False and interpret==None, (num_samples,1) if sampling==True and interpret==None, and (num_samples, interpret_shape) if sampling==True and an interpret function is provided.

  • gradient (Gradient) -- The gradient converter to be used for the probability gradients.

  • quantum_instance (Backend | QuantumInstance | None) -- The quantum instance to evaluate the circuits. Note that if sampling==True, a statevector simulator is not a valid backend for the quantum instance.

  • 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 -- if interpret is passed without output_shape.



Returns the underlying quantum circuit.


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


Returns the list of input parameters.


Returns interpret function to be used by the neural network.


Returns the number of input features.


Returns the number of trainable weights.


Returns the output shape.


Returns the quantum instance to evaluate the circuit.


Returns: True if the network returns a batch of samples and False if a sparse vector (dictionary) of probabilities in its forward pass.


Returns whether the output is sparse or not.


Returns the list of trainable weights parameters.


backward(input_data, weights)

Backward pass of the network.

forward(input_data, weights)

Forward pass of the network.

probabilities(input_data, weights)

Histogram (as dict) of the samples from the network.

probability_gradients(input_data, weights)

Probability gradients of histogram resulting from the network.

sample(input_data, weights)

Samples from the network.

set_interpret(interpret[, output_shape])

Change 'interpret' and corresponding 'output_shape'.