quantum-qiskit
What it does
The skill gives reference code patterns and fixes for qiskit 2.x. It is for developers and researchers writing variational quantum machine learning code.
When to use it
- ✓When you write Python code that imports qiskit or its machine learning or chemistry packages.
- ✓When you build a variational quantum classifier or a VQE chemistry calculation.
- ✓When you hit a qiskit 2.x migration error or need to add a noise model.
Skill link
https://github.com/aiming-lab/AutoResearchClaw/blob/main/researchclaw/skills/builtin/domain/quantum-qiskit/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Write a variational quantum classifier with a ZZ feature map in qiskit 2.x, and fix the import errors in my script.”
5 new skills a week. 1 minute to read.
How it works
The agent uses current qiskit 2.x patterns for feature maps, ansatz circuits, training, and noise models. It also lists the changes from earlier versions that commonly break code, along with fixes.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
FAQ
Does it cover qiskit 1.x code?
The reference focuses on the qiskit 2.x API and lists the breaking changes from 1.x.
What is a feature map?
A circuit that encodes classical data into quantum states before training.
What is VQE?
A variational method that estimates the ground-state energy of a molecule using a parameterized circuit.
Details
Original description by the author
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`.
Popularity
- GitHub stars
- 15k
- Ranking position
- #11069
- License
- MIT
- Updated
- 8/19/2026
Comments
- …
More skills from this repository
a-evolve
15kHelps your agent improve over repeated runs by diagnosing failures, creating targeted skills from error patterns, and recording lessons for later use.
biology-biopython
15kHelps your agent work with DNA, RNA, and protein sequences using Biopython, including file parsing, sequence calculations, BLAST searches, and database access.
chemistry-rdkit
15kHelps your agent analyze molecules written as SMILES strings with RDKit, including descriptors, fingerprints, similarity, and substructure search.
hypothesis-formulation
15kHelps your agent turn an observation into testable hypotheses, with competing explanations and clear predictions that could prove them wrong.
Similar skills
pytorch-patterns
280kHelps your agent use PyTorch for machine learning models. It applies best practices for efficient model training and ensures reproducible results.
evm-token-decimals
280kHelps your agent avoid errors with decimal numbers across different blockchain networks. It ensures token values are accurate in transactions and calculations.
ito-inference
280kLets your agent check the availability of AI models for use. It connects the compute request with the ready model service.