AGENT SKILL

qnn-gradients

Construct, execute, differentiate, and troubleshoot Qiskit Machine Learning neural networks and quantum geometry with EstimatorQNN, SamplerQNN, public V2 primitives, and layout-aware gradient workflows.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
qnn-gradients
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Construct, execute, differentiate, and troubleshoot Qiskit Machine Learning neural networks and quantum geometry with EstimatorQNN, SamplerQNN, public V2 primitives, and layout-aware gradient workflows.
disable-model-invocation
true

02 资源文件 5

03 SKILL.md 正文

QNNs and gradients

Use this route when a request is about NeuralNetwork, EstimatorQNN, SamplerQNN, forward/backward, parameter-shift or other QNN gradients, input gradients, observables, sampler interpretation, sparse outputs, QFI/QGT, effective dimension, or transpilation/layout handling for these workflows.

Route and boundaries

  • Read api-reference.md for public signatures, parameter ordering, output shapes, and primitive-version behavior.
  • Read workflows.md for construction, forward/backward, custom gradients, layout-aware V2, and effective-dimension procedures.
  • Read gradients-and-qgt.md for gradient families, options, derivative types, QGT/QFI, and interpretation of results.
  • Read troubleshooting.md before changing a circuit or primitive after an error.
  • Run scripts/qnn_smoke.py with --help for the bundled public-API smoke; run it without arguments for a tiny estimator/sampler forward and backward check.

Route full classifier/regressor fitting, optimizers, callbacks, and persistence to the algorithms route. Route fidelity kernels and state-fidelity circuits to kernels-fidelity. Route TorchConnector, autograd, sparse Torch integration, and hybrid PyTorch networks to data-circuits-connectors; this route only supplies the QNN and gradient contract that the connector consumes.

Operating contract

  1. Install the public package in the target environment, for example python -m pip install qiskit-machine-learning; add sparse only for sparse SamplerQNN output and use the optional dependency required by the chosen external primitive/backend when applicable.
  2. Decide whether the model output is an expectation value (EstimatorQNN) or a probability/distribution (SamplerQNN). A QNN is stateless: it stores a parameterized circuit and primitives, but not trainable weight values or a fitting loop.
  3. Identify input and weight parameters explicitly. Values are passed to the primitive in inputs followed by weights, in the exact order of the supplied input_params and weight_params sequences. The circuit must have exactly the combined number of parameters.
  4. For EstimatorQNN, use a circuit without measurements and supply one observable or a sequence of observables. For SamplerQNN, ensure the circuit is measured; custom interpret requires an explicit output_shape.
  5. For a V2/runtime-style primitive that needs ISA circuits, transpile with a pass manager and keep its use consistent with the QNN and its gradient. Apply a transpiled circuit's layout to each estimator observable. Add sampler measurements before transpilation and use stable classical-register names such as meas or c.
  6. Check forward and backward shapes against the referenced contract before connecting the QNN to another API. Set input_gradients=True only when input derivatives are needed; the default backward pass returns weight gradients and None for input gradients.
  7. Select a gradient implementation appropriate to the primitive and gates. Parameter-shift is the default for QNNs. Pass runtime options at construction or at gradient.run; run-time options override gradient defaults, which override primitive defaults.
  8. For QFI/QGT or effective dimension, use an estimator-based QGT on a pure, parameterized state, validate sample shapes, and treat shot/precision and pass-manager choices as part of the result's reproducibility record.

Do not claim that a CPU reference smoke proves a vendor backend, cloud runtime, CUDA, or shot-noise behavior. Record an unavailable optional backend as unverified and preserve the recovery steps in troubleshooting.md.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351