finite-difference

Estimates quantum circuit parameter gradients via finite difference schemes in Qiskit.

18|3|Updated Aug 14, 2026
One-click install
npx skills add https://github.com/unitarylab/quantum-practices --skill finite-difference-unitarylab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: finite-difference
Source: https://github.com/unitarylab/quantum-practices/tree/main/algorithms/gradients/finite-difference
Command: npx skills add https://github.com/unitarylab/quantum-practices --skill finite-difference-unitarylab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, qiskit, qiskit_algorithms, and includes scripts (resource) components.

What problem does it solve? Computing gradients of parameterized quantum circuits is essential for variational algorithms, but analytic gradient methods only work with specific gate sets. This Skill numerically approximates gradients for any differentiable quantum circuit using finite difference methods, providing a universal fallback when parameter-shift or LCU methods are not applicable. ## Core Features & Use Cases - Estimator and Sampler Gradients: Supports both FiniteDiffEstimatorGradient for expectation value gradients and FiniteDiffSamplerGradient for probability distribution gradients. - Three Difference Schemes: Central (second-order accurate, 2n evaluations), forward, and backward (first-order, n+1 evaluations) schemes with configurable step size epsilon. - Batched Execution: All perturbed circuit evaluations are submitted as a single primitive job to minimize overhead. - Use Case: When training a variational quantum eigensolver whose ansatz contains gates outside the parameter-shift rule's supported set, use central finite difference with epsilon=1e-2 to compute energy gradients for the optimizer. ## Quick Start Ask the AI to compute the gradient of a parameterized Qiskit circuit with respect to an observable using the finite difference method with central differencing.

Frequently Asked Questions about finite-difference

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I compute gradients of a parameterized quantum circuit in Qiskit?

Use FiniteDiffEstimatorGradient from qiskit_algorithms.gradients with an Estimator primitive, an epsilon step size, and a difference method. Call .run() with your circuits, observables, and parameter values to receive gradient arrays.

What is the difference between central, forward, and backward finite difference?

Central difference uses 2n circuit evaluations and is second-order accurate O(epsilon^2), while forward and backward use n+1 evaluations with first-order accuracy O(epsilon). Central is preferred for simulators; forward may suffice on noisy hardware.

When should I use finite difference instead of parameter shift gradients?

Use finite difference when circuits contain gates outside the analytic gradient supported sets, since it works with any differentiable gate. Parameter shift is exact and preferred when the gate set supports it.

How do I choose the epsilon step size for finite difference gradients?

Start with epsilon around 1e-2 and reduce while monitoring gradient stability. Too large causes truncation error; too small amplifies shot noise and floating-point error through the 1/epsilon division.

Why does FiniteDiffEstimatorGradient raise ValueError or TypeError?

A ValueError is raised when epsilon is not positive, and a TypeError is raised when method is not exactly 'central', 'forward', or 'backward'. Validate both arguments before constructing the gradient object.