Hardware-agnostic quantum ML framework with automatic differentiation. Use when training quantum circuits via gradients, building hybrid quantum-classical models, or needing device portability across IBM/Google/Rigetti/IonQ. Best for variational algorithms (VQE, QAOA), quantum neural networks, and integration with PyTorch or JAX. For hardware-specific optimizations use qiskit (IBM) or cirq (Google); for open quantum systems use qutip.
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills --skill pennylane
PennyLane is a quantum computing library that enables training quantum computers like neural networks. It provides automatic differentiation of quantum circuits, device-independent programming, and seamless integration with classical machine learning frameworks.
PennyLane 0.45.0 requires Python 3.11 or newer. Install using uv with pinned versions for reproducible environments:
uv pip install "pennylane==0.45.0"
For quantum hardware access, install the plugin matching the target provider. Start from a clean environment when adding or upgrading Qiskit because its dependency graph is strict.
# IBM Quantum
uv pip install "pennylane-qiskit==0.45.0"
# Amazon Braket
uv pip install "amazon-braket-pennylane-plugin==1.34.1"
# Google Cirq
uv pip install "pennylane-cirq==0.44.0"
# Rigetti Forest
uv pip install "pennylane-rigetti==0.40.0"
# IonQ
uv pip install "pennylane-ionq==0.45.0"
# High-performance local simulators
uv pip install "pennylane-lightning==0.45.0"
# Catalyst JIT compilation
uv pip install "pennylane-catalyst==0.15.0"
Build a quantum circuit and optimize its parameters:
import pennylane as qml
from pennylane import numpy as np
# Create device
dev = qml.device('default.qubit', wires=2)
# Define quantum circuit
@qml.qnode(dev)
def circuit(params):
qml.RX(params[0], wires=0)
qml.RY(params[1], wires=1)
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0))
# Optimize parameters
opt = qml.GradientDescentOptimizer(stepsize=0.1)
params = np.array([0.1, 0.2], requires_grad=True)
for i in range(100):
params = opt.step(circuit, params)
Build circuits with gates, measurements, and state preparation. See references/quantum_circuits.md for:
Create hybrid quantum-classical models. See references/quantum_ml.md for:
Simulate molecules and compute ground state energies. See references/quantum_chemistry.md for:
Execute on simulators or quantum hardware. See references/devices_backends.md for:
Train quantum circuits with various optimizers. See references/optimization.md for:
Leverage templates, transforms, and compilation. See references/advanced_features.md for:
# 1. Define ansatz
@qml.qnode(dev)
def classifier(x, weights):
# Encode data
qml.AngleEmbedding(x, wires=range(4))
# Variational layers
qml.StronglyEntanglingLayers(weights, wires=range(4))
return qml.expval(qml.PauliZ(0))
# 2. Train
opt = qml.AdamOptimizer(stepsize=0.01)
weights = np.random.random((3, 4, 3)) # 3 layers, 4 wires
for epoch in range(100):
for x, y in zip(X_train, y_train):
weights = opt.step(lambda w: (classifier(x, w) - y)**2, weights)
from pennylane import qchem
# 1. Build Hamiltonian
symbols = ['H', 'H']
geometry = np.array([[0.0, 0.0, -0.66140414], [0.0, 0.0, 0.66140414]])
molecule = qchem.Molecule(symbols, geometry)
H, n_qubits = qchem.molecular_hamiltonian(molecule)
hf_state = qchem.hf_state(electrons=2, orbitals=n_qubits)
singles, doubles = qchem.excitations(electrons=2, orbitals=n_qubits)
s_wires, d_wires = qchem.excitations_to_wires(singles, doubles)
# 2. Define ansatz
@qml.qnode(dev)
def vqe_circuit(params):
qml.BasisState(hf_state, wires=range(n_qubits))
qml.UCCSD(params, wires=range(n_qubits), s_wires=s_wires, d_wires=d_wires)
return qml.expval(H)
# 3. Optimize
opt = qml.AdamOptimizer(stepsize=0.1)
params = np.zeros(len(singles) + len(doubles), requires_grad=True)
for i in range(100):
params, energy = opt.step_and_cost(vqe_circuit, params)
print(f"Step {i}: Energy = {energy:.6f} Ha")
# Same circuit, different backends
circuit_def = lambda dev: qml.qnode(dev)(circuit_function)
# Test on simulator
dev_sim = qml.device('default.qubit', wires=4)
result_sim = circuit_def(dev_sim)(params)
# Run on quantum hardware
from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=4)
dev_hw = qml.device('qiskit.remote', wires=backend.num_qubits, backend=backend)
result_hw = circuit_def(dev_hw)(params)
For comprehensive coverage of specific topics, consult the reference files:
references/getting_started.md - Installation, basic concepts, first stepsreferences/quantum_circuits.md - Gates, measurements, circuit patternsreferences/quantum_ml.md - Hybrid models, framework integration, QNNsreferences/quantum_chemistry.md - VQE, molecular Hamiltonians, chemistry workflowsreferences/devices_backends.md - Simulators, hardware plugins, device configurationreferences/optimization.md - Optimizers, gradients, variational algorithmsreferences/advanced_features.md - Templates, transforms, JIT compilation, noisedefault.qubit before deploying to hardwareqml.specs() to analyze circuit complexity10. Compile when possible - Use Catalyst JIT for performance-critical code
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
Access NCBI GEO for gene expression/genomics data. Search/download microarray and RNA-seq datasets (GSE, GSM, GPL), retrieve SOFT/Matrix files, for transcriptomics and expression analysis.
Bayesian modeling with PyMC. Build hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior checks, for probabilistic programming and inference.
Multi-objective optimization framework. NSGA-II, NSGA-III, MOEA/D, Pareto fronts, constraint handling, benchmarks (ZDT, DTLZ), for engineering design and optimization problems.
Statistical modeling toolkit. OLS, GLM, logistic, ARIMA, time series, hypothesis tests, diagnostics, AIC/BIC, for rigorous statistical inference and econometric analysis.
Add unsigned integer (uint) type support to PyTorch operators by updating AT_DISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.
Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.
Write docstrings for PyTorch functions and methods following PyTorch conventions. Use when writing or updating docstrings in PyTorch code.
Take k-dense-ai/pennylane from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, uv.
Without those the skill loads but fails at the first command.