aer-metal 0.2.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aer_metal-0.2.0a1/.gitignore +12 -0
- aer_metal-0.2.0a1/CHANGELOG.md +67 -0
- aer_metal-0.2.0a1/CMakeLists.txt +32 -0
- aer_metal-0.2.0a1/LICENSE +203 -0
- aer_metal-0.2.0a1/NOTICE +16 -0
- aer_metal-0.2.0a1/PKG-INFO +264 -0
- aer_metal-0.2.0a1/README.md +229 -0
- aer_metal-0.2.0a1/cmake/embed.cmake +2 -0
- aer_metal-0.2.0a1/docs/NOISE_DESIGN.md +182 -0
- aer_metal-0.2.0a1/docs/RELEASE.md +85 -0
- aer_metal-0.2.0a1/docs/REPORT.md +394 -0
- aer_metal-0.2.0a1/docs/USAGE.md +138 -0
- aer_metal-0.2.0a1/docs/bench_wall.png +0 -0
- aer_metal-0.2.0a1/pyproject.toml +63 -0
- aer_metal-0.2.0a1/python/aer_metal/__init__.py +21 -0
- aer_metal-0.2.0a1/python/aer_metal/backend.py +468 -0
- aer_metal-0.2.0a1/python/aer_metal/batched.py +433 -0
- aer_metal-0.2.0a1/python/aer_metal/blocking.py +260 -0
- aer_metal-0.2.0a1/python/aer_metal/circuit.py +199 -0
- aer_metal-0.2.0a1/python/aer_metal/classical.py +193 -0
- aer_metal-0.2.0a1/python/aer_metal/densitymatrix.py +267 -0
- aer_metal-0.2.0a1/python/aer_metal/executor.py +729 -0
- aer_metal-0.2.0a1/python/aer_metal/fusion.py +337 -0
- aer_metal-0.2.0a1/python/aer_metal/lowering.py +262 -0
- aer_metal-0.2.0a1/python/aer_metal/memory.py +60 -0
- aer_metal-0.2.0a1/python/aer_metal/noise.py +310 -0
- aer_metal-0.2.0a1/python/aer_metal/ops.py +163 -0
- aer_metal-0.2.0a1/python/aer_metal/statevector.py +184 -0
- aer_metal-0.2.0a1/src/aer_metal/binding.mm +185 -0
- aer_metal-0.2.0a1/src/aer_metal/kernels.metal +769 -0
- aer_metal-0.2.0a1/src/aer_metal/metal_state.h +141 -0
- aer_metal-0.2.0a1/src/aer_metal/metal_state.mm +980 -0
- aer_metal-0.2.0a1/tests/conftest.py +4 -0
- aer_metal-0.2.0a1/tests/reference.py +57 -0
- aer_metal-0.2.0a1/tests/test_backend.py +471 -0
- aer_metal-0.2.0a1/tests/test_batched.py +203 -0
- aer_metal-0.2.0a1/tests/test_batched_kernels.py +181 -0
- aer_metal-0.2.0a1/tests/test_big.py +48 -0
- aer_metal-0.2.0a1/tests/test_blocking.py +217 -0
- aer_metal-0.2.0a1/tests/test_circuits.py +96 -0
- aer_metal-0.2.0a1/tests/test_core.py +180 -0
- aer_metal-0.2.0a1/tests/test_density_matrix.py +425 -0
- aer_metal-0.2.0a1/tests/test_fusion.py +166 -0
- aer_metal-0.2.0a1/tests/test_hhl.py +198 -0
- aer_metal-0.2.0a1/tests/test_m2_core.py +55 -0
- aer_metal-0.2.0a1/tests/test_memory.py +152 -0
- aer_metal-0.2.0a1/tests/test_noise.py +385 -0
- aer_metal-0.2.0a1/tests/test_sampling.py +58 -0
- aer_metal-0.2.0a1/tools/big_check.py +215 -0
- aer_metal-0.2.0a1/tools/build.sh +9 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0a1 — noise
|
|
4
|
+
|
|
5
|
+
Noise simulation, ported from Qiskit Aer's noise stack. Same platform and precision as
|
|
6
|
+
0.1 (Apple Silicon, complex64 on the GPU).
|
|
7
|
+
|
|
8
|
+
- `MetalSimulator(noise_model=...)` takes a `qiskit_aer.noise.NoiseModel` as it is:
|
|
9
|
+
all-qubit and qubit-specific quantum errors on any gate name or label, on `measure` and
|
|
10
|
+
on `reset`; readout errors on one or several qubits; `NoiseModel.from_backend(...)`
|
|
11
|
+
including relaxation on `delay`. Errors are inserted where Aer inserts them.
|
|
12
|
+
- Quantum errors made of unitary circuits, Pauli, reset and Kraus terms, and all of
|
|
13
|
+
`qiskit_aer.noise`'s standard errors, plus `PauliError` and `PauliLindbladError`.
|
|
14
|
+
`QuantumError.to_instruction()`, `kraus` and `superop` instructions work in circuits,
|
|
15
|
+
with or without a noise model.
|
|
16
|
+
- Statevector trajectories, as in Aer: unitary-mixture errors are sampled as gates, and
|
|
17
|
+
Kraus errors use Aer's norm-based sampling (probabilities from a GPU reduced density
|
|
18
|
+
matrix). Shot branching splits the shots between sampled outcomes. Readout errors are
|
|
19
|
+
applied to the sampled bits.
|
|
20
|
+
- Batched GPU trajectories, after Aer's batched-shots executor: up to
|
|
21
|
+
`batched_shots_gpu_max_qubits` (default 16) qubits, many trajectories of one circuit sit
|
|
22
|
+
in one buffer and each operation is a single dispatch over all of them. Options
|
|
23
|
+
`batched_shots_gpu` (default on), `batched_shots_gpu_max_qubits`,
|
|
24
|
+
`batched_shots_gpu_max_batch` (default: chosen from the shot count and a 512 MiB budget).
|
|
25
|
+
Batched circuits may contain mid-circuit measurement, reset, `initialize` and
|
|
26
|
+
`state_preparation`; control flow runs with shot branching instead.
|
|
27
|
+
Result metadata reports `batched_shots`, `batch_size` and `batch_rounds`. Counts do not
|
|
28
|
+
depend on the batch size, but they are not bit-identical to Aer's for the same seed.
|
|
29
|
+
- `method="density_matrix"`: the density matrix as a 2n-qubit vector on the GPU, gates as
|
|
30
|
+
superoperators or as U and conj(U), noise as superoperators, superoperator fusion.
|
|
31
|
+
Up to half the statevector limit: 16 qubits on a 128 GB machine.
|
|
32
|
+
- `method="automatic"` is now the default, as in Aer. It follows Aer's rule: the density
|
|
33
|
+
matrix when the circuit has quantum errors, fewer than 30 qubits, more shots than 2^n,
|
|
34
|
+
and nothing a density matrix cannot run; otherwise the statevector.
|
|
35
|
+
- `fusion_threshold` and `fusion_max_qubit` default to `None`, meaning a value per method
|
|
36
|
+
(statevector: threshold 14, max 2 with blocking or 5 without; density matrix:
|
|
37
|
+
threshold 7, max 2).
|
|
38
|
+
- In batched trajectories, a reset (including the reset terms of relaxation errors) draws
|
|
39
|
+
its outcome on the GPU, with no round trip to the host. With thermal-relaxation noise on
|
|
40
|
+
every gate this made batched runs 1.8–37x faster at 6–16 qubits. The outcome
|
|
41
|
+
probabilities are float32 GPU sums.
|
|
42
|
+
- Fixed: a circuit with more than 64 live branch states (shot branching) hung in 0.1.
|
|
43
|
+
|
|
44
|
+
Not yet supported: non-local quantum errors, errors on more than 5 qubits with the
|
|
45
|
+
density matrix, `precision="double"`, legacy `c_if`. These raise `NotImplementedError`.
|
|
46
|
+
|
|
47
|
+
## 0.1.0a1 — first alpha
|
|
48
|
+
|
|
49
|
+
First public alpha release. Apple Silicon (arm64 macOS) only. The GPU state is complex64
|
|
50
|
+
only.
|
|
51
|
+
|
|
52
|
+
- Metal port of the Qiskit Aer GPU statevector kernels: dense 1–5-qubit matrices (up to
|
|
53
|
+
10 qubits through a cached-matrix kernel), diagonals, multi-controlled
|
|
54
|
+
X/Y/Z/phase/U/swap, permutations, initialize, norm/probability reductions, Pauli
|
|
55
|
+
expectation values, measurement collapse and reset, and sampling.
|
|
56
|
+
- `MetalSimulator`, a Qiskit `BackendV2`: shots, counts, memory, seeds, parameter binds,
|
|
57
|
+
Aer save instructions, mid-circuit measurement and reset, and control flow (`if_else`,
|
|
58
|
+
`while_loop`, `for_loop`, `switch`, `box`, `store`) with Aer-style shot branching.
|
|
59
|
+
- A port of Aer's gate fusion (NQubitFusion and CostBasedFusion).
|
|
60
|
+
- Threadgroup-memory blocking: runs of gates on 12 local qubits are applied in one pass
|
|
61
|
+
over the state, and runs of diagonal phase gates are summed into a single phase.
|
|
62
|
+
- Large states: up to 33 qubits in a single buffer on a 128 GB machine, with memory
|
|
63
|
+
guards and zero-copy access to the state (`metal_state_array`,
|
|
64
|
+
`MetalStateVector.to_numpy(copy=False)`).
|
|
65
|
+
- `metal_statevector(qc)` returns a `qiskit.quantum_info.Statevector`.
|
|
66
|
+
|
|
67
|
+
Not yet supported: noise models, double precision, legacy `c_if`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
project(aer_metal LANGUAGES C CXX OBJCXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_OBJCXX_STANDARD 17)
|
|
7
|
+
|
|
8
|
+
find_package(Python 3.11 REQUIRED COMPONENTS Interpreter Development.Module
|
|
9
|
+
OPTIONAL_COMPONENTS ${SKBUILD_SABI_COMPONENT})
|
|
10
|
+
execute_process(
|
|
11
|
+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
12
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
|
|
13
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
14
|
+
|
|
15
|
+
# Embed the Metal kernel source as a C++ raw string (compiled at runtime by
|
|
16
|
+
# newLibraryWithSource: because the offline Metal toolchain is not installed).
|
|
17
|
+
set(KERNEL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/aer_metal/kernels.metal)
|
|
18
|
+
set(KERNEL_HDR ${CMAKE_CURRENT_BINARY_DIR}/generated/kernels_src.h)
|
|
19
|
+
add_custom_command(
|
|
20
|
+
OUTPUT ${KERNEL_HDR}
|
|
21
|
+
COMMAND ${CMAKE_COMMAND} -DIN=${KERNEL_SRC} -DOUT=${KERNEL_HDR}
|
|
22
|
+
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed.cmake
|
|
23
|
+
DEPENDS ${KERNEL_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed.cmake)
|
|
24
|
+
|
|
25
|
+
nanobind_add_module(_core NB_STATIC STABLE_ABI
|
|
26
|
+
src/aer_metal/binding.mm
|
|
27
|
+
src/aer_metal/metal_state.mm
|
|
28
|
+
${KERNEL_HDR})
|
|
29
|
+
target_include_directories(_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated src/aer_metal)
|
|
30
|
+
target_compile_options(_core PRIVATE -fobjc-arc -O2)
|
|
31
|
+
target_link_libraries(_core PRIVATE "-framework Metal" "-framework Foundation")
|
|
32
|
+
install(TARGETS _core LIBRARY DESTINATION aer_metal)
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright 2018 IBM and its contributors
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright 2018 IBM and its contributors.
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
aer_metal-0.2.0a1/NOTICE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
aer-metal
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
This project contains code ported from Qiskit Aer
|
|
5
|
+
(https://github.com/Qiskit/qiskit-aer, commit cb25c05),
|
|
6
|
+
Copyright IBM 2018-2024, licensed under the Apache License, Version 2.0.
|
|
7
|
+
|
|
8
|
+
Ported and modified files carry a notice saying so. In particular the GPU
|
|
9
|
+
kernels in src/aer_metal/kernels.metal are rewritten from
|
|
10
|
+
src/simulators/statevector/chunk/thrust_kernels.hpp, and the host dispatch in
|
|
11
|
+
src/aer_metal/metal_state.mm follows
|
|
12
|
+
src/simulators/statevector/qubitvector_thrust.hpp. Modifications: Metal
|
|
13
|
+
Shading Language / Objective-C++ instead of CUDA/Thrust, complex64 state
|
|
14
|
+
(Apple GPUs have no FP64), single GPU only.
|
|
15
|
+
|
|
16
|
+
The full Apache-2.0 license text is in LICENSE.
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aer-metal
|
|
3
|
+
Version: 0.2.0a1
|
|
4
|
+
Summary: Qiskit Aer's statevector simulator ported to Apple Metal (Apple Silicon GPU, complex64)
|
|
5
|
+
Keywords: quantum,qiskit,simulator,statevector,metal,gpu,apple-silicon
|
|
6
|
+
Author: Alexis Kirke
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: NOTICE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
13
|
+
Classifier: Environment :: GPU
|
|
14
|
+
Classifier: Programming Language :: C++
|
|
15
|
+
Classifier: Programming Language :: Objective C
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
23
|
+
Project-URL: Homepage, https://github.com/alexiskirke/aer-metal
|
|
24
|
+
Project-URL: Source, https://github.com/alexiskirke/aer-metal
|
|
25
|
+
Project-URL: Issues, https://github.com/alexiskirke/aer-metal/issues
|
|
26
|
+
Project-URL: Changelog, https://github.com/alexiskirke/aer-metal/blob/main/CHANGELOG.md
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Requires-Dist: numpy>=1.24
|
|
29
|
+
Requires-Dist: qiskit>=2.0
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
32
|
+
Requires-Dist: qiskit-aer>=0.15; extra == "test"
|
|
33
|
+
Requires-Dist: scipy; extra == "test"
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# aer-metal
|
|
37
|
+
|
|
38
|
+
A GPU quantum circuit simulator for Apple Silicon. It ports the GPU statevector path of
|
|
39
|
+
[Qiskit Aer](https://github.com/Qiskit/qiskit-aer) from CUDA/Thrust to Apple Metal, together
|
|
40
|
+
with Aer's noise simulation (trajectories and density matrix), and provides it as a Qiskit
|
|
41
|
+
`BackendV2`. Existing Qiskit code can switch to it by changing one line.
|
|
42
|
+
|
|
43
|
+
> **This is not an official Qiskit project.** It is an independent port and is not
|
|
44
|
+
> affiliated with or endorsed by IBM or the Qiskit project.
|
|
45
|
+
|
|
46
|
+
**Requirements:** macOS on Apple Silicon (arm64) and CPython 3.11–3.13. Intel Macs, Linux
|
|
47
|
+
and Windows are not supported.
|
|
48
|
+
|
|
49
|
+
## Precision: float32 only
|
|
50
|
+
|
|
51
|
+
Apple GPUs have no FP64. The state is stored as **complex64** (two float32 values per
|
|
52
|
+
amplitude), whereas Aer's default is complex128. Against Aer in double precision you can
|
|
53
|
+
expect:
|
|
54
|
+
|
|
55
|
+
- amplitude errors of about 1e-7 to 1e-6 (about 1e-6 relative at 30–33 qubits),
|
|
56
|
+
- state fidelity of about 1 − 1e-6,
|
|
57
|
+
- sampled counts that agree with Aer within shot noise.
|
|
58
|
+
|
|
59
|
+
If your work depends on amplitudes being accurate below about 1e-6, use Aer on the CPU.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
From [PyPI](https://pypi.org/project/aer-metal/) (macOS arm64 wheels for CPython 3.11–3.13;
|
|
64
|
+
it is an alpha, hence `--pre`):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install --pre aer-metal
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Wheels are also attached to each
|
|
71
|
+
[GitHub release](https://github.com/alexiskirke/aer-metal/releases), or you can build from source. To build from source (needs Xcode or the Command Line Tools; the Metal kernels are
|
|
72
|
+
compiled at runtime, so the offline Metal compiler is not required):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/alexiskirke/aer-metal && cd aer-metal
|
|
76
|
+
python -m venv .venv && .venv/bin/pip install ".[test]"
|
|
77
|
+
.venv/bin/python -m pytest -q tests
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Make sure the Python itself is arm64 (`python -c "import platform; print(platform.machine())"`
|
|
81
|
+
must print `arm64`). An x86_64 Python running under Rosetta cannot load the module.
|
|
82
|
+
|
|
83
|
+
## One-line swap from AerSimulator
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from qiskit import QuantumCircuit, transpile
|
|
87
|
+
from aer_metal import MetalSimulator # instead of: from qiskit_aer import AerSimulator
|
|
88
|
+
|
|
89
|
+
qc = QuantumCircuit(3)
|
|
90
|
+
qc.h(0); qc.cx(0, 1); qc.cx(1, 2)
|
|
91
|
+
qc.measure_all()
|
|
92
|
+
|
|
93
|
+
backend = MetalSimulator() # instead of: AerSimulator()
|
|
94
|
+
counts = backend.run(transpile(qc, backend), shots=4096, seed_simulator=1).result().get_counts()
|
|
95
|
+
print(counts) # {'000': ~2048, '111': ~2048}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
You only need the statevector?
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from aer_metal import metal_statevector
|
|
102
|
+
sv = metal_statevector(qc.remove_final_measurements(inplace=False)) # qiskit.quantum_info.Statevector
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
It also works with the Qiskit primitives:
|
|
106
|
+
`BackendSamplerV2(backend=MetalSimulator())`, `BackendEstimatorV2(backend=MetalSimulator())`.
|
|
107
|
+
|
|
108
|
+
## What is supported
|
|
109
|
+
|
|
110
|
+
- Every gate that has a matrix (up to 10 qubits) or a definition. Native support for:
|
|
111
|
+
all standard gates, `unitary`, `diagonal`, `mcx`/`mcphase` and other controlled gates
|
|
112
|
+
(including `ctrl_state`), `initialize` and `state_preparation`. The last two load the
|
|
113
|
+
vector directly, without synthesising gates.
|
|
114
|
+
- `shots`, `counts`, `memory=True`, `seed_simulator`, `parameter_binds`.
|
|
115
|
+
- Mid-circuit `measure`, `reset`, `if_test`/`if_else`, `while_loop`, `for_loop`, `switch`,
|
|
116
|
+
`box`, classical `Var`s and `store`. These run per shot, with shot branching as in Aer.
|
|
117
|
+
Circuits that only measure at the end are simulated once and then sampled.
|
|
118
|
+
- Aer's save instructions (run `import qiskit_aer` first so the `QuantumCircuit.save_*`
|
|
119
|
+
methods exist): `save_statevector`, `save_state`, `save_statevector_dict`,
|
|
120
|
+
`save_probabilities(_dict)`, `save_amplitudes(_squared)`,
|
|
121
|
+
`save_expectation_value(_variance)`, `save_density_matrix`.
|
|
122
|
+
- Gate fusion ported from Aer (`fusion_enable`, `fusion_threshold`, `fusion_max_qubit`,
|
|
123
|
+
`fusion_cost_factor`).
|
|
124
|
+
- Threadgroup-memory blocking (`blocking_enable=True` by default, `blocking_qubits=12`).
|
|
125
|
+
Consecutive gates that act on the same 12 "local" qubits are applied in one pass over
|
|
126
|
+
the state.
|
|
127
|
+
- Large states: one GPU buffer holds up to `device.maxBufferLength`. On a 128 GB machine
|
|
128
|
+
that is 33 qubits (64 GiB).
|
|
129
|
+
|
|
130
|
+
**Not supported:** methods other than `automatic`, `statevector` and `density_matrix`,
|
|
131
|
+
`precision="double"`, and the legacy `c_if`. Aer tuning options this backend does not
|
|
132
|
+
know are ignored.
|
|
133
|
+
|
|
134
|
+
## Noise
|
|
135
|
+
|
|
136
|
+
Pass a `qiskit_aer.noise.NoiseModel` as you would to `AerSimulator`:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from qiskit_aer.noise import NoiseModel, depolarizing_error, ReadoutError
|
|
140
|
+
from aer_metal import MetalSimulator
|
|
141
|
+
|
|
142
|
+
nm = NoiseModel()
|
|
143
|
+
nm.add_all_qubit_quantum_error(depolarizing_error(1e-3, 1), ["rz", "sx", "x"])
|
|
144
|
+
nm.add_all_qubit_quantum_error(depolarizing_error(1e-2, 2), ["cx"])
|
|
145
|
+
nm.add_all_qubit_readout_error(ReadoutError([[0.98, 0.02], [0.02, 0.98]]))
|
|
146
|
+
|
|
147
|
+
backend = MetalSimulator(noise_model=nm) # instead of: AerSimulator(noise_model=nm)
|
|
148
|
+
counts = backend.run(transpile(qc, backend), shots=10000).result().get_counts()
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The noise algorithms are ported from Aer, so results match `AerSimulator` with the same
|
|
152
|
+
noise model within shot noise. They are not bit-identical for the same seed: the random
|
|
153
|
+
numbers are drawn in a different order. With batched trajectories, counts do not depend on
|
|
154
|
+
the batch size.
|
|
155
|
+
|
|
156
|
+
- `method="automatic"` is the default, as in Aer (in 0.1 it was `statevector`). It picks
|
|
157
|
+
the density matrix when the circuit has quantum errors, fewer than 30 qubits and more
|
|
158
|
+
shots than 2^n; otherwise trajectories. Result metadata says which ran: `method`, and
|
|
159
|
+
`noise` (`ideal`, `readout`, `kraus` or `circuit` for trajectories, `superop` for the
|
|
160
|
+
density matrix).
|
|
161
|
+
- Trajectory options: `batched_shots_gpu` (default `True`), `batched_shots_gpu_max_qubits`
|
|
162
|
+
(16), `batched_shots_gpu_max_batch` (default: chosen from the shot count and a 512 MiB
|
|
163
|
+
budget). Metadata reports `batched_shots`, `batch_size` and `batch_rounds`.
|
|
164
|
+
- `fusion_threshold` and `fusion_max_qubit` default to `None`, meaning a value per method
|
|
165
|
+
(statevector 14 and 2 with blocking / 5 without; density matrix 7 and 2).
|
|
166
|
+
- `method="density_matrix"` also runs `initialize`, which Aer's density matrix rejects.
|
|
167
|
+
|
|
168
|
+
| Feature | Supported |
|
|
169
|
+
|---|---|
|
|
170
|
+
| All-qubit and qubit-specific quantum errors, on gates (by name or label), `measure`, `reset` | yes |
|
|
171
|
+
| Readout errors on one or several qubits | yes |
|
|
172
|
+
| `depolarizing_error`, `pauli_error`, `PauliError`, `PauliLindbladError`, amplitude/phase damping, `thermal_relaxation_error`, `reset_error`, coherent/mixed unitary errors, `kraus_error` | yes |
|
|
173
|
+
| `NoiseModel.from_backend(...)`, including relaxation on `delay` | yes |
|
|
174
|
+
| `QuantumError` instructions, `kraus` and `superop` instructions in circuits | yes |
|
|
175
|
+
| Noise inside `if_test`, loops, `switch` | yes |
|
|
176
|
+
| `method="statevector"`: trajectories (shot branching; batched on the GPU up to 16 qubits) | yes |
|
|
177
|
+
| `method="density_matrix"` (up to 16 qubits on a 128 GB machine) | yes |
|
|
178
|
+
| `method="automatic"` (the default): Aer's rule for choosing between the two | yes |
|
|
179
|
+
| Non-local errors, errors on more than 5 qubits with the density matrix | no (`NotImplementedError`) |
|
|
180
|
+
|
|
181
|
+
How each piece maps to Aer's code is in [docs/NOISE_DESIGN.md](https://github.com/alexiskirke/aer-metal/blob/main/docs/NOISE_DESIGN.md).
|
|
182
|
+
|
|
183
|
+
### Noise performance
|
|
184
|
+
|
|
185
|
+
Same machine and conditions as the noiseless table below (AC power, GPU idle, Aer from a cool
|
|
186
|
+
CPU on all cores, double precision). Three circuit families (layered rotations + cx,
|
|
187
|
+
Quantum Volume depth 5, QFT). Light noise: depolarizing 1e-3 / 1e-2 + 2 % readout. Heavy
|
|
188
|
+
noise: thermal relaxation (T1 50 us, T2 30 us) + 2 % readout. Both simulators use Aer's
|
|
189
|
+
automatic rule: density matrix when shots > 2^n, else trajectories.
|
|
190
|
+
|
|
191
|
+
Speed-up of aer-metal over Aer, both on the automatic method (Aer time / aer-metal time; > 1 = aer-metal faster), lowest to highest over the three circuit families. Empty: not measured, because one of the runs was predicted to take over 120 s.
|
|
192
|
+
|
|
193
|
+
| qubits | light, 1000 shots | light, 10000 shots | heavy, 1000 shots | heavy, 10000 shots |
|
|
194
|
+
|---|---|---|---|---|
|
|
195
|
+
| 6 | 0.7-1.5x | 0.8-1.4x | 0.6-1.4x | 0.9-1.5x |
|
|
196
|
+
| 8 | 0.5-0.8x | 1.0-1.4x | 0.7-1.0x | 1.0-1.1x |
|
|
197
|
+
| 10 | 2.3-3.5x | 2.7-6.4x | 2.1-2.6x | 2.9-5.9x |
|
|
198
|
+
| 12 | 2.6-3.2x | 27.3-84.9x | 1.7-2.3x | 30.2-94.2x |
|
|
199
|
+
| 14 | 4.0-6.1x | 6.2-7.5x | 2.6-3.5x | 4.3-5.3x |
|
|
200
|
+
| 16 | 1.2-4.0x | 2.2-9.7x | 2.6-4.4x | 4.5x |
|
|
201
|
+
| 18 | 2.4-7.9x | | 1.6-4.1x | |
|
|
202
|
+
| 20 | 5.7-10.5x | | | |
|
|
203
|
+
|
|
204
|
+
Up to 8 qubits both take milliseconds and neither wins. From 10 qubits aer-metal was
|
|
205
|
+
faster in every cell measured; the largest factors are the GPU density matrix at 12 qubits.
|
|
206
|
+
At 10–14 qubits `method="density_matrix"` is often faster than the automatic choice even
|
|
207
|
+
when there are fewer shots than 2^n. All rows are in `bench/RESULTS_n5.md`.
|
|
208
|
+
|
|
209
|
+
There is more in [docs/USAGE.md](https://github.com/alexiskirke/aer-metal/blob/main/docs/USAGE.md).
|
|
210
|
+
|
|
211
|
+
## Performance
|
|
212
|
+
|
|
213
|
+
Measured on an Apple M5 Max (40-core GPU, 18 CPU cores, 128 GB), on AC power. The table
|
|
214
|
+
shows wall time for `backend.run(qc, shots=1).result()`, which includes Python-side
|
|
215
|
+
lowering, fusion and blocking. Aer ran `AerSimulator(method="statevector")` on all CPU
|
|
216
|
+
cores with default fusion, from a **cold CPU**: the machine sat idle for 45 s before each
|
|
217
|
+
Aer run. Both were measured in the same session.
|
|
218
|
+
|
|
219
|
+
| circuit | qubits | aer-metal | Aer double | Aer single | speedup vs double |
|
|
220
|
+
|---|---|---|---|---|---|
|
|
221
|
+
| QFT | 16 | 3.6 ms | 9.8 ms | 6.2 ms | 2.7x |
|
|
222
|
+
| QFT | 20 | 8.1 ms | 29.5 ms | 33.3 ms | 3.6x |
|
|
223
|
+
| QFT | 24 | 21.4 ms | 0.43 s | 0.40 s | 20x |
|
|
224
|
+
| QFT | 26 | 74.6 ms | 2.12 s | 2.02 s | 28x |
|
|
225
|
+
| Quantum Volume | 16 | 14.8 ms | 17.7 ms | 18.2 ms | 1.2x |
|
|
226
|
+
| Quantum Volume | 20 | 22.5 ms | 75.0 ms | 62.9 ms | 3.3x |
|
|
227
|
+
| Quantum Volume | 24 | 68.4 ms | 1.27 s | 0.97 s | 19x |
|
|
228
|
+
| Quantum Volume | 26 | 0.21 s | 6.09 s | 5.85 s | 29x |
|
|
229
|
+
| random, depth 20 | 16 | 7.8 ms | 12.8 ms | 10.8 ms | 1.6x |
|
|
230
|
+
| random, depth 20 | 20 | 17.2 ms | 55.6 ms | 55.0 ms | 3.2x |
|
|
231
|
+
| random, depth 20 | 24 | 43.4 ms | 0.62 s | 0.62 s | 14x |
|
|
232
|
+
| random, depth 20 | 26 | 0.13 s | 3.08 s | 2.92 s | 23x |
|
|
233
|
+
|
|
234
|
+

|
|
235
|
+
|
|
236
|
+
aer-metal is faster at every measured size from 14 qubits up. At 12 qubits Aer wins
|
|
237
|
+
on Quantum Volume (0.9x) and on random circuits (0.6x). At that size the fixed per-run
|
|
238
|
+
costs, a few milliseconds, are larger than the simulation work. At 30 qubits aer-metal takes 1.1 s (QFT), 3.5 s (Quantum Volume) and
|
|
239
|
+
1.6 s (random). The full tables are in [docs/REPORT.md](https://github.com/alexiskirke/aer-metal/blob/main/docs/REPORT.md) and
|
|
240
|
+
`bench/RESULTS_m5.md`.
|
|
241
|
+
|
|
242
|
+
**Thermal throttling caveat.** Under sustained load, Aer on the CPU slows down within
|
|
243
|
+
about a second and recovers after an idle period. In back-to-back runs on this laptop,
|
|
244
|
+
the same 24-qubit QFT took 0.9 s, then 1.9 s, 2.8 s and so on, up to 4.7 s. GPU timings
|
|
245
|
+
stayed stable. Long jobs therefore see larger speedups than the cold numbers above,
|
|
246
|
+
which are the fair comparison for short jobs. Power state matters too: on battery in
|
|
247
|
+
low-power mode, aer-metal ran 2–4x slower end to end (the cause was not established). Your numbers will depend on the
|
|
248
|
+
machine, its cooling and the power mode.
|
|
249
|
+
|
|
250
|
+
## How it works
|
|
251
|
+
|
|
252
|
+
- The state is a single `MTLBuffer` in shared (unified) memory, so there are no host–device
|
|
253
|
+
copies.
|
|
254
|
+
- The Metal kernels mirror Aer's Thrust functors: dense 1–5-qubit matrices, diagonals,
|
|
255
|
+
multi-controlled gates, permutations, reductions (norm, probabilities, Pauli expectation
|
|
256
|
+
values), measurement collapse and sampling. They are compiled at runtime from the source
|
|
257
|
+
embedded in the module.
|
|
258
|
+
- Many gates are encoded into a single command buffer, so the CPU does not make a round
|
|
259
|
+
trip per gate.
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
Apache-2.0. Parts of this project are ported from Qiskit Aer (Apache-2.0, © IBM). See
|
|
264
|
+
[NOTICE](https://github.com/alexiskirke/aer-metal/blob/main/NOTICE) and [LICENSE](https://github.com/alexiskirke/aer-metal/blob/main/LICENSE).
|