gradients-interfaces
Configure PennyLane gradients, differentiable interfaces, optimizers, TorchLayer, and optional compiler/qjit workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- gradients-interfaces
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Configure PennyLane gradients, differentiable interfaces, optimizers, TorchLayer, and optional compiler/qjit workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/api-reference.md2.9 KB
- 参考文档references/troubleshooting.md2.8 KB
- 参考文档references/workflows.md2.6 KB
- 脚本scripts/interface_gradient_smoke.py703 B
- 脚本scripts/torchlayer_probe.py870 B
03 SKILL.md 正文
Gradients and interfaces
Use this sub-skill when a task involves differentiating QNodes, choosing diff_method, using Autograd/JAX/Torch/TensorFlow arrays, training hybrid models, converting QNodes to TorchLayer, or troubleshooting gradient/interface behavior.
Read first
references/api-reference.md: gradient, interface, optimizer, math, QNN, and qjit API facts.references/workflows.md: Autograd, JAX, Torch, TorchLayer, and finite-difference/parameter-shift patterns.references/troubleshooting.md: trainability warnings, interface mismatch, non-differentiable measurements, optional framework failures, and Catalyst caveats.scripts/interface_gradient_smoke.py: base Autograd gradient smoke that does not require optional ML frameworks.scripts/torchlayer_probe.py: optional TorchLayer probe; it exits clearly if Torch is not installed.
Route within this sub-skill
- Base gradients: use
qp.grad,qp.jacobian,qp.value_and_grad,qp.vjp,qp.jvp, and gradient transforms underqp.gradients. - Interface selection: set
interface="auto","autograd","jax","torch", or legacy"tf"deliberately when auto-detection is ambiguous. - Differentiation method: start with
diff_method="best"; choose parameter-shift, finite-diff, backprop, adjoint, SPSA, or device-specific methods only when the device/measurement/workflow requires it. - Training loops: use PennyLane optimizers for Autograd/NumPy workflows; use native JAX/Torch optimizers for those frameworks.
- QNN: use
qp.qnn.TorchLayer(qnode, weight_shapes, init_method=None)when integrating a QNode intotorch.nn. - Compilation:
qp.qjitroutes to Catalyst-backed workflows; do not claim qjit availability until Catalyst runtime is installed and checked.
Boundaries
- Circuit/device construction belongs to
../circuits-devices/SKILL.md. - Operator/template shape and custom-operator details belong to
../operators-transforms/SKILL.md, but gradient method compatibility may be handled here. - Resource estimation and qchem/domain algorithms belong to
../applications-qchem-resource/SKILL.md. - Source test markers and lint rules belong to
../repo-development/SKILL.md.
Minimal Autograd pattern
import pennylane as qp
dev = qp.device("default.qubit", wires=1)
@qp.qnode(dev)
def circuit(theta):
qp.RX(theta, wires=0)
return qp.expval(qp.Z(0))
theta = qp.numpy.array(0.2, requires_grad=True)
print(circuit(theta))
print(qp.grad(circuit)(theta))
If qp.grad returns () or warns about no trainable parameters, use a trainable PennyLane NumPy tensor or pass argnums explicitly.
Verification cues
State the array framework, QNode interface, diff_method, measurement type, shot setting, optional dependency status, and a numeric gradient check. For source changes, choose focused tests under tests/gradients/, tests/test_grad.py, interface-marked tests, or tests/qnn/ depending on the changed surface.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).