pennylane
Skill này làm gì
PennyLane giúp xây dựng và tối ưu mạch lượng tử. Nó cho phép kết hợp tính toán lượng tử với các mô hình trí tuệ nhân tạo (như PyTorch hoặc JAX) để giải các bài toán phức tạp, như tính năng lượng phân tử hoặc kiểm tra mạch lượng tử.
Khi nào nên dùng
- ✓Để tối ưu mạch lượng tử có các tham số điều chỉnh được.
- ✓Để xây dựng mô hình kết hợp tính toán lượng tử và cổ điển (AI).
- ✓Để tính năng lượng phân tử hoặc giải các bài toán tối ưu lượng tử.
Liên kết skill
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pennylane/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
“Tạo một mạch lượng tử để tính năng lượng phân tử hydro và tối ưu nó bằng thuật toán VQE.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
PennyLane cho phép bạn định nghĩa mạch lượng tử, rồi dùng các công cụ học máy để điều chỉnh tham số của mạch. Nó có thể mô phỏng mạch trên máy tính hoặc, nếu được cấu hình, gửi mạch đến phần cứng lượng tử thật.
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.
PennyLane
When to use
Use PennyLane to optimize parameterized circuits, build hybrid quantum-classical models, estimate molecular energies, or compare a validated circuit across devices. This skill targets stable PennyLane 0.45.1. The local examples use small synthetic systems; successful optimization does not establish quantum advantage, molecular accuracy, or hardware fidelity.
Installation
Create a dedicated environment; provider plugins and compiler dependencies should be resolved separately from unrelated scientific packages:
uv venv --python 3.13 .venv-pennylane
uv pip install --python .venv-pennylane/bin/python "pennylane==0.45.1"
PennyLane 0.45 requires NumPy 2+. Core installation includes Lightning. For ML, use the tested JAX 0.7.1/JAXlib 0.7.1 pair or PyTorch; do not assume the latest JAX is supported by this PennyLane release. See device setup for optional plugin versions and their verification limits.
Workflow
- Fix the problem convention: feature ordering and label encoding for ML; Hamiltonian sign for optimization; units, charge, multiplicity, basis, active space and mapping for chemistry.
- Build a small analytic
default.qubitcircuit. Keep the quantum function separate from the QNode when reusing it on another backend. - Check a known value and a gradient against an analytic or finite-difference
result before training. Use trainable
pennylane.numpyarrays for Autograd, framework-native tensors for Torch/JAX. - Optimize while recording objective, gradient norm, seeds, ansatz shape and
package versions.
step_and_costreturns the cost before its update; evaluate the objective again for final reporting. - Validate independently: held-out examples and classical baselines for ML; particle number and a sector-appropriate classical reference for VQE; enumerated small instances for QAOA.
- Introduce finite shots/noise, report uncertainty, inspect decomposed resources, then select a current accessible hardware backend and execution budget. Plugin portability does not guarantee identical gates, measurements or gradients.
Quick start: value, gradient and optimization
This self-contained example is executed by the skill's tests.
import pennylane as qml
from pennylane import numpy as np
dev = qml.device("default.qubit", wires=1)
@qml.qnode(dev, interface="autograd", diff_method="backprop")
def energy(theta):
qml.RY(theta, wires=0)
return qml.expval(qml.Z(0))
theta = np.array(0.3, requires_grad=True)
assert np.allclose(energy(theta), np.cos(theta))
assert np.allclose(qml.grad(energy)(theta), -np.sin(theta))
opt = qml.GradientDescentOptimizer(stepsize=0.2)
for _ in range(80):
theta = opt.step(energy, theta)
final_energy = float(energy(theta))
assert final_energy < -0.999
print(f"[OK] final expectation = {final_energy:.6f}")
Load the relevant reference
- Getting started: QNodes, shots, random streams, trainability, batched parameters and simulator selection.
- Quantum circuits: controls, measurement feedback, wire ordering, QFT, transforms and current resource access.
- Quantum ML: executed TorchLayer and JAX training, stable classifier loss, feature scaling and evaluation.
- Quantum chemistry: H2 UCCSD, units, particle sector checks, dipoles, active spaces, geometry and excited-state caveats.
- Devices: simulators, provider contracts, credentials, current target discovery and source-only integration boundaries.
- Optimization: gradient checks, SPSA, QNG, MaxCut sign and exact QUBO-to-Ising conversion.
- Advanced features: templates, noise, parametrized Hamiltonian evolution, Catalyst and error-correction examples.
Failure checks
- Samples/counts require finite shots; states require a supporting simulator.
Use
qml.set_shotson the QNode rather than mutating device shots. - Mid-circuit measurement values are symbolic. Use
qml.cond, not Pythonif m. qml.specsin 0.45.1 returnsCircuitSpecs; access.resources, not obsolete top-level dictionary keys. Record the transform level and account for split tapes.qml.qaoa.maxcutproduces negative cut size. Minimize it directly.
…
Câu hỏi thường gặp
Mạch lượng tử là gì?
Đó là chuỗi các chỉ dẫn (cổng lượng tử) thao tác trên các bit lượng tử (qubit) để thực hiện tính toán. Bạn có thể coi nó như một chương trình cho máy tính lượng tử.
Thuật toán lượng tử biến thiên (VQE/QAOA) là gì?
Đây là các phương pháp dùng mạch lượng tử có tham số điều chỉnh được cùng với máy tính cổ điển để tìm lời giải tốt nhất cho bài toán, như năng lượng tối thiểu của một phân tử hoặc bài toán tối ưu.
Tôi có thể chạy công cụ này trên máy của mình không?
Có. PennyLane có thể mô phỏng mạch lượng tử trên máy tính của bạn. Để chạy trên phần cứng lượng tử thật, bạn cần thiết lập quyền truy cập với một nhà cung cấp cụ thể.
Chi tiết
Mô tả gốc của tác giả
Builds and differentiates PennyLane quantum circuits, hybrid PyTorch or JAX models, molecular VQE and QAOA workflows. Use for variational quantum algorithms, quantum machine learning, simulator validation, and moving validated circuits to provider plugins. For hardware-specific compilation use qiskit or cirq; for open-system dynamics use qutip.
Độ phổ biến
- Sao GitHub
- 51k
- Vị trí xếp hạng
- #3525
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
13c-metabolic-flux
51kƯớc tính thông lượng chuyển hóa bằng dữ liệu theo dõi đồng vị carbon-13. Hữu ích để phân tích chuyển hóa tế bào và các con đường sinh hóa.
adaptyv
51kThiết kế thí nghiệm đặc trưng protein bằng Adaptyv API. Hỗ trợ ước tính chi phí, gửi trình tự và theo dõi kết quả phòng thí nghiệm.
aeon
51kThực hiện các tác vụ học máy trên dữ liệu chuỗi thời gian. Hữu ích để phân loại, dự báo, phát hiện bất thường và tìm mẫu trong dữ liệu tuần tự.
alphagenome
51kTra cứu các tác động di truyền đã được tính trước cho biến thể gen. Cung cấp điểm số và giải thích để hiểu ảnh hưởng của biến thể lên bộ gen.
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.