Skip to content

Commit b315c4f

Browse files
doichanjmelechlapsonEric-Arellano
authored
Release 0.14.1 (#2099)
* Fix AerCompiler to use custom pass manager to decompose control flow ops (#2095) * Fix AerCompiler to use basis_gates built from input circuit * use custom pass manager to decompose dontrol flow ops * remove unused import * Use sphinx.ext.linkcode for more precise source code links (#2101) * switched links to using sphinx.ext.linkcode * added release note * added check for qiskit methods * remove whitespace * removed regex subsitution Co-authored-by: Eric Arellano <[email protected]> * Update tox.ini Co-authored-by: Eric Arellano <[email protected]> * made updates following Eric's review * made final line more readable * cast filename to str * re-added regex sub --------- Co-authored-by: Eric Arellano <[email protected]> * Fix noise sampling on shot-branching (#2098) * Fix noise sampling on shot-branching * format * fix runtime noise sampling * remove copying branch * fix batch GPU * format * set initial value to Op structure * format * format * test * test * fix use of additional_ops.size() * fix error * fix remove_empty_branches * test * test * test * test * Fixes for dependency issues caused by 0.14 release (#2094) * Fixes for dependency issues * lint * lint * lint * fix release note * fix sampler * fix sampler * fix sampler * fix sampler * remove skip cp38 * hide primitives V2 for qiskit < 1.0 * lint * add test case for sampling measure for large stabilizer circuit * reduce warning * replace test case for large stabilizer with GHZ circuit * format * format * convert basis_gates from list to set * fix assemble_circuits * resolve conflicts * Replace example in README to using primitives (#2105) * Replace example in README to using primitives * upgrade python version to 3.10 for github actions * fix 3.10 * fix 3.10 * upgrade python version to 3.10 for github actions * skip 3.8 and 3.9 for MacOS arm64 * skip 3.8 and 3.9 for MacOS arm64 * skip 3.8 and 3.9 for MacOS arm64 * replace macos-latest with macos-13 * Revert "Replace example in README to using primitives" This reverts commit b536563. * Revert "Revert "Replace example in README to using primitives"" This reverts commit 807ac6f. * manually merge upstream * add example using noise model * remove print(result) * add release note and set versions * Fix CI failures (#2106) * upgrade github actions for macos_arm64 and windows * skip pp38/39 * exclude pp * fix doc * test * remove CIBW_TEST_SKIP for wheel --------- Co-authored-by: melechlapson <[email protected]> Co-authored-by: Eric Arellano <[email protected]>
1 parent e9c5737 commit b315c4f

30 files changed

+631
-328
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
15+
os: ["macos-13", "ubuntu-latest", "windows-2019"]
1616
steps:
17-
- uses: actions/checkout@v2
18-
- name: Set up Python 3.8
19-
uses: actions/setup-python@v2
17+
- uses: actions/checkout@v4
18+
- name: Set up Python '3.10'
19+
uses: actions/setup-python@v5
2020
with:
21-
python-version: 3.8
21+
python-version: '3.10'
2222
- name: Install deps
2323
run: pip install "conan<2.0.0"
2424
- name: Install openblas
@@ -73,11 +73,11 @@ jobs:
7373
matrix:
7474
os: ["ubuntu-latest"]
7575
steps:
76-
- uses: actions/checkout@v2
77-
- name: Set up Python 3.8
78-
uses: actions/setup-python@v2
76+
- uses: actions/checkout@v4
77+
- name: Set up Python '3.10'
78+
uses: actions/setup-python@v5
7979
with:
80-
python-version: 3.8
80+
python-version: '3.10'
8181
- name: Install deps
8282
run: pip install "conan<2.0.0"
8383
- name: Install openblas and mpi
@@ -121,13 +121,13 @@ jobs:
121121
needs: ["standalone"]
122122
strategy:
123123
matrix:
124-
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
124+
os: ["macos-13", "ubuntu-latest", "windows-2019"]
125125
steps:
126-
- uses: actions/checkout@v2
127-
- name: Set up Python Python 3.8
128-
uses: actions/setup-python@v2
126+
- uses: actions/checkout@v4
127+
- name: Set up Python Python '3.10'
128+
uses: actions/setup-python@v5
129129
with:
130-
python-version: 3.8
130+
python-version: '3.10'
131131
- name: Add msbuild to PATH
132132
uses: microsoft/[email protected]
133133
if: runner.os == 'Windows'
@@ -144,18 +144,20 @@ jobs:
144144
runs-on: ${{ matrix.os }}
145145
strategy:
146146
matrix:
147-
os: ["macOS-latest"]
147+
os: ["macos-latest"]
148148
steps:
149-
- uses: actions/checkout@v2
150-
- name: Set up Python Python 3.8
151-
uses: actions/setup-python@v2
149+
- uses: actions/checkout@v4
150+
- name: Set up Python Python 3.10
151+
uses: actions/setup-python@v5
152152
with:
153-
python-version: 3.8
153+
python-version: '3.10'
154+
architecture: arm64
154155
- name: Install deps
155156
run: python -m pip install -U cibuildwheel==2.16.2
156157
- name: Build Wheels
157158
env:
158159
CIBW_ARCHS_MACOS: arm64
160+
CIBW_SKIP: "pp* cp38* cp39*"
159161
run: cibuildwheel --output-dir wheelhouse
160162
- uses: actions/upload-artifact@v2
161163
with:
@@ -176,7 +178,7 @@ jobs:
176178
- uses: actions/setup-python@v4
177179
name: Install Python
178180
with:
179-
python-version: '3.8'
181+
python-version: '3.10'
180182
- name: Install cibuildwheel
181183
run: |
182184
python -m pip install cibuildwheel==2.16.2
@@ -208,7 +210,7 @@ jobs:
208210
- uses: actions/setup-python@v4
209211
name: Install Python
210212
with:
211-
python-version: '3.8'
213+
python-version: '3.10'
212214
- name: Install cibuildwheel
213215
run: |
214216
python -m pip install cibuildwheel==2.16.2

.github/workflows/deploy.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ jobs:
88
name: Build qiskit-aer wheels
99
strategy:
1010
matrix:
11-
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
11+
os: ["macos-13", "ubuntu-latest", "windows-2019"]
1212
runs-on: ${{ matrix.os }}
1313
environment: release
1414
steps:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-python@v4
1717
name: Install Python
1818
with:
19-
python-version: '3.8'
19+
python-version: '3.10'
2020
- name: Install cibuildwheel
2121
run: |
2222
python -m pip install cibuildwheel==2.16.2
2323
- name: Build wheels
2424
env:
2525
AER_CMAKE_OPENMP_BUILD: 1
26+
CIBW_SKIP: "pp* cp38-macosx_arm64 cp39-macosx_arm64"
2627
run: python -m cibuildwheel --output-dir wheelhouse
2728
- uses: actions/upload-artifact@v3
2829
with:
@@ -43,7 +44,7 @@ jobs:
4344
- uses: actions/setup-python@v4
4445
name: Install Python
4546
with:
46-
python-version: '3.8'
47+
python-version: '3.10'
4748
- uses: actions-rs/toolchain@v1
4849
with:
4950
toolchain: stable
@@ -73,19 +74,21 @@ jobs:
7374
strategy:
7475
fail-fast: false
7576
matrix:
76-
os: ["macOS-latest"]
77+
os: ["macos-latest"]
7778
environment: release
7879
steps:
79-
- uses: actions/checkout@v3
80-
- name: Set up Python Python 3.8
81-
uses: actions/setup-python@v4
80+
- uses: actions/checkout@v4
81+
- name: Set up Python Python '3.10'
82+
uses: actions/setup-python@v5
8283
with:
83-
python-version: 3.8
84+
python-version: '3.10'
85+
architecture: arm64
8486
- name: Install deps
8587
run: python -m pip install -U cibuildwheel==2.16.2
8688
- name: Build Wheels
8789
env:
8890
CIBW_ARCHS_MACOS: arm64
91+
CIBW_SKIP: "pp* cp38* cp39*"
8992
run: cibuildwheel --output-dir wheelhouse
9093
- uses: actions/upload-artifact@v3
9194
with:
@@ -103,7 +106,7 @@ jobs:
103106
- uses: actions/setup-python@v4
104107
name: Install Python
105108
with:
106-
python-version: '3.8'
109+
python-version: '3.10'
107110
- name: Install Deps
108111
run: pip install -U scikit-build wheel
109112
- name: Build Artifacts
@@ -140,7 +143,7 @@ jobs:
140143
- uses: actions/setup-python@v4
141144
name: Install Python
142145
with:
143-
python-version: '3.8'
146+
python-version: '3.10'
144147
- name: Install cibuildwheel
145148
run: |
146149
python -m pip install cibuildwheel==2.16.2
@@ -183,7 +186,7 @@ jobs:
183186
- uses: actions/setup-python@v4
184187
name: Install Python
185188
with:
186-
python-version: '3.8'
189+
python-version: '3.10'
187190
- name: Install cibuildwheel
188191
run: |
189192
python -m pip install cibuildwheel==2.16.2
@@ -218,7 +221,7 @@ jobs:
218221
- uses: actions/setup-python@v4
219222
name: Install Python
220223
with:
221-
python-version: '3.8'
224+
python-version: '3.10'
222225
- uses: actions-rs/toolchain@v1
223226
with:
224227
toolchain: stable
@@ -254,7 +257,7 @@ jobs:
254257
- uses: actions/setup-python@v4
255258
name: Install Python
256259
with:
257-
python-version: '3.8'
260+
python-version: '3.10'
258261
- uses: actions-rs/toolchain@v1
259262
with:
260263
toolchain: stable

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
timeout-minutes: 60
1414
strategy:
1515
matrix:
16-
python-version: [3.8]
16+
python-version: ['3.8']
1717
steps:
1818
- uses: actions/checkout@v2
1919
with:
@@ -50,7 +50,7 @@ jobs:
5050
needs: [docs]
5151
strategy:
5252
matrix:
53-
python-version: [3.8]
53+
python-version: ['3.8']
5454
steps:
5555
- uses: actions/checkout@v2
5656
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: [3.8]
15+
python-version: ['3.10']
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Set up Python ${{ matrix.python-version }}
@@ -147,7 +147,7 @@ jobs:
147147
timeout-minutes: 60
148148
strategy:
149149
matrix:
150-
python-version: [3.9]
150+
python-version: ['3.10']
151151
os: ["ubuntu-latest"]
152152
env:
153153
AER_THRUST_BACKEND: OMP
@@ -192,7 +192,7 @@ jobs:
192192
stestr run --slowest
193193
shell: bash
194194
tests_macos:
195-
runs-on: macOS-latest
195+
runs-on: macos-13
196196
name: macOS Python ${{ matrix.python-version }}
197197
needs: [sdist, lint]
198198
timeout-minutes: 60

README.md

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,101 @@ the [contributing guide](CONTRIBUTING.md#building-with-gpu-support)
4646
for instructions on doing this.
4747

4848
## Simulating your first Qiskit circuit with Aer
49-
Now that you have Aer installed, you can start simulating quantum circuits with noise. Here is a basic example:
49+
Now that you have Aer installed, you can start simulating quantum circuits using primitives and noise models. Here is a basic example:
5050

5151
```
5252
$ python
5353
```
5454

5555
```python
56-
import qiskit
56+
from qiskit import transpile
57+
from qiskit.circuit.library import RealAmplitudes
58+
from qiskit.quantum_info import SparsePauliOp
5759
from qiskit_aer import AerSimulator
58-
from qiskit_ibm_runtime import QiskitRuntimeService
5960

60-
# Generate 3-qubit GHZ state
61-
circ = qiskit.QuantumCircuit(3)
62-
circ.h(0)
63-
circ.cx(0, 1)
64-
circ.cx(1, 2)
65-
circ.measure_all()
66-
67-
# Construct an ideal simulator
68-
aersim = AerSimulator()
69-
70-
# Perform an ideal simulation
71-
result_ideal = aersim.run(circ).result()
72-
counts_ideal = result_ideal.get_counts(0)
73-
print('Counts(ideal):', counts_ideal)
74-
# Counts(ideal): {'000': 493, '111': 531}
75-
76-
# Construct a simulator using a noise model
77-
# from a real backend.
78-
provider = QiskitRuntimeService()
61+
sim = AerSimulator()
62+
# --------------------------
63+
# Simulating using estimator
64+
#---------------------------
65+
from qiskit_aer.primitives import EstimatorV2
66+
67+
psi1 = transpile(RealAmplitudes(num_qubits=2, reps=2), sim, optimization_level=0)
68+
psi2 = transpile(RealAmplitudes(num_qubits=2, reps=3), sim, optimization_level=0)
69+
70+
H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)])
71+
H2 = SparsePauliOp.from_list([("IZ", 1)])
72+
H3 = SparsePauliOp.from_list([("ZI", 1), ("ZZ", 1)])
73+
74+
theta1 = [0, 1, 1, 2, 3, 5]
75+
theta2 = [0, 1, 1, 2, 3, 5, 8, 13]
76+
theta3 = [1, 2, 3, 4, 5, 6]
77+
78+
estimator = EstimatorV2()
79+
80+
# calculate [ [<psi1(theta1)|H1|psi1(theta1)>,
81+
# <psi1(theta3)|H3|psi1(theta3)>],
82+
# [<psi2(theta2)|H2|psi2(theta2)>] ]
83+
job = estimator.run(
84+
[
85+
(psi1, [H1, H3], [theta1, theta3]),
86+
(psi2, H2, theta2)
87+
],
88+
precision=0.01
89+
)
90+
result = job.result()
91+
print(f"expectation values : psi1 = {result[0].data.evs}, psi2 = {result[1].data.evs}")
92+
93+
# --------------------------
94+
# Simulating using sampler
95+
# --------------------------
96+
from qiskit_aer.primitives import SamplerV2
97+
from qiskit import QuantumCircuit
98+
99+
# create a Bell circuit
100+
bell = QuantumCircuit(2)
101+
bell.h(0)
102+
bell.cx(0, 1)
103+
bell.measure_all()
104+
105+
# create two parameterized circuits
106+
pqc = RealAmplitudes(num_qubits=2, reps=2)
107+
pqc.measure_all()
108+
pqc = transpile(pqc, sim, optimization_level=0)
109+
pqc2 = RealAmplitudes(num_qubits=2, reps=3)
110+
pqc2.measure_all()
111+
pqc2 = transpile(pqc2, sim, optimization_level=0)
112+
113+
theta1 = [0, 1, 1, 2, 3, 5]
114+
theta2 = [0, 1, 2, 3, 4, 5, 6, 7]
115+
116+
# initialization of the sampler
117+
sampler = SamplerV2()
118+
119+
# collect 128 shots from the Bell circuit
120+
job = sampler.run([bell], shots=128)
121+
job_result = job.result()
122+
print(f"counts for Bell circuit : {job_result[0].data.meas.get_counts()}")
123+
124+
# run a sampler job on the parameterized circuits
125+
job2 = sampler.run([(pqc, theta1), (pqc2, theta2)])
126+
job_result = job2.result()
127+
print(f"counts for parameterized circuit : {job_result[0].data.meas.get_counts()}")
128+
129+
# --------------------------------------------------
130+
# Simulating with noise model from actual hardware
131+
# --------------------------------------------------
132+
from qiskit_ibm_runtime import QiskitRuntimeService
133+
provider = QiskitRuntimeService(channel='ibm_quantum', token="set your own token here")
79134
backend = provider.get_backend("ibm_kyoto")
80-
aersim_backend = AerSimulator.from_backend(backend)
81135

82-
# Perform noisy simulation
83-
result_noise = aersim_backend.run(circ).result()
84-
counts_noise = result_noise.get_counts(0)
136+
# create sampler from the actual backend
137+
sampler.from_backend(backend)
138+
139+
# run a sampler job on the parameterized circuits with noise model of the actual hardware
140+
job3 = sampler.run([(pqc, theta1), (pqc2, theta2)])
141+
job_result = job3.result()
142+
print(f"Parameterized for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}")
85143

86-
print('Counts(noise):', counts_noise)
87-
# Counts(noise): {'101': 16, '110': 48, '100': 7, '001': 31, '010': 7, '000': 464, '011': 15, '111': 436}
88144
```
89145

90146
## Contribution Guidelines

0 commit comments

Comments
 (0)