gradients

Compute analytic and numerical gradients of parameterized quantum circuits using Qiskit Algorithms.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Choosing and correctly implementing a quantum gradient method is difficult: each method (finite difference, parameter shift, LCU, SPSA, reverse-mode, QFI) has different gate restrictions, evaluation costs, and backend requirements. This Skill routes you to the right method and provides runnable Qiskit implementations, parameter schemas, and debugging guidance for each. ## Core Features & Use Cases - Method Routing: A decision table and flowchart select the correct gradient method based on gate set, QGT/QFI needs, parameter count, and evaluation budget. - Six Covered Methods: Finite difference, parameter shift, linear combination of unitaries (LCU), SPSA, reverse-mode statevector gradients, and Quantum Fisher Information via QGT. - Full API Reference: Constructor parameters, return fields, supported gate sets, circuit evaluation counts, and mathematical formulas for every Qiskit Algorithms gradient class. - Use Case: When training a variational quantum eigensolver with many parameters on limited hardware shots, use the routing guide to pick SPSA, then follow its leaf skill to generate a working SPSAEstimatorGradient example with correct batching and seed configuration. ## Quick Start Ask the assistant to compute the gradient of a parameterized Qiskit circuit and let it route you to the appropriate gradient method with a runnable example.

Frequently Asked Questions about gradients

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 gradient classes from qiskit_algorithms.gradients such as ParamShiftEstimatorGradient or FiniteDiffEstimatorGradient. Pass an estimator primitive, your circuit, observable, and parameter values to the run() method, then read result.gradients.

Parameter shift vs finite difference gradient: which should I use?

Parameter shift gives exact analytic gradients with no approximation error but requires gates from a supported set like rx, ry, rz, and cx. Finite difference works on any circuit but introduces truncation error controlled by the epsilon step size.

How do I compute the Quantum Fisher Information matrix in Qiskit?

Create a LinCombQGT instance with an estimator primitive, wrap it in the QFI class, and call run() with your circuit and parameter values. The result qfis field contains the QFI matrix computed as 4 times the real part of the QGT.

Does parameter shift work with any quantum gate?

No, parameter shift only supports gates whose generators have eigenvalues of plus or minus one half, including rx, ry, rz, rxx, ryy, rzz, rzx, cx, cy, cz, h, and p. Unsupported gates are decomposed during preprocessing, but exotic gates may fail.

When should I use SPSA instead of parameter shift for quantum gradients?

Use SPSA when your circuit has many parameters and a limited circuit evaluation budget. SPSA needs only 2 times batch_size evaluations regardless of parameter count, while parameter shift requires 2n evaluations for n parameters.

Why does reverse-mode gradient fail on my circuit?

Reverse-mode in qiskit_algorithms 0.4.0 can raise KeyError with parameterized two-qubit gates like cp, crx, cry, or crz. Use only parameterized rx, ry, rz gates with non-parameterized entanglers like cx, and note it scales exponentially with qubit count.