LinCombSamplerGradient

class LinCombSamplerGradient(sampler, shots=None, *, transpiler=None, transpiler_options=None)[source]

Bases: BaseSamplerGradient

Compute the gradients of the sampling probability. This method employs a linear combination of unitaries [1].

Reference: [1] Schuld et al., Evaluating analytic gradients on quantum hardware, 2018 arXiv:1811.11184

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 precision of the primitive. If None, 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 produced within 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

SUPPORTED_GATES = ['rx', 'ry', 'rz', 'rzx', 'rzz', 'ryy', 'rxx', 'cx', 'cy', 'cz', 'ccx', 'swap', 'iswap', 'h', 't', 's', 'sdg', 'x', 'y', 'z']
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)

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 as parameter_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 in circuits[i].

Raises:

ValueError – Invalid arguments are given.

Return type:

AlgorithmJob