BaseSamplerGradient¶
- class BaseSamplerGradient(sampler, shots=None, *, transpiler=None, transpiler_options=None)[source]¶
Bases:
ABC
Base class for a
SamplerGradient
to compute the gradients of the sampling probability.- Parameters:
sampler (BaseSamplerV2) – The sampler used to compute the gradients.
shots (int | None) – Number of shots to be used by the underlying Sampler. If provided, this number takes precedence over the default number of shots of the primitive. Otherwise, the default number of shots of the primitive is used.
transpiler (Transpiler | None) – An optional object with a run method allowing to transpile the circuits that are run when using this algorithm. If set to None, these won’t be transpiled.
transpiler_options (dict[str, Any] | None) – A dictionary of options to be passed to the transpiler’s run method as keyword arguments.
Attributes
- shots¶
Return the number of shots used by the run method of the Sampler primitive. If None, the default number of shots of the primitive is used.
- Returns:
The default number of shots.
Methods
- run(circuits, parameter_values, parameters=None, *, shots=None)[source]¶
Run the job of the sampler gradient on the given circuits.
- Parameters:
circuits (Sequence[QuantumCircuit]) – The list of quantum circuits to compute the gradients.
parameter_values (Sequence[Sequence[float]]) – The list of parameter values to be bound to the circuit.
parameters (Sequence[Sequence[Parameter] | None] | None) – The sequence of parameters to calculate only the gradients of the specified parameters. Each sequence of parameters corresponds to a circuit in
circuits
. Defaults to None, which means that the gradients of all parameters in each circuit are calculated. None in the sequence means that the gradients of all parameters in the corresponding circuit are calculated.shots (int | Sequence[int] | None) – Number of shots to be used by the underlying Sampler. If a single integer is provided, this number will be used for all circuits. If a sequence of integers is provided, they will be used on a per-circuit basis. If not set, the gradient’s default number of shots will be used for all circuits, and if that is None (not set) then the underlying primitive’s default number of shots will be used for all circuits.
- Returns:
The job object of the gradients of the sampling probability. The i-th result corresponds to
circuits[i]
evaluated with parameters bound asparameter_values[i]
. The j-th quasi-probability distribution in the i-th result corresponds to the gradients of the sampling probability for the j-th parameter incircuits[i]
.- Raises:
ValueError – Invalid arguments are given.
- Return type: