parameter-shift

Computes exact analytic gradients of parameterized quantum circuits via the parameter shift rule.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Numerical gradient methods like finite differences introduce approximation error and require careful step-size tuning when training parameterized quantum circuits. This Skill provides exact analytic gradient computation using the parameter shift rule, supporting both expectation value (Estimator) and probability distribution (Sampler) gradients on Qiskit. ## Core Features & Use Cases - Exact Analytic Gradients: Computes gradients with zero approximation error by evaluating circuits at shifted parameter values (theta +/- pi/2), batching all 2n evaluations into one primitive job. - Dual Primitive Support: Works with both ParamShiftEstimatorGradient for expectation values and ParamShiftSamplerGradient for probability distributions. - Selective Differentiation: Differentiate a subset of circuit parameters while holding others fixed, with output order matching the requested parameter list. - Use Case: When training a variational quantum eigensolver or quantum machine learning model, use this Skill to compute exact loss gradients with respect to rotation gate angles for gradient-based optimizers. ## Quick Start Ask the assistant to compute the gradient of a two-qubit RY circuit with a ZZ observable using the parameter shift rule in Qiskit.

Frequently Asked Questions about parameter-shift

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

FAQPage Schema
How do I compute quantum circuit gradients with the parameter shift rule in Qiskit?

Use ParamShiftEstimatorGradient from qiskit_algorithms.gradients with an Estimator primitive, then call .run() with your circuit, observable, and parameter values. The result's gradients field contains one array per circuit with exact analytic derivatives.

What is the difference between parameter shift and finite difference gradients?

Parameter shift computes exact analytic gradients by evaluating the circuit at theta plus and minus pi/2, introducing no approximation error. Finite difference approximates derivatives with small step sizes and carries truncation error that depends on the chosen epsilon.

Which gates are supported by the parameter shift rule?

Supported gates are x, y, z, h, rx, ry, rz, p, cx, cy, cz, ryy, rxx, rzz, and rzx. Circuits containing other gates are automatically decomposed during preprocessing, but gates that cannot be decomposed will raise an error.

Can I differentiate only some parameters of a quantum circuit?

Yes, pass a parameters argument to .run() listing the specific Parameter objects to differentiate. The output gradient array then contains one entry per requested parameter, in the same order as your list.

Why does my parameter shift gradient call raise an unsupported gate error?

The error occurs when a circuit contains gates outside the supported set that cannot be decomposed during preprocessing. Check your circuit's operations against the supported gate list and manually decompose exotic gates before running the gradient.

When should I not use the parameter shift rule?

Avoid it when gates have generators with eigenvalues other than plus or minus one half, since the fixed pi/2 shift no longer yields exact gradients. In those cases use linear combination of unitaries or finite difference methods instead.