pennylane
できること
PennyLaneは、量子回路の構築と最適化を助けるツールです。PyTorchやJAXなどのAIモデルと組み合わせて、量子計算と古典的な計算(AI)を一緒に使えるため、分子のエネルギー計算や量子回路の検証といった複雑な問題を解けます。
使う場面
- ✓調整可能なパラメータを持つ量子回路を最適化したいとき。
- ✓量子計算と古典的な計算(AI)を組み合わせたモデルを作りたいとき。
- ✓分子のエネルギーを計算したり、量子最適化問題を解いたりしたいとき。
スキルのリンク
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pennylane/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“水素分子のエネルギーを計算する量子回路を作成し、VQEアルゴリズムで最適化してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
PennyLaneでは量子回路を定義し、機械学習のツールを使ってその回路のパラメータを調整できます。回路はお使いのコンピュータ上でシミュレーションすることも、設定すれば実際の量子ハードウェアに送って実行することもできます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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.
…
よくある質問
量子回路とは何ですか?
量子ビット(キュービット)を操作して計算を行うための一連の命令(量子ゲート)のことです。量子コンピュータ向けのプログラムのようなものと考えるとわかりやすいでしょう。
変分量子アルゴリズム(VQE/QAOA)とは何ですか?
調整可能なパラメータを持つ量子回路と古典コンピュータを組み合わせて、分子の最小エネルギーや最適化問題の解など、問題に対する最良の解を見つける手法です。
自分のコンピュータで実行できますか?
はい、PennyLaneはお使いのコンピュータ上で量子回路をシミュレーションできます。実際の量子ハードウェアで実行するには、特定のプロバイダーへのアクセスを設定する必要があります。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 51k
- ランキング
- #3525
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
13c-metabolic-flux
51k炭素13同位体トレーシングのデータを使って代謝フラックスを推定します。細胞の代謝や生化学経路の分析に役立ちます。
adaptyv
51kAdaptyv APIを使ってタンパク質の特性評価実験を設計します。コストの見積もり、配列の提出、ラボの結果の監視を支援します。
aeon
51k時系列データに対して機械学習のタスクを実行します。逐次データの分類、予測、異常検知、パターンの発見に役立ちます。
alphagenome
51k遺伝的変異に対して、事前に計算されたゲノム上の効果を検索します。スコアと説明を提供し、変異がゲノムに与える影響を理解するのに役立ちます。