跳到正文
Skillpedia
智能体51k · #3551

qiskit

它能做什么

Qiskit 是一个用于在量子计算机上创建和运行程序的工具。你可以用它搭建量子线路、模拟线路的运行结果,还能把线路提交到真实的机器上执行。

适用场景

  • ✓当你想在本地测试量子计算的想法时。
  • ✓当你想准备实验并提交到 IBM 量子计算机上运行时。
  • ✓当你开发需要模拟或在真实硬件上运行的量子算法时。

技能链接

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/qiskit/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/qiskit/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“帮我创建一个简单的量子线路,包含两个量子比特,对第一个量子比特施加一个 H 门,并在两个量子比特之间施加一个 CX 门,然后模拟运行结果。”

每周 5 个新技能,1 分钟读完。

工作原理

Qiskit 的工作方式是把你的指令转换成量子计算机能够理解的量子操作。它既可以在普通电脑上模拟这些操作,也可以把它们发送到真实的量子处理器上运行。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Qiskit

Use current Qiskit 2.x APIs to build circuits, prepare hardware-compatible instruction set architecture (ISA) circuits, and execute them through V2 primitives.

Reviewed 2026-10-01 with local tests on qiskit==2.5.2, qiskit-ibm-runtime==0.50.0, and qiskit-aer==0.17.2. IBM account, QPU, session, and batch examples are illustrative and documentation/source-checked; no remote workloads were submitted. See references/sources.md for the verification boundary.

Runtime 0.50 deprecates the top-level SamplerV2/EstimatorV2 implementations. New code imports Sampler from qiskit_ibm_runtime.executor_sampler and Estimator from qiskit_ibm_runtime.executor_estimator. These still implement the V2 PUB interface, using client-side processing and Executor. Use option models from qiskit_ibm_runtime.options_models.

Choose the Right Path

Goal Recommended interface
Ideal evolution with finite-shot sampling qiskit.primitives.StatevectorSampler
Exact local expectation values qiskit.primitives.StatevectorEstimator
High-performance or noisy simulation Qiskit Aer
IBM QPU sampling qiskit_ibm_runtime.executor_sampler.Sampler
IBM QPU expectation values and mitigation qiskit_ibm_runtime.executor_estimator.Estimator
Backend without native primitives BackendSamplerV2 or BackendEstimatorV2
Open-system or master-equation dynamics Prefer QuTiP
Differentiable quantum machine learning Prefer PennyLane unless Qiskit integration is required

Installation

Create an isolated environment and install only the components needed:

uv venv --python 3.13
source .venv/bin/activate

# Core SDK plus plotting support
uv pip install "qiskit[visualization]==2.5.2"

# Add only when needed
uv pip install "qiskit-ibm-runtime==0.50.0"
uv pip install "qiskit-aer==0.17.2"

Do not install qiskit-terra; it was superseded by the qiskit distribution. Qiskit Runtime, Aer, Nature, Machine Learning, Optimization, and Algorithms are separate distributions.

For IBM account setup, CI-safe credential handling, optional packages, and environment repair, read references/setup.md.

Core Workflow

Follow this sequence for every hardware-oriented workload:

  1. Map the problem to a circuit and, for Estimator, one or more observables.
  2. Optimize the parameterized circuit once for the selected backend.
  3. Apply the layout to every observable.
  4. Execute ISA circuits through a V2 primitive using Primitive Unified Blocs (PUBs).
  5. Analyze register-aware results, metadata, uncertainty, and resource usage.

Do not bind and retranspile a parameterized circuit inside every optimizer iteration. Transpile the parameterized circuit once, then pass parameter arrays in PUBs.

Quick Local Sampling

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()  # creates the classical register named "meas"

sampler = StatevectorSampler(seed=7)
pub_result = sampler.run([circuit], shots=1024).result()[0]
counts = pub_result.data.meas.get_counts()
print(counts)

Sampler V2 preserves shots and classical-register structure. Access the register by its actual name; measure_all() uses meas.

For circuits with multiple classical registers, each register’s counts are a marginal distribution. Preserve shot alignment when computing cross-register correlations; multiplying marginal frequencies destroys those correlations. Use SamplerPubResult.join_data with an explicit register order for joint bitstrings and record that order in the result labels. Qiskit 2.5.2 puts the first joined BitArray register in the least-significant bits, contrary to the current docstring; verify with an asymmetric state. See references/primitives.md.

Quick Local Estimation

import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.primitives import StatevectorEstimator
from qiskit.quantum_info import SparsePauliOp

theta = Parameter("theta")
circuit = QuantumCircuit(2)
circuit.ry(theta, 0)
circuit.cx(0, 1)

observable = SparsePauliOp.from_list([("ZZ", 1.0), ("XX", 0.5)])
parameter_values = [[0.0], [np.pi / 4], [np.pi / 2]]

estimator = StatevectorEstimator(seed=7)
pub = (circuit, observable, parameter_values)

…
常见问题

Qiskit 中的 'primitives' 是什么?

Primitives(原语)是一些基础组件,能简化你与量子模拟器和硬件的交互,例如获取采样结果或期望值。

什么是 'transpilation'?

Transpilation(转译优化)是对你的量子线路进行优化的过程,使它能在你所用的特定量子硬件上高效运行。

我能在自己的电脑上使用 Qiskit 吗?

可以。你可以在本地电脑上用 Qiskit 模拟量子线路,不需要真正的量子计算机。

详情

作者的原始描述

Builds, simulates, transpiles, and executes quantum circuits with Qiskit and IBM Quantum Runtime. Use for Qiskit 2.x circuits and operators, V2 Sampler or Estimator primitives, target-aware transpilation, local or noisy simulation, IBM QPU execution, Runtime sessions or batches, error mitigation, and Qiskit ecosystem packages.

repo: K-Dense-AI/scientific-agent-skills

热度

GitHub 星标
51k
排名
#3551
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能