Qiskit/qiskit-aer

GitHub: Qiskit/qiskit-aer

作为 Qiskit 生态的核心组件,Aer 提供了带有噪声模型的高性能量子电路模拟功能,让开发者能在经典计算机上高保真地预演量子程序。

Stars: 642 | Forks: 420

# Aer - 用于 Qiskit 的高性能量子电路模拟器 [![License](https://img.shields.io/github/license/Qiskit/qiskit-aer.svg?style=popout-square)](https://opensource.org/licenses/Apache-2.0) [![Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/428bdbdaac130054.svg)](https://github.com/Qiskit/qiskit-aer/actions/workflows/build.yml) [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/8123a3aacd130056.svg)](https://github.com/Qiskit/qiskit-aer/actions/workflows/tests.yml) [![](https://img.shields.io/github/release/Qiskit/qiskit-aer.svg?style=popout-square)](https://github.com/Qiskit/qiskit-aer/releases) [![](https://img.shields.io/pypi/dm/qiskit-aer.svg?style=popout-square)](https://pypi.org/project/qiskit-aer/) **Aer** 是一个用于 Qiskit 编写的量子电路的高性能模拟器,包含逼真的噪声模型。 ## 安装 我们鼓励通过 pip 工具(一个 python 包管理器)安装 Aer: ``` pip install qiskit-aer ``` Pip 会自动为我们处理所有依赖项,并且您将始终安装最新的(且经过良好测试的)版本。 要从源码安装,请遵循[贡献指南](CONTRIBUTING.md)中的说明。 ## 安装 GPU 支持 为了在 Linux 上安装和运行支持 GPU 的模拟器,您需要预先安装 CUDA® 11.2 或更新版本。 CUDA® 本身需要一组特定的 GPU 驱动程序。请按照 NVIDIA® [网站](https://www.nvidia.com/drivers)上的 CUDA® 安装程序进行操作。 如果您想安装我们支持 GPU 的模拟器,则必须安装此另一个包: ``` pip install qiskit-aer-gpu ``` 上面的包适用于 CUDA® 12,因此如果您的系统安装了 CUDA® 11,请安装单独的包: ``` pip install qiskit-aer-gpu-cu11 ``` 这将覆盖您当前的 `qiskit-aer` 包安装,为您提供与标准 `qiskit-aer` 包相同的功能, 加上运行支持 GPU 的模拟器的能力:statevector、density matrix 和 unitary。 **注意**:此包仅在 x86_64 Linux 上可用。对于其他支持 CUDA 的平台,您必须从源码构建。您可以参考 [贡献指南](CONTRIBUTING.md#building-with-gpu-support) 获取有关执行此操作的说明。 ## 使用 Aer 模拟您的第一个 Qiskit 电路 现在您已经安装了 Aer,您可以开始使用原语 (primitives) 和噪声模型模拟量子电路。这是一个基本示例: ``` $ python ``` ``` from qiskit import transpile from qiskit.circuit.library import RealAmplitudes from qiskit.quantum_info import SparsePauliOp from qiskit_aer import AerSimulator sim = AerSimulator() # -------------------------- # Simulating using estimator #--------------------------- from qiskit_aer.primitives import EstimatorV2 psi1 = transpile(RealAmplitudes(num_qubits=2, reps=2), sim, optimization_level=0) psi2 = transpile(RealAmplitudes(num_qubits=2, reps=3), sim, optimization_level=0) H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)]) H2 = SparsePauliOp.from_list([("IZ", 1)]) H3 = SparsePauliOp.from_list([("ZI", 1), ("ZZ", 1)]) theta1 = [0, 1, 1, 2, 3, 5] theta2 = [0, 1, 1, 2, 3, 5, 8, 13] theta3 = [1, 2, 3, 4, 5, 6] estimator = EstimatorV2() # calculate [ [, # ], # [] ] job = estimator.run( [ (psi1, [H1, H3], [theta1, theta3]), (psi2, H2, theta2) ], precision=0.01 ) result = job.result() print(f"expectation values : psi1 = {result[0].data.evs}, psi2 = {result[1].data.evs}") # -------------------------- # Simulating using sampler # -------------------------- from qiskit_aer.primitives import SamplerV2 from qiskit import QuantumCircuit # create a Bell circuit bell = QuantumCircuit(2) bell.h(0) bell.cx(0, 1) bell.measure_all() # create two parameterized circuits pqc = RealAmplitudes(num_qubits=2, reps=2) pqc.measure_all() pqc = transpile(pqc, sim, optimization_level=0) pqc2 = RealAmplitudes(num_qubits=2, reps=3) pqc2.measure_all() pqc2 = transpile(pqc2, sim, optimization_level=0) theta1 = [0, 1, 1, 2, 3, 5] theta2 = [0, 1, 2, 3, 4, 5, 6, 7] # initialization of the sampler sampler = SamplerV2() # collect 128 shots from the Bell circuit job = sampler.run([bell], shots=128) job_result = job.result() print(f"counts for Bell circuit : {job_result[0].data.meas.get_counts()}") # run a sampler job on the parameterized circuits job2 = sampler.run([(pqc, theta1), (pqc2, theta2)]) job_result = job2.result() print(f"counts for parameterized circuit : {job_result[0].data.meas.get_counts()}") # -------------------------------------------------- # Simulating with noise model from actual hardware # -------------------------------------------------- from qiskit_ibm_runtime import QiskitRuntimeService provider = QiskitRuntimeService(channel='ibm_quantum', token="set your own token here") backend = provider.get_backend("ibm_kyoto") # create sampler from the actual backend sampler = SamplerV2.from_backend(backend) # run a sampler job on the parameterized circuits with noise model of the actual hardware bell_t = transpile(bell, AerSimulator(basis_gates=["ecr", "id", "rz", "sx"]), optimization_level=0) job3 = sampler.run([bell_t], shots=128) job_result = job3.result() print(f"counts for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}") ``` ## 贡献指南 如果您想为 Aer 做贡献,请查看我们的 [贡献指南](CONTRIBUTING.md)。本项目遵守 Qiskit 的[行为准则](CODE_OF_CONDUCT.md)。通过参与,您被期望维护此准则。 我们使用 [GitHub issues](https://github.com/Qiskit/qiskit-aer/issues) 跟踪请求和错误。请使用我们的 [slack](https://qiskit.slack.com) 进行讨论和简单提问。要加入我们的 Slack 社区,请使用此[链接](https://qiskit.slack.com/join/shared_invite/zt-fybmq791-hYRopcSH6YetxycNPXgv~A#/)。对于更适合在论坛上提出的问题,我们在 [Stack Exchange](https://quantumcomputing.stackexchange.com/questions/tagged/qiskit) 中使用 Qiskit 标签。 ## 下一步 现在您已经设置好并准备查看 [Aer 文档](https://qiskit.github.io/qiskit-aer/)中的一些其他示例。 ## 作者和引用 Aer 是许多在不同层面为项目做出贡献的[人](https://github.com/Qiskit/qiskit-aer/graphs/contributors)的成果。 如果您使用 Qiskit,请按照包含的 [BibTeX 文件](https://github.com/Qiskit/qiskit/blob/main/CITATION.bib)进行引用。 ## 许可证 [Apache License 2.0](LICENSE.txt)
标签:C++, CUDA, DNS解析, Python, Qiskit, Qiskit Aer, Vectored Exception Handling, 后端模拟器, 噪声模型, 开源项目, 数据擦除, 无后门, 科学计算, 逆向工具, 量子模拟, 量子电路模拟器, 量子算法, 量子计算, 量子软件开发工具包, 高性能仿真, 高性能计算