quantum-qiskit
Skill này làm gì
Skill cung cấp mẫu code tham chiếu và cách sửa lỗi cho qiskit 2.x. Skill dành cho lập trình viên và nhà nghiên cứu viết code học máy lượng tử biến thiên.
Khi nào nên dùng
- ✓Khi bạn viết code Python có import qiskit hoặc các gói học máy và hóa học của nó.
- ✓Khi bạn xây dựng bộ phân loại lượng tử biến thiên hoặc một phép tính hóa học VQE.
- ✓Khi bạn gặp lỗi khi chuyển sang qiskit 2.x hoặc cần thêm một mô hình nhiễu.
Liên kết skill
https://github.com/aiming-lab/AutoResearchClaw/blob/main/researchclaw/skills/builtin/domain/quantum-qiskit/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy viết một bộ phân loại lượng tử biến thiên với feature map ZZ trong qiskit 2.x, và sửa các lỗi import trong script của tôi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent dùng các mẫu hiện hành của qiskit 2.x cho feature map, mạch ansatz, huấn luyện và mô hình nhiễu. Agent cũng liệt kê những thay đổi từ phiên bản cũ thường làm code lỗi, kèm cách sửa.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Qiskit 2.x reference for variational quantum machine learning
This skill is a canonical reference for writing Python code that uses
qiskit 2.x and its ecosystem (qiskit_aer, qiskit_algorithms,
qiskit_machine_learning, qiskit_nature). It documents the API shapes
that work in qiskit 2.x today, the qiskit-1.x → 2.x migration breaks
that affect VQE and chemistry code, and a small number of common
mistakes with concrete fixes.
Section overview:
- Imports
- Data-encoding feature maps
- Variational ansatz construction
- VQC training (qiskit_machine_learning)
- VQE for chemistry (qiskit 2.x compatible)
- MPS-structured circuits
- Noise model integration
- qiskit 2.x compatibility notes
- Common errors and fixes
- Autoclaw integration: metric logging convention
1. Imports
import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit import ParameterVector
from qiskit.circuit.library import (
ZFeatureMap,
ZZFeatureMap,
StatePreparation,
EfficientSU2,
)
from qiskit.primitives import StatevectorSampler, StatevectorEstimator # V2 primitives
from qiskit.quantum_info import Statevector, SparsePauliOp
from qiskit_aer import AerSimulator
from qiskit_algorithms.optimizers import SPSA, COBYLA, L_BFGS_B, ADAM
from qiskit_algorithms.utils import algorithm_globals
from qiskit_machine_learning.algorithms.classifiers import VQC
For chemistry:
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.mappers import ParityMapper, JordanWignerMapper
Do not import from qiskit_nature.second_q.algorithms or
qiskit_algorithms.VQE under qiskit 2.x (they fail at import time, see
section 8).
2. Data-encoding feature maps
Three standard families. Each builder returns a parameterized circuit
suitable for use as the feature_map argument of VQC or for direct
contraction with a variational ansatz.
def build_angle_encoding(num_features: int) -> QuantumCircuit:
"""Hadamard plus single-qubit Z-rotation per feature.
Mathematically equivalent to ZFeatureMap(reps=1).
"""
return ZFeatureMap(feature_dimension=num_features, reps=1)
def build_amplitude_encoding(num_features: int):
"""Load an L2-normalized, zero-padded input as the amplitudes of a
quantum state. The encoding uses ceil(log2(num_features)) qubits.
Returns (circuit, parameter_vector, num_qubits). The caller binds
parameters per-sample via the helper below.
"""
num_qubits = int(np.ceil(np.log2(max(num_features, 2))))
full_dim = 2 ** num_qubits
params = ParameterVector("x_amp", full_dim)
qc = QuantumCircuit(num_qubits)
qc.append(StatePreparation(list(params)), range(num_qubits))
return qc, params, num_qubits
def amplitude_binding(x: np.ndarray, params, num_qubits: int) -> dict:
"""Build the parameter-value dict for a single input sample."""
x_norm = x / max(float(np.linalg.norm(x)), 1e-12)
padded = np.zeros(2 ** num_qubits, dtype=np.float64)
padded[: len(x_norm)] = x_norm
padded = padded / max(float(np.linalg.norm(padded)), 1e-12)
return {params[i]: float(padded[i]) for i in range(len(padded))}
def build_zz_feature_map(num_features: int) -> QuantumCircuit:
"""Two repetitions of Hadamard plus pairwise ZZ entangling rotations."""
return ZZFeatureMap(
feature_dimension=num_features, reps=2, entanglement="linear"
)
To verify that two encoders produce distinguishable output for a fixed input (catches dispatch bugs in code that constructs multiple encoders in a loop):
def assert_different_output_states(qc_a, qc_b, x, tol: float = 1e-6):
sv_a = Statevector(qc_a.assign_parameters(x))
sv_b = Statevector(qc_b.assign_parameters(x))
diff = float(np.linalg.norm(sv_a.data - sv_b.data))
assert diff > tol, f"encoders produced identical states (diff={diff})"
3. Variational ansatz construction
def build_ansatz(num_qubits: int, reps: int = 2) -> QuantumCircuit:
"""Hardware-efficient ansatz with alternating Pauli rotations
and a linear chain of CNOT entanglers. Trainable parameter count
is (reps + 1) * num_qubits for the default su2_gates = ['ry']."""
return EfficientSU2(
num_qubits=num_qubits, reps=reps, entanglement="linear"
)
ansatz.num_parameters gives the trainable parameter count, useful
for matching parameter budgets against clas
Câu hỏi thường gặp
Skill có bao phủ code qiskit 1.x không?
Tài liệu tập trung vào API qiskit 2.x và liệt kê các thay đổi gây lỗi so với 1.x.
Feature map là gì?
Là một mạch mã hóa dữ liệu cổ điển thành trạng thái lượng tử trước khi huấn luyện.
VQE là gì?
Là một phương pháp biến thiên ước lượng năng lượng trạng thái nền của một phân tử bằng một mạch có tham số.
Chi tiết
Mô tả gốc của tác giả
Reference qiskit 2.x patterns for variational quantum machine learning. Covers data-encoding feature maps, variational quantum classifier (VQC) training, variational quantum eigensolver (VQE) for chemistry, matrix-product-state circuits, and noise model integration. Use when writing Python code that imports `qiskit`, `qiskit_aer`, `qiskit_algorithms`, `qiskit_machine_learning`, or `qiskit_nature`.
Độ phổ biến
- Sao GitHub
- 15k
- Vị trí xếp hạng
- #11069
- Giấy phép
- MIT
- Cập nhật
- 19/8/2026
Bình luận
- …
Thêm skill từ kho mã này
a-evolve
15kGiúp agent cải thiện qua nhiều lần chạy bằng cách chẩn đoán lỗi, tạo skill nhắm đúng từ các mẫu lỗi và ghi lại bài học để dùng sau.
biology-biopython
15kGiúp agent làm việc với chuỗi DNA, RNA và protein bằng Biopython, bao gồm phân tích file, tính toán trên chuỗi, tìm kiếm BLAST và truy cập cơ sở dữ liệu.
chemistry-rdkit
15kGiúp agent phân tích phân tử viết dưới dạng chuỗi SMILES bằng RDKit, bao gồm descriptor, fingerprint, độ tương đồng và tìm kiếm cấu trúc con.
hypothesis-formulation
15kGiúp agent biến một quan sát thành các giả thuyết có thể kiểm tra, kèm các lời giải thích cạnh tranh và dự đoán rõ ràng có thể bác bỏ chúng.
Skill tương tự
pytorch-patterns
280kGiúp agent của bạn dùng PyTorch cho các mô hình học máy. Áp dụng thực hành tốt nhất để huấn luyện mô hình hiệu quả và đảm bảo kết quả có thể lặp lại.
evm-token-decimals
280kGiúp agent tránh lỗi về số thập phân khi làm việc với các mạng blockchain khác nhau. Đảm bảo giá trị token chính xác trong giao dịch và phép tính.
ito-inference
280kGiúp agent kiểm tra xem các mô hình AI đã sẵn sàng để dùng chưa. Kết nối yêu cầu tài nguyên tính toán với dịch vụ mô hình đã sẵn sàng.