qiskit-aer 0.17.2__cp314-cp314-win_amd64.whl
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.
- qiskit_aer/VERSION.txt +1 -0
- qiskit_aer/__init__.py +89 -0
- qiskit_aer/aererror.py +30 -0
- qiskit_aer/aerprovider.py +119 -0
- qiskit_aer/backends/__init__.py +20 -0
- qiskit_aer/backends/aer_compiler.py +1085 -0
- qiskit_aer/backends/aer_simulator.py +1025 -0
- qiskit_aer/backends/aerbackend.py +679 -0
- qiskit_aer/backends/backend_utils.py +567 -0
- qiskit_aer/backends/backendconfiguration.py +395 -0
- qiskit_aer/backends/backendproperties.py +590 -0
- qiskit_aer/backends/compatibility.py +287 -0
- qiskit_aer/backends/controller_wrappers.cp314-win_amd64.pyd +0 -0
- qiskit_aer/backends/libopenblas.dll +0 -0
- qiskit_aer/backends/name_mapping.py +306 -0
- qiskit_aer/backends/qasm_simulator.py +925 -0
- qiskit_aer/backends/statevector_simulator.py +330 -0
- qiskit_aer/backends/unitary_simulator.py +316 -0
- qiskit_aer/jobs/__init__.py +35 -0
- qiskit_aer/jobs/aerjob.py +143 -0
- qiskit_aer/jobs/utils.py +66 -0
- qiskit_aer/library/__init__.py +204 -0
- qiskit_aer/library/control_flow_instructions/__init__.py +16 -0
- qiskit_aer/library/control_flow_instructions/jump.py +47 -0
- qiskit_aer/library/control_flow_instructions/mark.py +30 -0
- qiskit_aer/library/control_flow_instructions/store.py +29 -0
- qiskit_aer/library/default_qubits.py +44 -0
- qiskit_aer/library/instructions_table.csv +21 -0
- qiskit_aer/library/save_instructions/__init__.py +44 -0
- qiskit_aer/library/save_instructions/save_amplitudes.py +168 -0
- qiskit_aer/library/save_instructions/save_clifford.py +63 -0
- qiskit_aer/library/save_instructions/save_data.py +129 -0
- qiskit_aer/library/save_instructions/save_density_matrix.py +91 -0
- qiskit_aer/library/save_instructions/save_expectation_value.py +257 -0
- qiskit_aer/library/save_instructions/save_matrix_product_state.py +71 -0
- qiskit_aer/library/save_instructions/save_probabilities.py +156 -0
- qiskit_aer/library/save_instructions/save_stabilizer.py +70 -0
- qiskit_aer/library/save_instructions/save_state.py +79 -0
- qiskit_aer/library/save_instructions/save_statevector.py +120 -0
- qiskit_aer/library/save_instructions/save_superop.py +62 -0
- qiskit_aer/library/save_instructions/save_unitary.py +63 -0
- qiskit_aer/library/set_instructions/__init__.py +19 -0
- qiskit_aer/library/set_instructions/set_density_matrix.py +78 -0
- qiskit_aer/library/set_instructions/set_matrix_product_state.py +83 -0
- qiskit_aer/library/set_instructions/set_stabilizer.py +77 -0
- qiskit_aer/library/set_instructions/set_statevector.py +78 -0
- qiskit_aer/library/set_instructions/set_superop.py +78 -0
- qiskit_aer/library/set_instructions/set_unitary.py +78 -0
- qiskit_aer/noise/__init__.py +265 -0
- qiskit_aer/noise/device/__init__.py +25 -0
- qiskit_aer/noise/device/models.py +397 -0
- qiskit_aer/noise/device/parameters.py +202 -0
- qiskit_aer/noise/errors/__init__.py +30 -0
- qiskit_aer/noise/errors/base_quantum_error.py +119 -0
- qiskit_aer/noise/errors/pauli_error.py +283 -0
- qiskit_aer/noise/errors/pauli_lindblad_error.py +363 -0
- qiskit_aer/noise/errors/quantum_error.py +451 -0
- qiskit_aer/noise/errors/readout_error.py +355 -0
- qiskit_aer/noise/errors/standard_errors.py +498 -0
- qiskit_aer/noise/noise_model.py +1231 -0
- qiskit_aer/noise/noiseerror.py +30 -0
- qiskit_aer/noise/passes/__init__.py +18 -0
- qiskit_aer/noise/passes/local_noise_pass.py +160 -0
- qiskit_aer/noise/passes/relaxation_noise_pass.py +137 -0
- qiskit_aer/primitives/__init__.py +44 -0
- qiskit_aer/primitives/estimator.py +751 -0
- qiskit_aer/primitives/estimator_v2.py +159 -0
- qiskit_aer/primitives/sampler.py +361 -0
- qiskit_aer/primitives/sampler_v2.py +256 -0
- qiskit_aer/quantum_info/__init__.py +32 -0
- qiskit_aer/quantum_info/states/__init__.py +16 -0
- qiskit_aer/quantum_info/states/aer_densitymatrix.py +313 -0
- qiskit_aer/quantum_info/states/aer_state.py +525 -0
- qiskit_aer/quantum_info/states/aer_statevector.py +302 -0
- qiskit_aer/utils/__init__.py +44 -0
- qiskit_aer/utils/noise_model_inserter.py +66 -0
- qiskit_aer/utils/noise_transformation.py +431 -0
- qiskit_aer/version.py +86 -0
- qiskit_aer-0.17.2.dist-info/METADATA +209 -0
- qiskit_aer-0.17.2.dist-info/RECORD +83 -0
- qiskit_aer-0.17.2.dist-info/WHEEL +5 -0
- qiskit_aer-0.17.2.dist-info/licenses/LICENSE.txt +203 -0
- qiskit_aer-0.17.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2019, 2021
|
|
4
|
+
#
|
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
8
|
+
#
|
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
11
|
+
# that they have been altered from the originals.
|
|
12
|
+
"""
|
|
13
|
+
Aer qasm simulator backend.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import copy
|
|
17
|
+
import logging
|
|
18
|
+
from qiskit.providers.options import Options
|
|
19
|
+
from qiskit.providers.backend import BackendV2
|
|
20
|
+
|
|
21
|
+
from ..version import __version__
|
|
22
|
+
from .aerbackend import AerBackend, AerError
|
|
23
|
+
from .backendconfiguration import AerBackendConfiguration
|
|
24
|
+
from .backendproperties import target_to_backend_properties
|
|
25
|
+
from .backend_utils import (
|
|
26
|
+
cpp_execute_circuits,
|
|
27
|
+
available_methods,
|
|
28
|
+
available_devices,
|
|
29
|
+
MAX_QUBITS_STATEVECTOR,
|
|
30
|
+
BASIS_GATES,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# pylint: disable=import-error, no-name-in-module, abstract-method
|
|
34
|
+
from .controller_wrappers import aer_controller_execute
|
|
35
|
+
|
|
36
|
+
logger = logging.getLogger(__name__)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AerSimulator(AerBackend):
|
|
40
|
+
"""
|
|
41
|
+
Noisy quantum circuit simulator backend.
|
|
42
|
+
|
|
43
|
+
**Configurable Options**
|
|
44
|
+
|
|
45
|
+
The `AerSimulator` supports multiple simulation methods and
|
|
46
|
+
configurable options for each simulation method. These may be set using the
|
|
47
|
+
appropriate kwargs during initialization. They can also be set of updated
|
|
48
|
+
using the :meth:`set_options` method.
|
|
49
|
+
|
|
50
|
+
Run-time options may also be specified as kwargs using the :meth:`run` method.
|
|
51
|
+
These will not be stored in the backend and will only apply to that execution.
|
|
52
|
+
They will also override any previously set options.
|
|
53
|
+
|
|
54
|
+
For example, to configure a density matrix simulator with a custom noise
|
|
55
|
+
model to use for every execution
|
|
56
|
+
|
|
57
|
+
.. code-block:: python
|
|
58
|
+
|
|
59
|
+
noise_model = NoiseModel.from_backend(backend)
|
|
60
|
+
backend = AerSimulator(method='density_matrix',
|
|
61
|
+
noise_model=noise_model)
|
|
62
|
+
|
|
63
|
+
**Simulating an IBM Quantum Backend**
|
|
64
|
+
|
|
65
|
+
The simulator can be automatically configured to mimic an IBM Quantum backend using
|
|
66
|
+
the :meth:`from_backend` method. This will configure the simulator to use the
|
|
67
|
+
basic device :class:`NoiseModel` for that backend, and the same basis gates
|
|
68
|
+
and coupling map.
|
|
69
|
+
|
|
70
|
+
.. code-block:: python
|
|
71
|
+
|
|
72
|
+
backend = AerSimulator.from_backend(backend)
|
|
73
|
+
|
|
74
|
+
**Returning the Final State**
|
|
75
|
+
|
|
76
|
+
The final state of the simulator can be saved to the returned
|
|
77
|
+
``Result`` object by appending the
|
|
78
|
+
:func:`~qiskit_aer.library.save_state` instruction to a
|
|
79
|
+
quantum circuit. The format of the final state will depend on the
|
|
80
|
+
simulation method used. Additional simulation data may also be saved
|
|
81
|
+
using the other save instructions in :mod:`qiskit.provider.aer.library`.
|
|
82
|
+
|
|
83
|
+
**Simulation Method Option**
|
|
84
|
+
|
|
85
|
+
The simulation method is set using the ``method`` kwarg. A list supported
|
|
86
|
+
simulation methods can be returned using :meth:`available_methods`, these
|
|
87
|
+
are
|
|
88
|
+
|
|
89
|
+
* ``"automatic"``: Default simulation method. Select the simulation
|
|
90
|
+
method automatically based on the circuit and noise model.
|
|
91
|
+
|
|
92
|
+
* ``"statevector"``: A dense statevector simulation that can sample
|
|
93
|
+
measurement outcomes from *ideal* circuits with all measurements at
|
|
94
|
+
end of the circuit. For noisy simulations each shot samples a
|
|
95
|
+
randomly sampled noisy circuit from the noise model.
|
|
96
|
+
|
|
97
|
+
* ``"density_matrix"``: A dense density matrix simulation that may
|
|
98
|
+
sample measurement outcomes from *noisy* circuits with all
|
|
99
|
+
measurements at end of the circuit.
|
|
100
|
+
|
|
101
|
+
* ``"stabilizer"``: An efficient Clifford stabilizer state simulator
|
|
102
|
+
that can simulate noisy Clifford circuits if all errors in the noise
|
|
103
|
+
model are also Clifford errors.
|
|
104
|
+
|
|
105
|
+
* ``"extended_stabilizer"``: An approximate simulated for Clifford + T
|
|
106
|
+
circuits based on a state decomposition into ranked-stabilizer state.
|
|
107
|
+
The number of terms grows with the number of non-Clifford (T) gates.
|
|
108
|
+
|
|
109
|
+
* ``"matrix_product_state"``: A tensor-network statevector simulator that
|
|
110
|
+
uses a Matrix Product State (MPS) representation for the state. This
|
|
111
|
+
can be done either with or without truncation of the MPS bond dimensions
|
|
112
|
+
depending on the simulator options. The default behaviour is no
|
|
113
|
+
truncation.
|
|
114
|
+
|
|
115
|
+
* ``"unitary"``: A dense unitary matrix simulation of an ideal circuit.
|
|
116
|
+
This simulates the unitary matrix of the circuit itself rather than
|
|
117
|
+
the evolution of an initial quantum state. This method can only
|
|
118
|
+
simulate gates, it does not support measurement, reset, or noise.
|
|
119
|
+
|
|
120
|
+
* ``"superop"``: A dense superoperator matrix simulation of an ideal or
|
|
121
|
+
noisy circuit. This simulates the superoperator matrix of the circuit
|
|
122
|
+
itself rather than the evolution of an initial quantum state. This method
|
|
123
|
+
can simulate ideal and noisy gates, and reset, but does not support
|
|
124
|
+
measurement.
|
|
125
|
+
|
|
126
|
+
* ``"tensor_network"``: A tensor-network based simulation that supports
|
|
127
|
+
both statevector and density matrix. Currently there is only available
|
|
128
|
+
for GPU and accelerated by using cuTensorNet APIs of cuQuantum.
|
|
129
|
+
|
|
130
|
+
**GPU Simulation**
|
|
131
|
+
|
|
132
|
+
By default all simulation methods run on the CPU, however select methods
|
|
133
|
+
also support running on a GPU if qiskit-aer was installed with GPU support
|
|
134
|
+
on a compatible NVidia GPU and CUDA version.
|
|
135
|
+
|
|
136
|
+
+--------------------------+---------------+
|
|
137
|
+
| Method | GPU Supported |
|
|
138
|
+
+==========================+===============+
|
|
139
|
+
| ``automatic`` | Sometimes |
|
|
140
|
+
+--------------------------+---------------+
|
|
141
|
+
| ``statevector`` | Yes |
|
|
142
|
+
+--------------------------+---------------+
|
|
143
|
+
| ``density_matrix`` | Yes |
|
|
144
|
+
+--------------------------+---------------+
|
|
145
|
+
| ``stabilizer`` | No |
|
|
146
|
+
+--------------------------+---------------+
|
|
147
|
+
| ``matrix_product_state`` | No |
|
|
148
|
+
+--------------------------+---------------+
|
|
149
|
+
| ``extended_stabilizer`` | No |
|
|
150
|
+
+--------------------------+---------------+
|
|
151
|
+
| ``unitary`` | Yes |
|
|
152
|
+
+--------------------------+---------------+
|
|
153
|
+
| ``superop`` | No |
|
|
154
|
+
+--------------------------+---------------+
|
|
155
|
+
| ``tensor_network`` | Yes(GPU only) |
|
|
156
|
+
+--------------------------+---------------+
|
|
157
|
+
|
|
158
|
+
Running a GPU simulation is done using ``device="GPU"`` kwarg during
|
|
159
|
+
initialization or with :meth:`set_options`. The list of supported devices
|
|
160
|
+
for the current system can be returned using :meth:`available_devices`.
|
|
161
|
+
|
|
162
|
+
For multiple shots simulation, OpenMP threads should be exploited for
|
|
163
|
+
multi-GPUs. Number of GPUs used for multi-shots is reported in
|
|
164
|
+
metadata ``gpu_parallel_shots_`` or is batched execution is done reported
|
|
165
|
+
in metadata ``batched_shots_optimization_parallel_gpus``.
|
|
166
|
+
For large qubits circuits with multiple GPUs, number of GPUs is reported
|
|
167
|
+
in metadata ``chunk_parallel_gpus`` in ``cacheblocking``.
|
|
168
|
+
|
|
169
|
+
If AerSimulator is built with cuStateVec support, cuStateVec APIs are enabled
|
|
170
|
+
by setting ``cuStateVec_enable=True``.
|
|
171
|
+
|
|
172
|
+
* ``target_gpus`` (list): List of GPU's IDs starting from 0 sets
|
|
173
|
+
the target GPUs used for the simulation.
|
|
174
|
+
If this option is not specified, all the available GPUs are used for
|
|
175
|
+
chunks/shots distribution.
|
|
176
|
+
|
|
177
|
+
**Additional Backend Options**
|
|
178
|
+
|
|
179
|
+
The following simulator specific backend options are supported
|
|
180
|
+
|
|
181
|
+
* ``method`` (str): Set the simulation method (Default: ``"automatic"``).
|
|
182
|
+
Use :meth:`available_methods` to return a list of all availabe methods.
|
|
183
|
+
|
|
184
|
+
* ``device`` (str): Set the simulation device (Default: ``"CPU"``).
|
|
185
|
+
Use :meth:`available_devices` to return a list of devices supported
|
|
186
|
+
on the current system.
|
|
187
|
+
|
|
188
|
+
* ``precision`` (str): Set the floating point precision for
|
|
189
|
+
certain simulation methods to either ``"single"`` or ``"double"``
|
|
190
|
+
precision (default: ``"double"``).
|
|
191
|
+
|
|
192
|
+
* ``executor`` (futures.Executor or None): Set a custom executor for
|
|
193
|
+
asynchronous running of simulation jobs (Default: None).
|
|
194
|
+
|
|
195
|
+
* ``max_job_size`` (int or None): If the number of run circuits
|
|
196
|
+
exceeds this value simulation will be run as a set of of sub-jobs
|
|
197
|
+
on the executor. If ``None`` simulation of all circuits are submitted
|
|
198
|
+
to the executor as a single job (Default: None).
|
|
199
|
+
|
|
200
|
+
* ``max_shot_size`` (int or None): If the number of shots of a noisy
|
|
201
|
+
circuit exceeds this value simulation will be split into multi
|
|
202
|
+
circuits for execution and the results accumulated. If ``None``
|
|
203
|
+
circuits will not be split based on shots. When splitting circuits
|
|
204
|
+
use the ``max_job_size`` option to control how these split circuits
|
|
205
|
+
should be submitted to the executor (Default: None).
|
|
206
|
+
|
|
207
|
+
a noise model exceeds this value simulation will be splitted into
|
|
208
|
+
sub-circuits. If ``None`` simulator does noting (Default: None).
|
|
209
|
+
|
|
210
|
+
* ``enable_truncation`` (bool): If set to True this removes unnecessary
|
|
211
|
+
qubits which do not affect the simulation outcome from the simulated
|
|
212
|
+
circuits (Default: True).
|
|
213
|
+
|
|
214
|
+
* ``zero_threshold`` (double): Sets the threshold for truncating
|
|
215
|
+
small values to zero in the result data (Default: 1e-10).
|
|
216
|
+
|
|
217
|
+
* ``validation_threshold`` (double): Sets the threshold for checking
|
|
218
|
+
if initial states are valid (Default: 1e-8).
|
|
219
|
+
|
|
220
|
+
* ``max_parallel_threads`` (int): Sets the maximum number of CPU
|
|
221
|
+
cores used by OpenMP for parallelization. If set to 0 the
|
|
222
|
+
maximum will be set to the number of CPU cores (Default: 0).
|
|
223
|
+
|
|
224
|
+
* ``max_parallel_experiments`` (int): Sets the maximum number of
|
|
225
|
+
experiments that may be executed in parallel up to the
|
|
226
|
+
max_parallel_threads value. If set to 1 parallel circuit
|
|
227
|
+
execution will be disabled. If set to 0 the maximum will be
|
|
228
|
+
automatically set to max_parallel_threads (Default: 1).
|
|
229
|
+
|
|
230
|
+
* ``max_parallel_shots`` (int): Sets the maximum number of
|
|
231
|
+
shots that may be executed in parallel during each experiment
|
|
232
|
+
execution, up to the max_parallel_threads value. If set to 1
|
|
233
|
+
parallel shot execution will be disabled. If set to 0 the
|
|
234
|
+
maximum will be automatically set to max_parallel_threads.
|
|
235
|
+
Note that this cannot be enabled at the same time as parallel
|
|
236
|
+
experiment execution (Default: 0).
|
|
237
|
+
|
|
238
|
+
* ``max_memory_mb`` (int): Sets the maximum size of memory
|
|
239
|
+
to store quantum states. If quantum states need more, an error
|
|
240
|
+
is thrown unless -1 is set. In general, a state vector of n-qubits
|
|
241
|
+
uses 2^n complex values (16 Bytes).
|
|
242
|
+
If set to 0, the maximum will be automatically set to
|
|
243
|
+
the system memory size (Default: 0).
|
|
244
|
+
|
|
245
|
+
* ``cuStateVec_enable`` (bool): This option enables accelerating by
|
|
246
|
+
cuStateVec library of cuQuantum from NVIDIA, that has highly optimized
|
|
247
|
+
kernels for GPUs (Default: False). This option will be ignored
|
|
248
|
+
if AerSimulator is not built with cuStateVec support.
|
|
249
|
+
|
|
250
|
+
* ``blocking_enable`` (bool): This option enables parallelization with
|
|
251
|
+
multiple GPUs or multiple processes with MPI (CPU/GPU). This option
|
|
252
|
+
is only available for ``"statevector"``, ``"density_matrix"`` and
|
|
253
|
+
``"unitary"`` (Default: False).
|
|
254
|
+
|
|
255
|
+
* ``blocking_qubits`` (int): Sets the number of qubits of chunk size
|
|
256
|
+
used for parallelizing with multiple GPUs or multiple processes with
|
|
257
|
+
MPI (CPU/GPU). 16*2^blocking_qubits should be less than 1/4 of the GPU
|
|
258
|
+
memory in double precision. This option is only available for
|
|
259
|
+
``"statevector"``, ``"density_matrix"`` and ``"unitary"``.
|
|
260
|
+
This option should be set when using option ``blocking_enable=True``
|
|
261
|
+
(Default: 0).
|
|
262
|
+
If multiple GPUs are used for parallelization number of GPUs is
|
|
263
|
+
reported to ``chunk_parallel_gpus`` in ``cacheblocking`` metadata.
|
|
264
|
+
|
|
265
|
+
* ``chunk_swap_buffer_qubits`` (int): Sets the number of qubits of
|
|
266
|
+
maximum buffer size (=2^chunk_swap_buffer_qubits) used for multiple
|
|
267
|
+
chunk-swaps over MPI processes. This parameter should be smaller than
|
|
268
|
+
``blocking_qubits`` otherwise multiple chunk-swaps is disabled.
|
|
269
|
+
``blocking_qubits`` - ``chunk_swap_buffer_qubits`` swaps are applied
|
|
270
|
+
at single all-to-all communication. (Default: 15).
|
|
271
|
+
|
|
272
|
+
* ``batched_shots_gpu`` (bool): This option enables batched execution
|
|
273
|
+
of multiple shot simulations on GPU devices for GPU enabled simulation
|
|
274
|
+
methods. This optimization is intended for statevector simulations with
|
|
275
|
+
noise models, or statevecor and density matrix simulations with
|
|
276
|
+
intermediate measurements and can greatly accelerate simulation time
|
|
277
|
+
on GPUs. If there are multiple GPUs on the system, shots are distributed
|
|
278
|
+
automatically across available GPUs. Also this option distributes multiple
|
|
279
|
+
shots to parallel processes of MPI (Default: False).
|
|
280
|
+
If multiple GPUs are used for batched exectuion number of GPUs is
|
|
281
|
+
reported to ``batched_shots_optimization_parallel_gpus`` metadata.
|
|
282
|
+
``cuStateVec_enable`` is not supported for this option.
|
|
283
|
+
|
|
284
|
+
* ``batched_shots_gpu_max_qubits`` (int): This option sets the maximum
|
|
285
|
+
number of qubits for enabling the ``batched_shots_gpu`` option. If the
|
|
286
|
+
number of active circuit qubits is greater than this value batching of
|
|
287
|
+
simulation shots will not be used. (Default: 16).
|
|
288
|
+
|
|
289
|
+
* ``num_threads_per_device`` (int): This option sets the number of
|
|
290
|
+
threads per device. For GPU simulation, this value sets number of
|
|
291
|
+
threads per GPU. This parameter is used to optimize Pauli noise
|
|
292
|
+
simulation with multiple-GPUs (Default: 1).
|
|
293
|
+
|
|
294
|
+
* ``shot_branching_enable`` (bool): This option enables/disables
|
|
295
|
+
applying shot-branching technique to speed up multi-shots of dynamic
|
|
296
|
+
circutis simulations or circuits simulations with noise models.
|
|
297
|
+
(Default: False).
|
|
298
|
+
Starting from single state shared with multiple shots and
|
|
299
|
+
state will be branched dynamically at runtime.
|
|
300
|
+
This option can decrease runs of shots if there will be less branches
|
|
301
|
+
than number of total shots.
|
|
302
|
+
This option is available for ``"statevector"``, ``"density_matrix"``
|
|
303
|
+
and ``"tensor_network"``.
|
|
304
|
+
WARNING: `shot_branching` option is unstable on MacOS currently
|
|
305
|
+
|
|
306
|
+
* ``shot_branching_sampling_enable`` (bool): This option enables/disables
|
|
307
|
+
applying sampling measure if the input circuit has all the measure
|
|
308
|
+
operations at the end of the circuit. (Default: False).
|
|
309
|
+
Because measure operation branches state into 2 states, it is not
|
|
310
|
+
efficient to apply branching for measure.
|
|
311
|
+
Sampling measure improves speed to get counts for multiple-shots
|
|
312
|
+
sharing the same state.
|
|
313
|
+
Note that the counts obtained by sampling measure may not be as same as
|
|
314
|
+
the counts calculated by multiple measure operations,
|
|
315
|
+
becuase sampling measure takes only one randome number per shot.
|
|
316
|
+
This option is available for ``"statevector"``, ``"density_matrix"``
|
|
317
|
+
and ``"tensor_network"``.
|
|
318
|
+
|
|
319
|
+
* ``accept_distributed_results`` (bool): This option enables storing
|
|
320
|
+
results independently in each process (Default: None).
|
|
321
|
+
|
|
322
|
+
* ``runtime_parameter_bind_enable`` (bool): If this option is True
|
|
323
|
+
parameters are bound at runtime by using multi-shots without constructing
|
|
324
|
+
circuits for each parameters. For GPU this option can be used with
|
|
325
|
+
``batched_shots_gpu`` to run with multiple parameters in a batch.
|
|
326
|
+
(Default: False).
|
|
327
|
+
|
|
328
|
+
These backend options only apply when using the ``"statevector"``
|
|
329
|
+
simulation method:
|
|
330
|
+
|
|
331
|
+
* ``statevector_parallel_threshold`` (int): Sets the threshold that
|
|
332
|
+
the number of qubits must be greater than to enable OpenMP
|
|
333
|
+
parallelization for matrix multiplication during execution of
|
|
334
|
+
an experiment. If parallel circuit or shot execution is enabled
|
|
335
|
+
this will only use unallocated CPU cores up to
|
|
336
|
+
max_parallel_threads. Note that setting this too low can reduce
|
|
337
|
+
performance (Default: 14).
|
|
338
|
+
|
|
339
|
+
* ``statevector_sample_measure_opt`` (int): Sets the threshold that
|
|
340
|
+
the number of qubits must be greater than to enable a large
|
|
341
|
+
qubit optimized implementation of measurement sampling. Note
|
|
342
|
+
that setting this two low can reduce performance (Default: 10)
|
|
343
|
+
|
|
344
|
+
These backend options only apply when using the ``"stabilizer"``
|
|
345
|
+
simulation method:
|
|
346
|
+
|
|
347
|
+
* ``stabilizer_max_snapshot_probabilities`` (int): set the maximum
|
|
348
|
+
qubit number for the :class:`~qiskit_aer.library.SaveProbabilities` instruction (Default: 32).
|
|
349
|
+
|
|
350
|
+
These backend options only apply when using the ``"extended_stabilizer"``
|
|
351
|
+
simulation method:
|
|
352
|
+
|
|
353
|
+
* ``extended_stabilizer_sampling_method`` (string): Choose how to simulate
|
|
354
|
+
measurements on qubits. The performance of the simulator depends
|
|
355
|
+
significantly on this choice. In the following, let n be the number of
|
|
356
|
+
qubits in the circuit, m the number of qubits measured, and S be the
|
|
357
|
+
number of shots (Default: resampled_metropolis).
|
|
358
|
+
|
|
359
|
+
- ``"metropolis"``: Use a Monte-Carlo method to sample many output
|
|
360
|
+
strings from the simulator at once. To be accurate, this method
|
|
361
|
+
requires that all the possible output strings have a non-zero
|
|
362
|
+
probability. It will give inaccurate results on cases where
|
|
363
|
+
the circuit has many zero-probability outcomes.
|
|
364
|
+
This method has an overall runtime that scales as n^{2} + (S-1)n.
|
|
365
|
+
|
|
366
|
+
- ``"resampled_metropolis"``: A variant of the metropolis method,
|
|
367
|
+
where the Monte-Carlo method is reinitialised for every shot. This
|
|
368
|
+
gives better results for circuits where some outcomes have zero
|
|
369
|
+
probability, but will still fail if the output distribution
|
|
370
|
+
is sparse. The overall runtime scales as Sn^{2}.
|
|
371
|
+
|
|
372
|
+
- ``"norm_estimation"``: An alternative sampling method using
|
|
373
|
+
random state inner products to estimate outcome probabilities. This
|
|
374
|
+
method requires twice as much memory, and significantly longer
|
|
375
|
+
runtimes, but gives accurate results on circuits with sparse
|
|
376
|
+
output distributions. The overall runtime scales as Sn^{3}m^{3}.
|
|
377
|
+
|
|
378
|
+
* ``extended_stabilizer_metropolis_mixing_time`` (int): Set how long the
|
|
379
|
+
monte-carlo method runs before performing measurements. If the
|
|
380
|
+
output distribution is strongly peaked, this can be decreased
|
|
381
|
+
alongside setting extended_stabilizer_disable_measurement_opt
|
|
382
|
+
to True (Default: 5000).
|
|
383
|
+
|
|
384
|
+
* ``extended_stabilizer_approximation_error`` (double): Set the error
|
|
385
|
+
in the approximation for the extended_stabilizer method. A
|
|
386
|
+
smaller error needs more memory and computational time
|
|
387
|
+
(Default: 0.05).
|
|
388
|
+
|
|
389
|
+
* ``extended_stabilizer_norm_estimation_samples`` (int): The default number
|
|
390
|
+
of samples for the norm estimation sampler. The method will use the
|
|
391
|
+
default, or 4m^{2} samples where m is the number of qubits to be
|
|
392
|
+
measured, whichever is larger (Default: 100).
|
|
393
|
+
|
|
394
|
+
* ``extended_stabilizer_norm_estimation_repetitions`` (int): The number
|
|
395
|
+
of times to repeat the norm estimation. The median of these reptitions
|
|
396
|
+
is used to estimate and sample output strings (Default: 3).
|
|
397
|
+
|
|
398
|
+
* ``extended_stabilizer_parallel_threshold`` (int): Set the minimum
|
|
399
|
+
size of the extended stabilizer decomposition before we enable
|
|
400
|
+
OpenMP parallelization. If parallel circuit or shot execution
|
|
401
|
+
is enabled this will only use unallocated CPU cores up to
|
|
402
|
+
max_parallel_threads (Default: 100).
|
|
403
|
+
|
|
404
|
+
* ``extended_stabilizer_probabilities_snapshot_samples`` (int): If using
|
|
405
|
+
the metropolis or resampled_metropolis sampling method, set the number of
|
|
406
|
+
samples used to estimate probabilities in a probabilities snapshot
|
|
407
|
+
(Default: 3000).
|
|
408
|
+
|
|
409
|
+
These backend options only apply when using the ``matrix_product_state``
|
|
410
|
+
simulation method:
|
|
411
|
+
|
|
412
|
+
* ``matrix_product_state_max_bond_dimension`` (int): Sets a limit
|
|
413
|
+
on the number of Schmidt coefficients retained at the end of
|
|
414
|
+
the svd algorithm. Coefficients beyond this limit will be discarded.
|
|
415
|
+
(Default: None, i.e., no limit on the bond dimension).
|
|
416
|
+
|
|
417
|
+
* ``matrix_product_state_truncation_threshold`` (double):
|
|
418
|
+
Discard the smallest coefficients for which the sum of
|
|
419
|
+
their squares is smaller than this threshold.
|
|
420
|
+
(Default: 1e-16).
|
|
421
|
+
|
|
422
|
+
* ``mps_sample_measure_algorithm`` (str): Choose which algorithm to use for
|
|
423
|
+
``"sample_measure"`` (Default: "mps_apply_measure").
|
|
424
|
+
|
|
425
|
+
- ``mps_probabilities``: This method first constructs the probability
|
|
426
|
+
vector and then generates a sample per shot. It is more efficient for
|
|
427
|
+
a large number of shots and a small number of qubits, with complexity
|
|
428
|
+
O(2^n * n * D^2) to create the vector and O(1) per shot, where n is
|
|
429
|
+
the number of qubits and D is the bond dimension.
|
|
430
|
+
|
|
431
|
+
- ``mps_apply_measure``: This method creates a copy of the mps structure
|
|
432
|
+
and measures directly on it. It is more efficient for a small number of
|
|
433
|
+
shots, and a large number of qubits, with complexity around
|
|
434
|
+
O(n * D^2) per shot.
|
|
435
|
+
|
|
436
|
+
* ``mps_log_data`` (bool): if True, output logging data of the MPS
|
|
437
|
+
structure: bond dimensions and values discarded during approximation.
|
|
438
|
+
(Default: False)
|
|
439
|
+
|
|
440
|
+
* ``mps_swap_direction`` (str): Determine the direction of swapping the
|
|
441
|
+
qubits when internal swaps are inserted for a 2-qubit gate.
|
|
442
|
+
Possible values are "mps_swap_right" and "mps_swap_left".
|
|
443
|
+
(Default: "mps_swap_left")
|
|
444
|
+
|
|
445
|
+
* ``chop_threshold`` (float): This option sets a threshold for
|
|
446
|
+
truncating snapshots (Default: 1e-8).
|
|
447
|
+
|
|
448
|
+
* ``mps_parallel_threshold`` (int): This option sets OMP number threshold (Default: 14).
|
|
449
|
+
|
|
450
|
+
* ``mps_omp_threads`` (int): This option sets the number of OMP threads (Default: 1).
|
|
451
|
+
|
|
452
|
+
* ``mps_lapack`` (bool): This option indicates to compute the SVD function
|
|
453
|
+
using OpenBLAS/Lapack interface (Default: False).
|
|
454
|
+
|
|
455
|
+
These backend options only apply when using the ``tensor_network``
|
|
456
|
+
simulation method:
|
|
457
|
+
|
|
458
|
+
* ``tensor_network_num_sampling_qubits`` (int): is used to set number
|
|
459
|
+
of qubits to be sampled in single tensor network contraction when
|
|
460
|
+
using sampling measure. (Default: 10)
|
|
461
|
+
|
|
462
|
+
* ``use_cuTensorNet_autotuning`` (bool): enables auto tuning of plan
|
|
463
|
+
in cuTensorNet API. It takes some time for tuning, so enable if the
|
|
464
|
+
circuit is very large. (Default: False)
|
|
465
|
+
|
|
466
|
+
These backend options apply in circuit optimization passes:
|
|
467
|
+
|
|
468
|
+
* ``fusion_enable`` (bool): Enable fusion optimization in circuit
|
|
469
|
+
optimization passes [Default: True]
|
|
470
|
+
* ``fusion_verbose`` (bool): Output gates generated in fusion optimization
|
|
471
|
+
into metadata [Default: False]
|
|
472
|
+
* ``fusion_max_qubit`` (int): Maximum number of qubits for a operation generated
|
|
473
|
+
in a fusion optimization. A default value (``None``) automatically sets a value
|
|
474
|
+
depending on the simulation method: [Default: None]
|
|
475
|
+
* ``fusion_threshold`` (int): Threshold that number of qubits must be greater
|
|
476
|
+
than or equal to enable fusion optimization. A default value automatically sets
|
|
477
|
+
a value depending on the simulation method [Default: None]
|
|
478
|
+
|
|
479
|
+
``fusion_enable`` and ``fusion_threshold`` are set as follows if their default
|
|
480
|
+
values (``None``) are configured:
|
|
481
|
+
|
|
482
|
+
+--------------------------+----------------------+----------------------+
|
|
483
|
+
| Method | ``fusion_max_qubit`` | ``fusion_threshold`` |
|
|
484
|
+
+==========================+======================+======================+
|
|
485
|
+
| ``statevector`` | 5 | 14 |
|
|
486
|
+
+--------------------------+----------------------+----------------------+
|
|
487
|
+
| ``density_matrix`` | 2 | 7 |
|
|
488
|
+
+--------------------------+----------------------+----------------------+
|
|
489
|
+
| ``unitary`` | 5 | 7 |
|
|
490
|
+
+--------------------------+----------------------+----------------------+
|
|
491
|
+
| ``superop`` | 2 | 7 |
|
|
492
|
+
+--------------------------+----------------------+----------------------+
|
|
493
|
+
| other methods | 5 | 14 |
|
|
494
|
+
+--------------------------+----------------------+----------------------+
|
|
495
|
+
|
|
496
|
+
"""
|
|
497
|
+
|
|
498
|
+
_BASIS_GATES = BASIS_GATES
|
|
499
|
+
|
|
500
|
+
_CUSTOM_INSTR = {
|
|
501
|
+
"statevector": sorted(
|
|
502
|
+
[
|
|
503
|
+
"quantum_channel",
|
|
504
|
+
"qerror_loc",
|
|
505
|
+
"roerror",
|
|
506
|
+
"kraus",
|
|
507
|
+
"save_expval",
|
|
508
|
+
"save_expval_var",
|
|
509
|
+
"save_probabilities",
|
|
510
|
+
"save_probabilities_dict",
|
|
511
|
+
"save_amplitudes",
|
|
512
|
+
"save_amplitudes_sq",
|
|
513
|
+
"save_density_matrix",
|
|
514
|
+
"save_state",
|
|
515
|
+
"save_statevector",
|
|
516
|
+
"save_statevector_dict",
|
|
517
|
+
"set_statevector",
|
|
518
|
+
"if_else",
|
|
519
|
+
"for_loop",
|
|
520
|
+
"while_loop",
|
|
521
|
+
"break_loop",
|
|
522
|
+
"continue_loop",
|
|
523
|
+
"initialize",
|
|
524
|
+
"reset",
|
|
525
|
+
"switch_case",
|
|
526
|
+
"delay",
|
|
527
|
+
]
|
|
528
|
+
),
|
|
529
|
+
"density_matrix": sorted(
|
|
530
|
+
[
|
|
531
|
+
"quantum_channel",
|
|
532
|
+
"qerror_loc",
|
|
533
|
+
"roerror",
|
|
534
|
+
"kraus",
|
|
535
|
+
"superop",
|
|
536
|
+
"save_state",
|
|
537
|
+
"save_expval",
|
|
538
|
+
"save_expval_var",
|
|
539
|
+
"save_probabilities",
|
|
540
|
+
"save_probabilities_dict",
|
|
541
|
+
"save_density_matrix",
|
|
542
|
+
"save_amplitudes_sq",
|
|
543
|
+
"set_density_matrix",
|
|
544
|
+
"if_else",
|
|
545
|
+
"for_loop",
|
|
546
|
+
"while_loop",
|
|
547
|
+
"break_loop",
|
|
548
|
+
"continue_loop",
|
|
549
|
+
"reset",
|
|
550
|
+
"switch_case",
|
|
551
|
+
"delay",
|
|
552
|
+
]
|
|
553
|
+
),
|
|
554
|
+
"matrix_product_state": sorted(
|
|
555
|
+
[
|
|
556
|
+
"quantum_channel",
|
|
557
|
+
"qerror_loc",
|
|
558
|
+
"roerror",
|
|
559
|
+
"kraus",
|
|
560
|
+
"save_expval",
|
|
561
|
+
"save_expval_var",
|
|
562
|
+
"save_probabilities",
|
|
563
|
+
"save_probabilities_dict",
|
|
564
|
+
"save_state",
|
|
565
|
+
"save_matrix_product_state",
|
|
566
|
+
"save_statevector",
|
|
567
|
+
"save_density_matrix",
|
|
568
|
+
"save_amplitudes",
|
|
569
|
+
"save_amplitudes_sq",
|
|
570
|
+
"set_matrix_product_state",
|
|
571
|
+
"if_else",
|
|
572
|
+
"for_loop",
|
|
573
|
+
"while_loop",
|
|
574
|
+
"break_loop",
|
|
575
|
+
"continue_loop",
|
|
576
|
+
"initialize",
|
|
577
|
+
"reset",
|
|
578
|
+
"switch_case",
|
|
579
|
+
"delay",
|
|
580
|
+
]
|
|
581
|
+
),
|
|
582
|
+
"stabilizer": sorted(
|
|
583
|
+
[
|
|
584
|
+
"quantum_channel",
|
|
585
|
+
"qerror_loc",
|
|
586
|
+
"roerror",
|
|
587
|
+
"save_expval",
|
|
588
|
+
"save_expval_var",
|
|
589
|
+
"save_probabilities",
|
|
590
|
+
"save_probabilities_dict",
|
|
591
|
+
"save_amplitudes_sq",
|
|
592
|
+
"save_state",
|
|
593
|
+
"save_clifford",
|
|
594
|
+
"save_stabilizer",
|
|
595
|
+
"set_stabilizer",
|
|
596
|
+
"if_else",
|
|
597
|
+
"for_loop",
|
|
598
|
+
"while_loop",
|
|
599
|
+
"break_loop",
|
|
600
|
+
"continue_loop",
|
|
601
|
+
"reset",
|
|
602
|
+
"switch_case",
|
|
603
|
+
"delay",
|
|
604
|
+
]
|
|
605
|
+
),
|
|
606
|
+
"extended_stabilizer": sorted(
|
|
607
|
+
[
|
|
608
|
+
"quantum_channel",
|
|
609
|
+
"qerror_loc",
|
|
610
|
+
"roerror",
|
|
611
|
+
"save_statevector",
|
|
612
|
+
"reset",
|
|
613
|
+
"delay",
|
|
614
|
+
]
|
|
615
|
+
),
|
|
616
|
+
"unitary": sorted(
|
|
617
|
+
[
|
|
618
|
+
"save_state",
|
|
619
|
+
"save_unitary",
|
|
620
|
+
"set_unitary",
|
|
621
|
+
"reset",
|
|
622
|
+
"delay",
|
|
623
|
+
]
|
|
624
|
+
),
|
|
625
|
+
"superop": sorted(
|
|
626
|
+
[
|
|
627
|
+
"quantum_channel",
|
|
628
|
+
"qerror_loc",
|
|
629
|
+
"kraus",
|
|
630
|
+
"superop",
|
|
631
|
+
"save_state",
|
|
632
|
+
"save_superop",
|
|
633
|
+
"set_superop",
|
|
634
|
+
"reset",
|
|
635
|
+
"delay",
|
|
636
|
+
]
|
|
637
|
+
),
|
|
638
|
+
"tensor_network": sorted(
|
|
639
|
+
[
|
|
640
|
+
"quantum_channel",
|
|
641
|
+
"qerror_loc",
|
|
642
|
+
"roerror",
|
|
643
|
+
"kraus",
|
|
644
|
+
"superop",
|
|
645
|
+
"save_state",
|
|
646
|
+
"save_expval",
|
|
647
|
+
"save_expval_var",
|
|
648
|
+
"save_probabilities",
|
|
649
|
+
"save_probabilities_dict",
|
|
650
|
+
"save_density_matrix",
|
|
651
|
+
"save_amplitudes",
|
|
652
|
+
"save_amplitudes_sq",
|
|
653
|
+
"save_statevector",
|
|
654
|
+
"save_statevector_dict",
|
|
655
|
+
"set_statevector",
|
|
656
|
+
"set_density_matrix",
|
|
657
|
+
"initialize",
|
|
658
|
+
"reset",
|
|
659
|
+
"switch_case",
|
|
660
|
+
"delay",
|
|
661
|
+
]
|
|
662
|
+
),
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
# Automatic method custom instructions are the union of statevector,
|
|
666
|
+
# density matrix, and stabilizer methods
|
|
667
|
+
_CUSTOM_INSTR[None] = _CUSTOM_INSTR["automatic"] = sorted(
|
|
668
|
+
set(_CUSTOM_INSTR["statevector"])
|
|
669
|
+
.union(_CUSTOM_INSTR["stabilizer"])
|
|
670
|
+
.union(_CUSTOM_INSTR["density_matrix"])
|
|
671
|
+
.union(_CUSTOM_INSTR["matrix_product_state"])
|
|
672
|
+
.union(_CUSTOM_INSTR["unitary"])
|
|
673
|
+
.union(_CUSTOM_INSTR["superop"])
|
|
674
|
+
.union(_CUSTOM_INSTR["tensor_network"])
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
_DEFAULT_CONFIGURATION = {
|
|
678
|
+
"backend_name": "aer_simulator",
|
|
679
|
+
"backend_version": __version__,
|
|
680
|
+
"n_qubits": MAX_QUBITS_STATEVECTOR,
|
|
681
|
+
"url": "https://github.com/Qiskit/qiskit-aer",
|
|
682
|
+
"simulator": True,
|
|
683
|
+
"local": True,
|
|
684
|
+
"conditional": True,
|
|
685
|
+
"memory": True,
|
|
686
|
+
"max_shots": int(1e6),
|
|
687
|
+
"description": "A C++ Qasm simulator with noise",
|
|
688
|
+
"coupling_map": None,
|
|
689
|
+
"basis_gates": BASIS_GATES["automatic"],
|
|
690
|
+
"custom_instructions": _CUSTOM_INSTR["automatic"],
|
|
691
|
+
"gates": [],
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
_SIMULATION_METHODS = [
|
|
695
|
+
"automatic",
|
|
696
|
+
"statevector",
|
|
697
|
+
"density_matrix",
|
|
698
|
+
"stabilizer",
|
|
699
|
+
"matrix_product_state",
|
|
700
|
+
"extended_stabilizer",
|
|
701
|
+
"unitary",
|
|
702
|
+
"superop",
|
|
703
|
+
"tensor_network",
|
|
704
|
+
]
|
|
705
|
+
|
|
706
|
+
_AVAILABLE_METHODS = None
|
|
707
|
+
|
|
708
|
+
_SIMULATION_DEVICES = ("CPU", "GPU", "Thrust")
|
|
709
|
+
|
|
710
|
+
_AVAILABLE_DEVICES = None
|
|
711
|
+
|
|
712
|
+
def __init__(
|
|
713
|
+
self, configuration=None, properties=None, provider=None, target=None, **backend_options
|
|
714
|
+
):
|
|
715
|
+
self._controller = aer_controller_execute()
|
|
716
|
+
|
|
717
|
+
# Update available methods and devices for class
|
|
718
|
+
if AerSimulator._AVAILABLE_DEVICES is None:
|
|
719
|
+
AerSimulator._AVAILABLE_DEVICES = available_devices(self._controller)
|
|
720
|
+
if AerSimulator._AVAILABLE_METHODS is None:
|
|
721
|
+
AerSimulator._AVAILABLE_METHODS = available_methods(
|
|
722
|
+
AerSimulator._SIMULATION_METHODS, AerSimulator._AVAILABLE_DEVICES
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
# Default configuration
|
|
726
|
+
if configuration is None:
|
|
727
|
+
configuration = AerBackendConfiguration.from_dict(AerSimulator._DEFAULT_CONFIGURATION)
|
|
728
|
+
|
|
729
|
+
# set backend name from method and device in option
|
|
730
|
+
if "from" not in configuration.backend_name:
|
|
731
|
+
method = "automatic"
|
|
732
|
+
device = "CPU"
|
|
733
|
+
for key, value in backend_options.items():
|
|
734
|
+
if key == "method":
|
|
735
|
+
method = value
|
|
736
|
+
if key == "device":
|
|
737
|
+
device = value
|
|
738
|
+
if method not in [None, "automatic"]:
|
|
739
|
+
configuration.backend_name += f"_{method}"
|
|
740
|
+
if device not in [None, "CPU"]:
|
|
741
|
+
configuration.backend_name += f"_{device}".lower()
|
|
742
|
+
|
|
743
|
+
# Cache basis gates since computing the intersection
|
|
744
|
+
# of noise model, method, and config gates is expensive.
|
|
745
|
+
self._cached_basis_gates = self._BASIS_GATES["automatic"]
|
|
746
|
+
|
|
747
|
+
super().__init__(
|
|
748
|
+
configuration,
|
|
749
|
+
properties=properties,
|
|
750
|
+
provider=provider,
|
|
751
|
+
target=target,
|
|
752
|
+
backend_options=backend_options,
|
|
753
|
+
)
|
|
754
|
+
|
|
755
|
+
if "basis_gates" in backend_options.items():
|
|
756
|
+
self._check_basis_gates(backend_options["basis_gates"])
|
|
757
|
+
|
|
758
|
+
@classmethod
|
|
759
|
+
def _default_options(cls):
|
|
760
|
+
return Options(
|
|
761
|
+
# Global options
|
|
762
|
+
shots=1024,
|
|
763
|
+
method="automatic",
|
|
764
|
+
device="CPU",
|
|
765
|
+
precision="double",
|
|
766
|
+
executor=None,
|
|
767
|
+
max_job_size=None,
|
|
768
|
+
max_shot_size=None,
|
|
769
|
+
enable_truncation=True,
|
|
770
|
+
zero_threshold=1e-10,
|
|
771
|
+
validation_threshold=None,
|
|
772
|
+
max_parallel_threads=None,
|
|
773
|
+
max_parallel_experiments=None,
|
|
774
|
+
max_parallel_shots=None,
|
|
775
|
+
max_memory_mb=None,
|
|
776
|
+
fusion_enable=True,
|
|
777
|
+
fusion_verbose=False,
|
|
778
|
+
fusion_max_qubit=None,
|
|
779
|
+
fusion_threshold=None,
|
|
780
|
+
accept_distributed_results=None,
|
|
781
|
+
memory=None,
|
|
782
|
+
noise_model=None,
|
|
783
|
+
seed_simulator=None,
|
|
784
|
+
# cuStateVec (cuQuantum) option
|
|
785
|
+
cuStateVec_enable=False,
|
|
786
|
+
# cache blocking for multi-GPUs/MPI options
|
|
787
|
+
blocking_qubits=None,
|
|
788
|
+
blocking_enable=False,
|
|
789
|
+
chunk_swap_buffer_qubits=None,
|
|
790
|
+
# multi-shots optimization options (GPU only)
|
|
791
|
+
batched_shots_gpu=False,
|
|
792
|
+
batched_shots_gpu_max_qubits=16,
|
|
793
|
+
num_threads_per_device=1,
|
|
794
|
+
# multi-shot branching
|
|
795
|
+
shot_branching_enable=False,
|
|
796
|
+
shot_branching_sampling_enable=False,
|
|
797
|
+
# statevector options
|
|
798
|
+
statevector_parallel_threshold=14,
|
|
799
|
+
statevector_sample_measure_opt=10,
|
|
800
|
+
# stabilizer options
|
|
801
|
+
stabilizer_max_snapshot_probabilities=32,
|
|
802
|
+
# extended stabilizer options
|
|
803
|
+
extended_stabilizer_sampling_method="resampled_metropolis",
|
|
804
|
+
extended_stabilizer_metropolis_mixing_time=5000,
|
|
805
|
+
extended_stabilizer_approximation_error=0.05,
|
|
806
|
+
extended_stabilizer_norm_estimation_samples=100,
|
|
807
|
+
extended_stabilizer_norm_estimation_repetitions=3,
|
|
808
|
+
extended_stabilizer_parallel_threshold=100,
|
|
809
|
+
extended_stabilizer_probabilities_snapshot_samples=3000,
|
|
810
|
+
# MPS options
|
|
811
|
+
matrix_product_state_truncation_threshold=1e-16,
|
|
812
|
+
matrix_product_state_max_bond_dimension=None,
|
|
813
|
+
mps_sample_measure_algorithm="mps_heuristic",
|
|
814
|
+
mps_log_data=False,
|
|
815
|
+
mps_swap_direction="mps_swap_left",
|
|
816
|
+
chop_threshold=1e-8,
|
|
817
|
+
mps_parallel_threshold=14,
|
|
818
|
+
mps_omp_threads=1,
|
|
819
|
+
mps_lapack=False,
|
|
820
|
+
# tensor network options
|
|
821
|
+
tensor_network_num_sampling_qubits=10,
|
|
822
|
+
use_cuTensorNet_autotuning=False,
|
|
823
|
+
# parameter binding
|
|
824
|
+
runtime_parameter_bind_enable=False,
|
|
825
|
+
)
|
|
826
|
+
|
|
827
|
+
def __repr__(self):
|
|
828
|
+
"""String representation of an AerSimulator."""
|
|
829
|
+
display = super().__repr__()
|
|
830
|
+
noise_model = getattr(self.options, "noise_model", None)
|
|
831
|
+
if noise_model is None or noise_model.is_ideal():
|
|
832
|
+
return display
|
|
833
|
+
pad = " " * (len(self.__class__.__name__) + 1)
|
|
834
|
+
return f"{display[:-1]}\n{pad}noise_model={repr(noise_model)})"
|
|
835
|
+
|
|
836
|
+
@classmethod
|
|
837
|
+
def from_backend(cls, backend, **options):
|
|
838
|
+
"""Initialize simulator from backend."""
|
|
839
|
+
if isinstance(backend, BackendV2):
|
|
840
|
+
if backend.description is None:
|
|
841
|
+
description = "created by AerSimulator.from_backend"
|
|
842
|
+
else:
|
|
843
|
+
description = backend.description
|
|
844
|
+
|
|
845
|
+
configuration = AerBackendConfiguration(
|
|
846
|
+
backend_name=f"aer_simulator_from({backend.name})",
|
|
847
|
+
backend_version=backend.backend_version,
|
|
848
|
+
n_qubits=backend.num_qubits,
|
|
849
|
+
basis_gates=backend.operation_names,
|
|
850
|
+
gates=[],
|
|
851
|
+
max_shots=int(1e6),
|
|
852
|
+
coupling_map=list(backend.coupling_map.get_edges()),
|
|
853
|
+
max_experiments=backend.max_circuits,
|
|
854
|
+
description=description,
|
|
855
|
+
)
|
|
856
|
+
properties = target_to_backend_properties(backend.target)
|
|
857
|
+
target = backend.target
|
|
858
|
+
else:
|
|
859
|
+
raise TypeError(
|
|
860
|
+
"The backend argument requires a BackendV2 object, " f"not a {type(backend)} object"
|
|
861
|
+
)
|
|
862
|
+
# Use automatic noise model if none is provided
|
|
863
|
+
if "noise_model" not in options:
|
|
864
|
+
# pylint: disable=import-outside-toplevel
|
|
865
|
+
# Avoid cyclic import
|
|
866
|
+
from ..noise.noise_model import NoiseModel
|
|
867
|
+
|
|
868
|
+
noise_model = NoiseModel.from_backend(backend)
|
|
869
|
+
if not noise_model.is_ideal():
|
|
870
|
+
options["noise_model"] = noise_model
|
|
871
|
+
|
|
872
|
+
# Initialize simulator
|
|
873
|
+
sim = cls(configuration=configuration, properties=properties, target=target, **options)
|
|
874
|
+
return sim
|
|
875
|
+
|
|
876
|
+
def available_methods(self):
|
|
877
|
+
"""Return the available simulation methods."""
|
|
878
|
+
return copy.copy(self._AVAILABLE_METHODS)
|
|
879
|
+
|
|
880
|
+
def available_devices(self):
|
|
881
|
+
"""Return the available simulation methods."""
|
|
882
|
+
if "_gpu" in self.name:
|
|
883
|
+
return ["GPU"]
|
|
884
|
+
return copy.copy(self._AVAILABLE_DEVICES)
|
|
885
|
+
|
|
886
|
+
def configuration(self):
|
|
887
|
+
"""Return the simulator backend configuration.
|
|
888
|
+
|
|
889
|
+
Returns:
|
|
890
|
+
BackendConfiguration: the configuration for the backend.
|
|
891
|
+
"""
|
|
892
|
+
config = copy.copy(self._configuration)
|
|
893
|
+
for key, val in self._options_configuration.items():
|
|
894
|
+
setattr(config, key, val)
|
|
895
|
+
|
|
896
|
+
method = getattr(self.options, "method", "automatic")
|
|
897
|
+
|
|
898
|
+
# Update basis gates based on custom options, config, method,
|
|
899
|
+
# and noise model
|
|
900
|
+
config.custom_instructions = self._CUSTOM_INSTR[method]
|
|
901
|
+
config.basis_gates = self._cached_basis_gates + config.custom_instructions
|
|
902
|
+
return config
|
|
903
|
+
|
|
904
|
+
def _execute_circuits(self, aer_circuits, noise_model, config):
|
|
905
|
+
"""Execute circuits on the backend."""
|
|
906
|
+
ret = cpp_execute_circuits(self._controller, aer_circuits, noise_model, config)
|
|
907
|
+
return ret
|
|
908
|
+
|
|
909
|
+
def set_option(self, key, value):
|
|
910
|
+
if key == "custom_instructions":
|
|
911
|
+
self._set_configuration_option(key, value)
|
|
912
|
+
return
|
|
913
|
+
if key == "method":
|
|
914
|
+
if value is not None and value not in self.available_methods():
|
|
915
|
+
raise AerError(
|
|
916
|
+
f"Invalid simulation method {value}. Available methods"
|
|
917
|
+
f" are: {self.available_methods()}"
|
|
918
|
+
)
|
|
919
|
+
self._set_method_config(value)
|
|
920
|
+
if key == "basis_gates":
|
|
921
|
+
self._check_basis_gates(value)
|
|
922
|
+
|
|
923
|
+
super().set_option(key, value)
|
|
924
|
+
if key in ["method", "noise_model", "basis_gates"]:
|
|
925
|
+
self._cached_basis_gates = self._basis_gates()
|
|
926
|
+
|
|
927
|
+
# update backend name
|
|
928
|
+
if key in ["method", "device"]:
|
|
929
|
+
if "from" not in self.name:
|
|
930
|
+
if key == "method":
|
|
931
|
+
self.name = "aer_simulator"
|
|
932
|
+
if value != "automatic":
|
|
933
|
+
self.name += f"_{value}"
|
|
934
|
+
device = getattr(self.options, "device", "CPU")
|
|
935
|
+
if device != "CPU":
|
|
936
|
+
self.name += f"_{device}".lower()
|
|
937
|
+
if key == "device":
|
|
938
|
+
method = getattr(self.options, "method", "auto")
|
|
939
|
+
self.name = "aer_simulator"
|
|
940
|
+
if method != "automatic":
|
|
941
|
+
self.name += f"_{method}"
|
|
942
|
+
if value != "CPU":
|
|
943
|
+
self.name += f"_{value}".lower()
|
|
944
|
+
|
|
945
|
+
def _basis_gates(self):
|
|
946
|
+
"""Return simulator basis gates.
|
|
947
|
+
|
|
948
|
+
This will be the option value of basis gates if it was set,
|
|
949
|
+
otherwise it will be the intersection of the configuration, noise model
|
|
950
|
+
and method supported basis gates.
|
|
951
|
+
"""
|
|
952
|
+
# Use option value for basis gates if set
|
|
953
|
+
if "basis_gates" in self._options_configuration:
|
|
954
|
+
return self._options_configuration["basis_gates"]
|
|
955
|
+
|
|
956
|
+
# Compute intersection with method basis gates
|
|
957
|
+
method = getattr(self._options, "method", "automatic")
|
|
958
|
+
method_gates = self._BASIS_GATES[method]
|
|
959
|
+
config_gates = self._configuration.basis_gates
|
|
960
|
+
if config_gates:
|
|
961
|
+
basis_gates = set(config_gates).intersection(method_gates)
|
|
962
|
+
else:
|
|
963
|
+
basis_gates = method_gates
|
|
964
|
+
|
|
965
|
+
# Compute intersection with noise model basis gates
|
|
966
|
+
noise_model = getattr(self.options, "noise_model", None)
|
|
967
|
+
if noise_model:
|
|
968
|
+
noise_gates = noise_model.basis_gates
|
|
969
|
+
basis_gates = basis_gates.intersection(noise_gates)
|
|
970
|
+
else:
|
|
971
|
+
noise_gates = None
|
|
972
|
+
|
|
973
|
+
if not basis_gates:
|
|
974
|
+
logger.warning(
|
|
975
|
+
"The intersection of configuration basis gates (%s), "
|
|
976
|
+
"simulation method basis gates (%s), and "
|
|
977
|
+
"noise model basis gates (%s) is empty",
|
|
978
|
+
config_gates,
|
|
979
|
+
method_gates,
|
|
980
|
+
noise_gates,
|
|
981
|
+
)
|
|
982
|
+
return sorted(basis_gates)
|
|
983
|
+
|
|
984
|
+
def _set_method_config(self, method=None):
|
|
985
|
+
"""Set non-basis gate options when setting method"""
|
|
986
|
+
# Update configuration description and number of qubits
|
|
987
|
+
if method == "statevector":
|
|
988
|
+
description = "A C++ statevector simulator with noise"
|
|
989
|
+
n_qubits = MAX_QUBITS_STATEVECTOR
|
|
990
|
+
elif method == "density_matrix":
|
|
991
|
+
description = "A C++ density matrix simulator with noise"
|
|
992
|
+
n_qubits = MAX_QUBITS_STATEVECTOR // 2
|
|
993
|
+
elif method == "unitary":
|
|
994
|
+
description = "A C++ unitary matrix simulator"
|
|
995
|
+
n_qubits = MAX_QUBITS_STATEVECTOR // 2
|
|
996
|
+
elif method == "superop":
|
|
997
|
+
description = "A C++ superop matrix simulator with noise"
|
|
998
|
+
n_qubits = MAX_QUBITS_STATEVECTOR // 4
|
|
999
|
+
elif method == "matrix_product_state":
|
|
1000
|
+
description = "A C++ matrix product state simulator with noise"
|
|
1001
|
+
n_qubits = 63 # TODO: not sure what to put here?
|
|
1002
|
+
elif method == "stabilizer":
|
|
1003
|
+
description = "A C++ Clifford stabilizer simulator with noise"
|
|
1004
|
+
n_qubits = 10000 # TODO: estimate from memory
|
|
1005
|
+
elif method == "extended_stabilizer":
|
|
1006
|
+
description = "A C++ Clifford+T extended stabilizer simulator with noise"
|
|
1007
|
+
n_qubits = 63 # TODO: estimate from memory
|
|
1008
|
+
else:
|
|
1009
|
+
# Clear options to default
|
|
1010
|
+
description = None
|
|
1011
|
+
n_qubits = None
|
|
1012
|
+
|
|
1013
|
+
if self._configuration.coupling_map:
|
|
1014
|
+
n_qubits = max(list(map(max, self._configuration.coupling_map))) + 1
|
|
1015
|
+
|
|
1016
|
+
self._set_configuration_option("description", description)
|
|
1017
|
+
self._set_configuration_option("n_qubits", n_qubits)
|
|
1018
|
+
|
|
1019
|
+
def _check_basis_gates(self, basis_gates):
|
|
1020
|
+
method = getattr(self.options, "method", "automatic")
|
|
1021
|
+
# check if basis_gates contains non-supported gates
|
|
1022
|
+
if method != "automatic":
|
|
1023
|
+
for gate in basis_gates:
|
|
1024
|
+
if gate not in self._BASIS_GATES[method]:
|
|
1025
|
+
raise AerError(f"Invalid gate {gate} for simulation method {method}.")
|