Skip to content

Commit

Permalink
Release 0.14.1 (#2099)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent e9c5737 commit b315c4f
Show file tree
Hide file tree
Showing 30 changed files with 631 additions and 328 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
os: ["macos-13", "ubuntu-latest", "windows-2019"]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python '3.10'
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
- name: Install deps
run: pip install "conan<2.0.0"
- name: Install openblas
Expand Down Expand Up @@ -73,11 +73,11 @@ jobs:
matrix:
os: ["ubuntu-latest"]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python '3.10'
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
- name: Install deps
run: pip install "conan<2.0.0"
- name: Install openblas and mpi
Expand Down Expand Up @@ -121,13 +121,13 @@ jobs:
needs: ["standalone"]
strategy:
matrix:
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
os: ["macos-13", "ubuntu-latest", "windows-2019"]
steps:
- uses: actions/checkout@v2
- name: Set up Python Python 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python Python '3.10'
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: runner.os == 'Windows'
Expand All @@ -144,18 +144,20 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macOS-latest"]
os: ["macos-latest"]
steps:
- uses: actions/checkout@v2
- name: Set up Python Python 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
architecture: arm64
- name: Install deps
run: python -m pip install -U cibuildwheel==2.16.2
- name: Build Wheels
env:
CIBW_ARCHS_MACOS: arm64
CIBW_SKIP: "pp* cp38* cp39*"
run: cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v2
with:
Expand All @@ -176,7 +178,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.16.2
Expand Down Expand Up @@ -208,7 +210,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.16.2
Expand Down
29 changes: 16 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ jobs:
name: Build qiskit-aer wheels
strategy:
matrix:
os: ["macOS-latest", "ubuntu-latest", "windows-2019"]
os: ["macos-13", "ubuntu-latest", "windows-2019"]
runs-on: ${{ matrix.os }}
environment: release
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.16.2
- name: Build wheels
env:
AER_CMAKE_OPENMP_BUILD: 1
CIBW_SKIP: "pp* cp38-macosx_arm64 cp39-macosx_arm64"
run: python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v3
with:
Expand All @@ -43,7 +44,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down Expand Up @@ -73,19 +74,21 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["macOS-latest"]
os: ["macos-latest"]
environment: release
steps:
- uses: actions/checkout@v3
- name: Set up Python Python 3.8
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python Python '3.10'
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
architecture: arm64
- name: Install deps
run: python -m pip install -U cibuildwheel==2.16.2
- name: Build Wheels
env:
CIBW_ARCHS_MACOS: arm64
CIBW_SKIP: "pp* cp38* cp39*"
run: cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v3
with:
Expand All @@ -103,7 +106,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install Deps
run: pip install -U scikit-build wheel
- name: Build Artifacts
Expand Down Expand Up @@ -140,7 +143,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.16.2
Expand Down Expand Up @@ -183,7 +186,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.16.2
Expand Down Expand Up @@ -218,7 +221,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down Expand Up @@ -254,7 +257,7 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.8'
python-version: '3.10'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: [3.8]
python-version: ['3.8']
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
needs: [docs]
strategy:
matrix:
python-version: [3.8]
python-version: ['3.8']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: ['3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: [3.9]
python-version: ['3.10']
os: ["ubuntu-latest"]
env:
AER_THRUST_BACKEND: OMP
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
stestr run --slowest
shell: bash
tests_macos:
runs-on: macOS-latest
runs-on: macos-13
name: macOS Python ${{ matrix.python-version }}
needs: [sdist, lint]
timeout-minutes: 60
Expand Down
112 changes: 84 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,101 @@ the [contributing guide](CONTRIBUTING.md#building-with-gpu-support)
for instructions on doing this.

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

```
$ python
```

```python
import qiskit
from qiskit import transpile
from qiskit.circuit.library import RealAmplitudes
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import QiskitRuntimeService

# Generate 3-qubit GHZ state
circ = qiskit.QuantumCircuit(3)
circ.h(0)
circ.cx(0, 1)
circ.cx(1, 2)
circ.measure_all()

# Construct an ideal simulator
aersim = AerSimulator()

# Perform an ideal simulation
result_ideal = aersim.run(circ).result()
counts_ideal = result_ideal.get_counts(0)
print('Counts(ideal):', counts_ideal)
# Counts(ideal): {'000': 493, '111': 531}

# Construct a simulator using a noise model
# from a real backend.
provider = QiskitRuntimeService()
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")
aersim_backend = AerSimulator.from_backend(backend)

# Perform noisy simulation
result_noise = aersim_backend.run(circ).result()
counts_noise = result_noise.get_counts(0)
# 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()}")

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

## Contribution Guidelines
Expand Down
Loading

0 comments on commit b315c4f

Please sign in to comment.