技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
data-circuits-connectors【数据与研究】Operate Qiskit Machine Learning's built-in datasets, circuit helpers, reference primitives, TorchConnector integration, and shared validation utilities.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
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.
qnn_circuit for a feature-map/ansatz pair or
raw_feature_vector only for power-of-two amplitude dimensions.QMLEstimator() and QMLSampler() are exact by default; nonzero estimator
precision or finite sampler shots delegates to the corresponding Qiskit
reference primitive behavior.torch extra, set input_gradients=True on
the QNN when upstream input gradients are needed, then use
TorchConnector. Keep sparse settings consistent between the QNN and
connector.python /path/to/this/skill/scripts/check_install.py --help,
dataset_smoke.py --help, and torch_connector_smoke.py --help.ad_hoc_data
returns rows of length n; phase-of-matter and entanglement datasets return
state vectors of dimension 2**n (entanglement ndarray formatting adds a
final singleton axis). A statevector feature of dimension 2**n needs an
n-qubit circuit.(x_train, y_train, x_test, y_test); include_sample_total=True appends a
fifth array.ad_hoc_data and entanglement concentration
use qiskit_machine_learning.utils.algorithm_globals.random_seed; phase of
matter has its own seed argument. For a PyTorch workflow also call
torch.manual_seed if randomized PyTorch parameters or data ordering must
be repeatable.one_hot mode.raw_feature_vector(feature_dimension) requires a positive power of two and
creates log2(feature_dimension) qubits. Its parameterized initialize
instruction is only defined after all amplitudes are bound and is unsuitable
for gradient-based circuit optimization.qnn_circuit returns (circuit, feature_map.parameters, ansatz.parameters).
Explicit feature map and ansatz circuits should have matching qubit counts.
The legacy num_qubits-based padding/alignment path is deprecated; construct
matching circuits explicitly for forward compatibility.TorchConnector(sparse=True) is valid only when neural_network.sparse is
also true and requires the sparse extra. A dense connector can materialize
a sparse QNN result, but a sparse connector cannot wrap a dense QNN.torch.cuda.is_available() before
selecting cuda. CPU is the portable default. Do not infer CUDA support from
the package being importable.scripts/check_install.pyscripts/dataset_smoke.pyscripts/torch_connector_smoke.pyfrom 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.