data-circuits-connectors
Operate Qiskit Machine Learning's built-in datasets, circuit helpers, reference primitives, TorchConnector integration, and shared validation utilities.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- data-circuits-connectors
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Operate Qiskit Machine Learning's built-in datasets, circuit helpers, reference primitives, TorchConnector integration, and shared validation utilities.
- disable-model-invocation
- true
02 资源文件 7
- 参考文档references/api-reference.md10.2 KB
- 参考文档references/datasets-and-circuits.md8.6 KB
- 参考文档references/primitives-and-connectors.md7.7 KB
- 参考文档references/troubleshooting.md9.0 KB
- 脚本scripts/check_install.py3.6 KB
- 脚本scripts/dataset_smoke.py4.2 KB
- 脚本scripts/torch_connector_smoke.py3.3 KB
03 SKILL.md 正文
Data, circuits, primitives, and connectors
Use this sub-skill when the task is about generating a built-in Qiskit Machine Learning dataset, composing an ML circuit, evaluating a circuit with the package's exact/reference primitives, or exposing a QNN through PyTorch. It also covers reproducibility and small validation/loss helpers.
This sub-skill does not own model fitting or optimizer strategy. Route
algorithm/model-selection questions to algorithms, QNN gradient design to
qnn-gradients, fidelity-kernel behavior to kernels-fidelity, and optimizer
internals to optimizers in the surrounding graph.
Fast routing
- Need data? Read datasets-and-circuits.md and choose the dataset whose feature representation matches the QNN input.
- Need a circuit? Check qubit count and parameter partition before building
the QNN. Use
qnn_circuitfor a feature-map/ansatz pair orraw_feature_vectoronly for power-of-two amplitude dimensions. - Need deterministic reference evaluation? Read
primitives-and-connectors.md.
QMLEstimator()andQMLSampler()are exact by default; nonzero estimator precision or finite sampler shots delegates to the corresponding Qiskit reference primitive behavior. - Need PyTorch? Install the
torchextra, setinput_gradients=Trueon the QNN when upstream input gradients are needed, then useTorchConnector. Keep sparse settings consistent between the QNN and connector. - An import or shape/device error? Start with
troubleshooting.md, then run the linked
scripts from any working directory:
python /path/to/this/skill/scripts/check_install.py --help,dataset_smoke.py --help, andtorch_connector_smoke.py --help.
Operating rules
- Treat dataset feature dimension as a contract, not a hint.
ad_hoc_datareturns rows of lengthn; phase-of-matter and entanglement datasets return state vectors of dimension2**n(entanglement ndarray formatting adds a final singleton axis). A statevector feature of dimension2**nneeds ann-qubit circuit. - Check the return arity. The four standard values are
(x_train, y_train, x_test, y_test);include_sample_total=Trueappends a fifth array. - Seed the correct generator.
ad_hoc_dataand entanglement concentration useqiskit_machine_learning.utils.algorithm_globals.random_seed; phase of matter has its ownseedargument. For a PyTorch workflow also calltorch.manual_seedif randomized PyTorch parameters or data ordering must be repeatable. - Do not silently normalize or reshape labels. One-hot labels and scalar/string
labels are different downstream contracts; preserve the requested
one_hotmode. raw_feature_vector(feature_dimension)requires a positive power of two and createslog2(feature_dimension)qubits. Its parameterized initialize instruction is only defined after all amplitudes are bound and is unsuitable for gradient-based circuit optimization.qnn_circuitreturns(circuit, feature_map.parameters, ansatz.parameters). Explicit feature map and ansatz circuits should have matching qubit counts. The legacynum_qubits-based padding/alignment path is deprecated; construct matching circuits explicitly for forward compatibility.TorchConnector(sparse=True)is valid only whenneural_network.sparseis also true and requires thesparseextra. A dense connector can materialize a sparse QNN result, but a sparse connector cannot wrap a dense QNN.- A CUDA request is conditional: check
torch.cuda.is_available()before selectingcuda. CPU is the portable default. Do not infer CUDA support from the package being importable.
Canonical API index
- Dataset and circuit contracts: datasets-and-circuits.md
- Primitive and connector contracts: primitives-and-connectors.md
- Signatures, outputs, and utility index: api-reference.md
- Failure diagnosis: troubleshooting.md
- Install probe:
scripts/check_install.py - Deterministic dataset probe:
scripts/dataset_smoke.py - CPU/CUDA TorchConnector probe:
scripts/torch_connector_smoke.py
Minimal patterns
from qiskit_machine_learning.datasets import ad_hoc_data
from qiskit_machine_learning.utils import algorithm_globals
algorithm_globals.random_seed = 1376
x_train, y_train, x_test, y_test = ad_hoc_data(
training_size=20, test_size=10, n=2, gap=0.3
)
from qiskit_machine_learning.circuit.library import qnn_circuit
from qiskit_machine_learning.neural_networks import EstimatorQNN
from qiskit_machine_learning.primitives import QMLEstimator
circuit, input_params, weight_params = qnn_circuit(2)
qnn = EstimatorQNN(
circuit=circuit,
input_params=input_params,
weight_params=weight_params,
estimator=QMLEstimator(),
input_gradients=True, # required for gradients into an upstream torch layer
)
# Optional dependency: pip install 'qiskit-machine-learning[torch]'
from qiskit_machine_learning.connectors import TorchConnector
model = TorchConnector(qnn, initial_weights=[0.0] * qnn.num_weights)
Use the references for parameter validation, output shapes, exact-vs-sampled semantics, and recovery steps; keep this file as the routing 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).