reverse

Computes expectation gradients and QGT entries via reverse-mode statevector differentiation in Qiskit.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Computing exact gradients and Quantum Geometric Tensor entries for parameterized quantum circuits typically requires many extra circuit evaluations with parameter-shift or finite-difference methods. This Skill provides reverse-mode statevector differentiation using Qiskit's ReverseEstimatorGradient and ReverseQGT, delivering exact analytic gradients in a single reverse sweep for small circuits. ## Core Features & Use Cases - Exact Gradient Computation: Uses ReverseEstimatorGradient to compute expectation value gradients with O(P) scaling in the number of parameterized gates, with no truncation error. - QGT Computation: Uses ReverseQGT with configurable phase-fix and derivative type (REAL, IMAG, COMPLEX) for natural gradient optimization workflows. - Reference Implementation: Includes a manual NumPy-based reverse-sweep implementation with known test cases validated against finite differences and analytic solutions. - Use Case: A researcher training a variational quantum eigensolver on a 2-qubit RY+CX ansatz needs exact gradients of the ZZ expectation value; this Skill generates runnable Qiskit code and validates results against finite-difference baselines. ## Quick Start Ask the assistant to compute the gradient of the ZZ observable for a two-qubit RY parameterized circuit using reverse-mode differentiation in Qiskit.

Frequently Asked Questions about reverse

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 ReverseEstimatorGradient from qiskit_algorithms.gradients by calling run() with your circuit, observable, and parameter values. It performs a reverse sweep over statevectors to produce exact analytic gradients without extra circuit evaluations.

What is the difference between reverse-mode gradient and parameter-shift?

Reverse-mode gradient differentiates directly on statevectors in a single backward sweep with O(P) scaling, while parameter-shift requires additional circuit evaluations per parameter. Reverse-mode is exact but limited to statevector simulation of small circuits.

How do I compute the Quantum Geometric Tensor in Qiskit?

Use ReverseQGT from qiskit_algorithms.gradients and call run() with your circuit and parameter values. Set phase_fix=True for the phase-fixed metric used by natural gradient optimizers, and choose the derivative_type for real, imaginary, or complex output.

Why does ReverseEstimatorGradient raise KeyError with parameterized two-qubit gates?

In qiskit_algorithms 0.4.0, circuits with parameterized cp, crx, cry, or crz gates can raise KeyError during gradient-parameter preprocessing. Use only parameterized rx, ry, rz gates and keep entanglers like cx non-parameterized.

What are the limitations of reverse-mode statevector gradients?

Runtime and memory scale exponentially as O(2^n) with qubit count, making circuits beyond roughly 10 qubits impractical. It also supports only the declared gate set and cannot use external estimator or sampler primitives.