Go to file
Jun Doi ba9eb905ff
Add simulator_metadata in metadata of SamplerV2 (#2109)
Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>
2024-05-24 14:53:05 +09:00
.github Fix CI failures (#2106) 2024-04-25 16:00:41 +09:00
cmake Remove muparserx from cmake configuration (#2045) 2024-02-02 10:28:12 +09:00
contrib Release Aer 0.14 (#2050) 2024-04-01 18:01:55 +09:00
docs Use sphinx.ext.linkcode for more precise source code links (#2101) 2024-04-18 11:23:31 +09:00
qiskit_aer Add simulator_metadata in metadata of SamplerV2 (#2109) 2024-05-24 14:53:05 +09:00
releasenotes Add simulator_metadata in metadata of SamplerV2 (#2109) 2024-05-24 14:53:05 +09:00
src Always hook omp functions in Mac (#2128) 2024-05-21 10:55:03 +09:00
test Disable test shot_branching on MacOS (#2143) 2024-05-20 21:59:05 +09:00
tools remove import execute (#2041) 2024-02-02 15:09:27 +09:00
.clang-format add code-formatting with black for python and with clang-format for c++ (#1630) 2023-03-13 20:19:06 +00:00
.clang-tidy Modernizing code (#338) 2019-09-26 09:56:15 -04:00
.git-blame-ignore-revs Add git blame ignore file (#1745) 2023-03-14 00:17:15 +00:00
.gitignore Move Aer to its own package (#1526) 2022-08-31 10:33:59 +09:00
.mailmap Update garrison's name in .mailmap (#1444) 2022-02-02 10:15:06 +00:00
.mergify.yml Add mergify configuration (#1518) 2022-05-10 09:26:18 -04:00
.pylintrc add code-formatting with black for python and with clang-format for c++ (#1630) 2023-03-13 20:19:06 +00:00
.stestr.conf Switch group regex to parallel-class 2019-11-14 14:47:30 -05:00
BENCHMARKING.md Prepare for renaming default branch to main (#1233) 2021-04-28 16:15:27 -04:00
CMakeLists.txt Remove muparserx from cmake configuration (#2045) 2024-02-02 10:28:12 +09:00
CODE_OF_CONDUCT.md Qiskit projects point to main CoC (#1049) 2020-11-18 16:41:57 -05:00
CONTRIBUTING.md Remove qiskit.org links (#2057) 2024-02-13 09:52:25 +09:00
LICENSE.txt * Added Apache 2 license 2018-08-29 13:28:45 +02:00
MANIFEST.in Move Aer to its own package (#1526) 2022-08-31 10:33:59 +09:00
README.md Replace example in README to using primitives (#2105) 2024-04-26 11:19:32 +09:00
constraints.txt Add support for running with Python 3.12 (#2022) 2024-01-15 15:13:47 +00:00
pyproject.toml Fix CI failures (#2106) 2024-04-25 16:00:41 +09:00
requirements-dev.txt Update Sphinx theme (#1946) 2023-10-18 17:38:36 +09:00
setup.py Remove qiskit aer translation stage (#2142) 2024-05-20 11:09:37 +09:00
tox.ini Use sphinx.ext.linkcode for more precise source code links (#2101) 2024-04-18 11:23:31 +09:00

README.md

Aer - high performance quantum circuit simulation for Qiskit

License Build Tests

Aer is a high performance simulator for quantum circuits written in Qiskit, that includes realistic noise models.

Installation

We encourage installing Aer via the pip tool (a python package manager):

pip install qiskit-aer

Pip will handle all dependencies automatically for us, and you will always install the latest (and well-tested) version.

To install from source, follow the instructions in the contribution guidelines.

Installing GPU support

In order to install and run the GPU supported simulators on Linux, you need CUDA® 11.2 or newer previously installed. CUDA® itself would require a set of specific GPU drivers. Please follow CUDA® installation procedure in the NVIDIA® web.

If you want to install our GPU supported simulators, you have to install this other package:

pip install qiskit-aer-gpu

The package above is for CUDA&reg 12, so if your system has CUDA® 11 installed, install separate package:

pip install qiskit-aer-gpu-cu11

This will overwrite your current qiskit-aer package installation giving you the same functionality found in the canonical qiskit-aer package, plus the ability to run the GPU supported simulators: statevector, density matrix, and unitary.

Note: This package is only available on x86_64 Linux. For other platforms that have CUDA support, you will have to build from source. You can refer to the contributing guide for instructions on doing this.

Simulating your first Qiskit circuit with Aer

Now that you have Aer installed, you can start simulating quantum circuits using primitives and noise models. Here is a basic example:

$ 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 [ [<psi1(theta1)|H1|psi1(theta1)>,
#              <psi1(theta3)|H3|psi1(theta3)>],
#             [<psi2(theta2)|H2|psi2(theta2)>] ]
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.from_backend(backend)

# run a sampler job on the parameterized circuits with noise model of the actual hardware
job3 = sampler.run([(pqc, theta1), (pqc2, theta2)])
job_result = job3.result()
print(f"Parameterized for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}")

Contribution Guidelines

If you'd like to contribute to Aer, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expected to uphold this code.

We use GitHub issues for tracking requests and bugs. Please use our slack for discussion and simple questions. To join our Slack community use the link. For questions that are more suited for a forum, we use the Qiskit tag in the Stack Exchange.

Next Steps

Now you're set up and ready to check out some of the other examples from the Aer documentation.

Authors and Citation

Aer is the work of many people who contribute to the project at different levels. If you use Qiskit, please cite as per the included BibTeX file.

License

Apache License 2.0