CircuitQNN¶
- 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)[sorgente]¶
Basi:
SamplingNeuralNetwork
Pending deprecation: A sampling neural network based on a given quantum circuit.
- Parametri:
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 fromRawFeatureVector
, 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 (
Optional
[List
[Parameter
]]) – The parameters of the circuit corresponding to the input.weight_params (
Optional
[List
[Parameter
]]) – 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 thatsampling==True
will always result in a dense return array independent of the other settings.interpret (
Optional
[Callable
[[int
],Union
[int
,Tuple
[int
, …]]]]) – 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, andsampling==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 (
Union
[int
,Tuple
[int
, …],None
]) – The output shape of the custom interpretation, only used in the case where an interpret function is provided andsampling==False
. Note that in the remaining cases, the output shape is automatically inferred by:2^num_qubits
ifsampling==False
andinterpret==None
,(num_samples,1)
ifsampling==True
andinterpret==None
, and(num_samples, interpret_shape)
ifsampling==True
and an interpret function is provided.gradient (
Optional
[Gradient
]) – The gradient converter to be used for the probability gradients.quantum_instance (
Union
[Backend
,QuantumInstance
,None
]) – The quantum instance to evaluate the circuits. Note that ifsampling==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 isFalse
by default, and must be explicitly set toTrue
for a proper gradient computation when usingTorchConnector
.
- Solleva:
QiskitMachineLearningError – if
interpret
is passed withoutoutput_shape
.
Attributes
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 quantum instance to evaluate the circuit.
Returns the list of trainable weights parameters.
Methods
set_interpret
(interpret[, output_shape])Change 'interpret' and corresponding 'output_shape'.