unitarylab/quantum-practices/gradients

Claude Code and agent skill by unitarylab/quantum-practices

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Master routing guide for all quantum gradient and geometric tensor methods in this folder. Read this file first, then follow the leaf skill for the chosen method. Skill-first for covered code generation, runnable examples, execution, debugging, validation, and fixed workflows.

Install

npx vskill@latest install unitarylab/quantum-practices/gradients

SKILL.md

Quantum Gradients — Master Guide

Purpose

This file routes you to the right gradient method.

Sub-skills in this folder:

  • finite-difference/SKILL.md
  • parameter-shift/SKILL.md
  • linear-combination/SKILL.md
  • spsa/SKILL.md
  • reverse/SKILL.md
  • qfi/SKILL.md

Method Selection

SituationMethod
Circuit uses arbitrary gates, no analytic rule neededfinite-difference
Circuit uses supported rotation/controlled gates, need exact gradientparameter-shift
Same as above, but also need QGT or complex-valued gradientlinear-combination
Many parameters, limited circuit evaluation budgetspsa
Small circuit, statevector simulation, no external backend neededreverse
Need the Quantum Fisher Information matrixqfi

Method Comparison

MethodAnalytic?Circuit evals per callGate restrictionQGT supportBackend
Finite differenceNo2n (central) or n+1NoneNoEstimator / Sampler
Parameter shiftYes2nrx ry rz cx cy cz rxx ryy rzz rzx p ...NoEstimator / Sampler
Linear combination (LCU)Yesn – 2nSame as above + h t s iswapYes (LinCombQGT)Estimator / Sampler
SPSANo (stochastic)2 × batch_size (fixed)NoneNoEstimator / Sampler
ReverseYesO(P) per gradientrx ry rz cp crx cry crzYes (ReverseQGT)None (statevector)
QFIYes (via QGT)Same as LinCombQGTSame as LCUYes (is a QGT wrapper)Estimator

n = number of target parameters; P = number of parameterized gates.


Method Summaries

finite-difference

Numerically approximates ∂f/∂θ_i by perturbing one parameter at a time.

  • Classes: FiniteDiffEstimatorGradient, FiniteDiffSamplerGradient
  • Key params: epsilon, method ("central" / "forward" / "backward")
  • No gate restrictions; works on any circuit
  • Read: finite-difference/SKILL.md
parameter-shift

Computes exact gradient via (f(θ + π/2) - f(θ - π/2)) / 2 per parameter.

  • Classes: ParamShiftEstimatorGradient, ParamShiftSamplerGradient
  • No free tuning parameter (shift is fixed at π/2)
  • Requires circuits from the supported gate set
  • Read: parameter-shift/SKILL.md
linear-combination (LCU)

Augments the circuit with an ancilla qubit to compute exact analytic gradients, and can also compute the full Quantum Geometric Tensor.

  • Classes: LinCombEstimatorGradient, LinCombSamplerGradient, LinCombQGT
  • Key param: derivative_type (REAL / IMAG / COMPLEX)
  • Requires circuits from the supported gate set
  • Read: linear-combination/SKILL.md
SPSA

Estimates gradients stochastically by perturbing all parameters simultaneously. Only 2 × batch_size circuit evaluations regardless of parameter count.

  • Classes: SPSAEstimatorGradient, SPSASamplerGradient
  • Key params: epsilon, batch_size, seed
  • Best for high-dimensional parameter spaces with limited evaluation budget
  • Read: spsa/SKILL.md
reverse

Reverse-mode gradient using statevector simulation. No external primitive needed. Efficient in number of circuit evaluations but scales exponentially with qubit count.

  • Classes: ReverseEstimatorGradient, ReverseQGT
  • Key param: derivative_type, phase_fix
  • Only for small, noiseless statevector simulations
  • Read: reverse/SKILL.md
qfi

Wraps a BaseQGT (typically LinCombQGT) to return the Quantum Fisher Information matrix: QFI = 4 × Re(QGT).

  • Class: QFI
  • Required: a BaseQGT instance as qgt argument
  • Output field: qfis (list of n × n real matrices)
  • Read: qfi/SKILL.md

Shared API Pattern

All gradient classes share the same run interface:

python
result = gradient_or_qfi.run(
circuits=[qc],
observables=[obs], # only for estimator-based methods
parameter_values=[[...]],
parameters=[[...]], # subset to differentiate; None = all
).result()

Return fields:

  • Gradient classes: gradients, metadata, precision or shots
  • QGT / QFI classes: qgts or qfis, metadata

Quick Decision Guide

Does the circuit use only supported rotation/controlled gates?
├── No → finite-difference
└── Yes
├── Need QGT or complex-valued gradient?
│ ├── Yes → linear-combination (LinCombQGT / LinCombEstimatorGradient)
│ └── No → parameter-shift (simpler, same cost)
│
├── Statevector simulation, small circuit, no backend needed?
│ └── Yes → reverse
│
├── High-dimensional parameters, limited eval budget?
│ └── Yes → spsa
│
└── Need QFI matrix specifically?
└── Yes → qfi (wraps LinCombQGT internally)

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/unitarylab/quantum-practices/gradients/badge)](https://verified-skill.com/skills/unitarylab/quantum-practices/gradients)

Something wrong with this skill or its page? Tell us.