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,330 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2019.
|
|
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 statevector simulator backend.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import copy
|
|
17
|
+
import logging
|
|
18
|
+
from warnings import warn
|
|
19
|
+
|
|
20
|
+
from qiskit.providers.options import Options
|
|
21
|
+
|
|
22
|
+
from ..aererror import AerError
|
|
23
|
+
from ..version import __version__
|
|
24
|
+
from .aerbackend import AerBackend
|
|
25
|
+
from .backendconfiguration import AerBackendConfiguration
|
|
26
|
+
from .backend_utils import (
|
|
27
|
+
available_devices,
|
|
28
|
+
MAX_QUBITS_STATEVECTOR,
|
|
29
|
+
LEGACY_METHOD_MAP,
|
|
30
|
+
cpp_execute_circuits,
|
|
31
|
+
map_legacy_method_config,
|
|
32
|
+
add_final_save_op,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# pylint: disable=import-error, no-name-in-module, abstract-method
|
|
36
|
+
from .controller_wrappers import aer_controller_execute
|
|
37
|
+
|
|
38
|
+
# Logger
|
|
39
|
+
logger = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class StatevectorSimulator(AerBackend):
|
|
43
|
+
"""Ideal quantum circuit statevector simulator
|
|
44
|
+
|
|
45
|
+
**Configurable Options**
|
|
46
|
+
|
|
47
|
+
The `StatevectorSimulator` supports CPU and GPU simulation methods and
|
|
48
|
+
additional configurable options. These may be set using the appropriate kwargs
|
|
49
|
+
during initialization. They can also be set of updated using the
|
|
50
|
+
:meth:`set_options` method.
|
|
51
|
+
|
|
52
|
+
Run-time options may also be specified as kwargs using the :meth:`run` method.
|
|
53
|
+
These will not be stored in the backend and will only apply to that execution.
|
|
54
|
+
They will also override any previously set options.
|
|
55
|
+
|
|
56
|
+
For example, to configure a a single-precision simulator
|
|
57
|
+
|
|
58
|
+
.. code-block:: python
|
|
59
|
+
|
|
60
|
+
backend = StatevectorSimulator(precision='single')
|
|
61
|
+
|
|
62
|
+
**Backend Options**
|
|
63
|
+
|
|
64
|
+
The following configurable backend options are supported
|
|
65
|
+
|
|
66
|
+
* ``device`` (str): Set the simulation device (Default: ``"CPU"``).
|
|
67
|
+
Use :meth:`available_devices` to return a list of devices supported
|
|
68
|
+
on the current system.
|
|
69
|
+
|
|
70
|
+
* ``method`` (str): [DEPRECATED] Set the simulation method supported
|
|
71
|
+
methods are ``"statevector"`` for CPU simulation, and
|
|
72
|
+
``"statevector_gpu"`` for GPU simulation. This option has been
|
|
73
|
+
deprecated, use the ``device`` option to set "CPU" or "GPU"
|
|
74
|
+
simulation instead.
|
|
75
|
+
|
|
76
|
+
* ``precision`` (str): Set the floating point precision for
|
|
77
|
+
certain simulation methods to either ``"single"`` or ``"double"``
|
|
78
|
+
precision (default: ``"double"``).
|
|
79
|
+
|
|
80
|
+
* ``executor`` (futures.Executor): Set a custom executor for
|
|
81
|
+
asynchronous running of simulation jobs (Default: None).
|
|
82
|
+
|
|
83
|
+
* ``max_job_size`` (int or None): If the number of run circuits
|
|
84
|
+
exceeds this value simulation will be run as a set of of sub-jobs
|
|
85
|
+
on the executor. If ``None`` simulation of all circuits aer submitted
|
|
86
|
+
to the executor as a single job (Default: None).
|
|
87
|
+
|
|
88
|
+
* ``max_shot_size`` (int or None): If the number of shots of a noisy
|
|
89
|
+
circuit exceeds this value simulation will be split into multi
|
|
90
|
+
circuits for execution and the results accumulated. If ``None``
|
|
91
|
+
circuits will not be split based on shots. When splitting circuits
|
|
92
|
+
use the ``max_job_size`` option to control how these split circuits
|
|
93
|
+
should be submitted to the executor (Default: None).
|
|
94
|
+
|
|
95
|
+
* ``zero_threshold`` (double): Sets the threshold for truncating
|
|
96
|
+
small values to zero in the result data (Default: 1e-10).
|
|
97
|
+
|
|
98
|
+
* ``validation_threshold`` (double): Sets the threshold for checking
|
|
99
|
+
if the initial statevector is valid (Default: 1e-8).
|
|
100
|
+
|
|
101
|
+
* ``max_parallel_threads`` (int): Sets the maximum number of CPU
|
|
102
|
+
cores used by OpenMP for parallelization. If set to 0 the
|
|
103
|
+
maximum will be set to the number of CPU cores (Default: 0).
|
|
104
|
+
|
|
105
|
+
* ``max_parallel_experiments`` (int): Sets the maximum number of
|
|
106
|
+
experiments that may be executed in parallel up to the
|
|
107
|
+
max_parallel_threads value. If set to 1 parallel circuit
|
|
108
|
+
execution will be disabled. If set to 0 the maximum will be
|
|
109
|
+
automatically set to max_parallel_threads (Default: 1).
|
|
110
|
+
|
|
111
|
+
* ``max_memory_mb`` (int): Sets the maximum size of memory
|
|
112
|
+
to store a state vector. If a state vector needs more, an error
|
|
113
|
+
is thrown. In general, a state vector of n-qubits uses 2^n complex
|
|
114
|
+
values (16 Bytes). If set to 0, the maximum will be automatically
|
|
115
|
+
set to the system memory size (Default: 0).
|
|
116
|
+
|
|
117
|
+
* ``statevector_parallel_threshold`` (int): Sets the threshold that
|
|
118
|
+
"n_qubits" must be greater than to enable OpenMP
|
|
119
|
+
parallelization for matrix multiplication during execution of
|
|
120
|
+
an experiment. If parallel circuit or shot execution is enabled
|
|
121
|
+
this will only use unallocated CPU cores up to
|
|
122
|
+
max_parallel_threads. Note that setting this too low can reduce
|
|
123
|
+
performance (Default: 14).
|
|
124
|
+
|
|
125
|
+
These backend options apply in circuit optimization passes:
|
|
126
|
+
|
|
127
|
+
* ``fusion_enable`` (bool): Enable fusion optimization in circuit
|
|
128
|
+
optimization passes [Default: True]
|
|
129
|
+
* ``fusion_verbose`` (bool): Output gates generated in fusion optimization
|
|
130
|
+
into metadata [Default: False]
|
|
131
|
+
* ``fusion_max_qubit`` (int): Maximum number of qubits for a operation generated
|
|
132
|
+
in a fusion optimization [Default: 5]
|
|
133
|
+
* ``fusion_threshold`` (int): Threshold that number of qubits must be greater
|
|
134
|
+
than or equal to enable fusion optimization [Default: 14]
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
_DEFAULT_CONFIGURATION = {
|
|
138
|
+
"backend_name": "statevector_simulator",
|
|
139
|
+
"backend_version": __version__,
|
|
140
|
+
"n_qubits": MAX_QUBITS_STATEVECTOR,
|
|
141
|
+
"url": "https://github.com/Qiskit/qiskit-aer",
|
|
142
|
+
"simulator": True,
|
|
143
|
+
"local": True,
|
|
144
|
+
"conditional": True,
|
|
145
|
+
"open_pulse": False,
|
|
146
|
+
"memory": True,
|
|
147
|
+
"max_shots": int(1e6), # Note that this backend will only ever
|
|
148
|
+
# perform a single shot. This value is just
|
|
149
|
+
# so that the default shot value for execute
|
|
150
|
+
# will not raise an error when trying to run
|
|
151
|
+
# a simulation
|
|
152
|
+
"description": "A C++ statevector circuit simulator",
|
|
153
|
+
"coupling_map": None,
|
|
154
|
+
"basis_gates": sorted(
|
|
155
|
+
[
|
|
156
|
+
"u1",
|
|
157
|
+
"u2",
|
|
158
|
+
"u3",
|
|
159
|
+
"u",
|
|
160
|
+
"p",
|
|
161
|
+
"r",
|
|
162
|
+
"rx",
|
|
163
|
+
"ry",
|
|
164
|
+
"rz",
|
|
165
|
+
"id",
|
|
166
|
+
"x",
|
|
167
|
+
"y",
|
|
168
|
+
"z",
|
|
169
|
+
"h",
|
|
170
|
+
"s",
|
|
171
|
+
"sdg",
|
|
172
|
+
"sx",
|
|
173
|
+
"sxdg",
|
|
174
|
+
"t",
|
|
175
|
+
"tdg",
|
|
176
|
+
"swap",
|
|
177
|
+
"cx",
|
|
178
|
+
"cy",
|
|
179
|
+
"cz",
|
|
180
|
+
"csx",
|
|
181
|
+
"cu",
|
|
182
|
+
"cp",
|
|
183
|
+
"cu1",
|
|
184
|
+
"cu2",
|
|
185
|
+
"cu3",
|
|
186
|
+
"rxx",
|
|
187
|
+
"ryy",
|
|
188
|
+
"rzz",
|
|
189
|
+
"rzx",
|
|
190
|
+
"ccx",
|
|
191
|
+
"ccz",
|
|
192
|
+
"cswap",
|
|
193
|
+
"mcx",
|
|
194
|
+
"mcy",
|
|
195
|
+
"mcz",
|
|
196
|
+
"mcsx",
|
|
197
|
+
"mcu",
|
|
198
|
+
"mcp",
|
|
199
|
+
"mcphase",
|
|
200
|
+
"mcu1",
|
|
201
|
+
"mcu2",
|
|
202
|
+
"mcu3",
|
|
203
|
+
"mcrx",
|
|
204
|
+
"mcry",
|
|
205
|
+
"mcrz",
|
|
206
|
+
"mcr",
|
|
207
|
+
"mcswap",
|
|
208
|
+
"unitary",
|
|
209
|
+
"diagonal",
|
|
210
|
+
"multiplexer",
|
|
211
|
+
"initialize",
|
|
212
|
+
"delay",
|
|
213
|
+
"pauli",
|
|
214
|
+
]
|
|
215
|
+
),
|
|
216
|
+
"custom_instructions": sorted(
|
|
217
|
+
[
|
|
218
|
+
"kraus",
|
|
219
|
+
"roerror",
|
|
220
|
+
"quantum_channel",
|
|
221
|
+
"qerror_loc",
|
|
222
|
+
"save_expval",
|
|
223
|
+
"save_density_matrix",
|
|
224
|
+
"save_statevector",
|
|
225
|
+
"save_probs",
|
|
226
|
+
"save_probs_ket",
|
|
227
|
+
"save_amplitudes",
|
|
228
|
+
"save_amplitudes_sq",
|
|
229
|
+
"save_state",
|
|
230
|
+
"set_statevector",
|
|
231
|
+
"reset",
|
|
232
|
+
]
|
|
233
|
+
),
|
|
234
|
+
"gates": [],
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
_SIMULATION_DEVICES = ("CPU", "GPU", "Thrust")
|
|
238
|
+
|
|
239
|
+
_AVAILABLE_DEVICES = None
|
|
240
|
+
|
|
241
|
+
def __init__(self, configuration=None, properties=None, provider=None, **backend_options):
|
|
242
|
+
warn(
|
|
243
|
+
"The `StatevectorSimulator` backend will be deprecated in the"
|
|
244
|
+
" future. It has been superseded by the `AerSimulator`"
|
|
245
|
+
" backend. To obtain legacy functionality initialize with"
|
|
246
|
+
' `AerSimulator(method="statevector")` and append run circuits'
|
|
247
|
+
" with the `save_state` instruction.",
|
|
248
|
+
PendingDeprecationWarning,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
self._controller = aer_controller_execute()
|
|
252
|
+
|
|
253
|
+
if StatevectorSimulator._AVAILABLE_DEVICES is None:
|
|
254
|
+
StatevectorSimulator._AVAILABLE_DEVICES = available_devices(self._controller)
|
|
255
|
+
|
|
256
|
+
if configuration is None:
|
|
257
|
+
configuration = AerBackendConfiguration.from_dict(
|
|
258
|
+
StatevectorSimulator._DEFAULT_CONFIGURATION
|
|
259
|
+
)
|
|
260
|
+
else:
|
|
261
|
+
configuration.open_pulse = False
|
|
262
|
+
|
|
263
|
+
super().__init__(
|
|
264
|
+
configuration, properties=properties, provider=provider, backend_options=backend_options
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
@classmethod
|
|
268
|
+
def _default_options(cls):
|
|
269
|
+
return Options(
|
|
270
|
+
# Global options
|
|
271
|
+
shots=1,
|
|
272
|
+
device="CPU",
|
|
273
|
+
precision="double",
|
|
274
|
+
executor=None,
|
|
275
|
+
max_job_size=None,
|
|
276
|
+
max_shot_size=None,
|
|
277
|
+
zero_threshold=1e-10,
|
|
278
|
+
validation_threshold=None,
|
|
279
|
+
max_parallel_threads=None,
|
|
280
|
+
max_parallel_experiments=None,
|
|
281
|
+
max_parallel_shots=None,
|
|
282
|
+
max_memory_mb=None,
|
|
283
|
+
seed_simulator=None,
|
|
284
|
+
fusion_enable=True,
|
|
285
|
+
fusion_verbose=False,
|
|
286
|
+
fusion_max_qubit=5,
|
|
287
|
+
fusion_threshold=14,
|
|
288
|
+
# statevector options
|
|
289
|
+
statevector_parallel_threshold=14,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
def set_option(self, key, value):
|
|
293
|
+
if key == "method":
|
|
294
|
+
# Handle deprecation of method option for device option
|
|
295
|
+
warn(
|
|
296
|
+
"The method option of the `StatevectorSimulator` has been"
|
|
297
|
+
" deprecated as of qiskit-aer 0.9.0. To run a GPU statevector"
|
|
298
|
+
" simulation use the option `device='GPU'` instead",
|
|
299
|
+
DeprecationWarning,
|
|
300
|
+
)
|
|
301
|
+
if value in LEGACY_METHOD_MAP:
|
|
302
|
+
value, device = LEGACY_METHOD_MAP[value]
|
|
303
|
+
self.set_option("device", device)
|
|
304
|
+
if value != "statevector":
|
|
305
|
+
raise AerError(
|
|
306
|
+
"only the 'statevector' method is supported for the StatevectorSimulator"
|
|
307
|
+
)
|
|
308
|
+
return
|
|
309
|
+
super().set_option(key, value)
|
|
310
|
+
|
|
311
|
+
def available_methods(self):
|
|
312
|
+
"""Return the available simulation methods."""
|
|
313
|
+
warn(
|
|
314
|
+
"The `available_methods` method of the StatevectorSimulator"
|
|
315
|
+
" is deprecated as of qiskit-aer 0.9.0 as this simulator only"
|
|
316
|
+
" supports a single method. To check if GPU simulation is available"
|
|
317
|
+
" use the `available_devices` method instead.",
|
|
318
|
+
DeprecationWarning,
|
|
319
|
+
)
|
|
320
|
+
return ("statevector",)
|
|
321
|
+
|
|
322
|
+
def available_devices(self):
|
|
323
|
+
"""Return the available simulation methods."""
|
|
324
|
+
return copy.copy(self._AVAILABLE_DEVICES)
|
|
325
|
+
|
|
326
|
+
def _execute_circuits(self, aer_circuits, noise_model, config):
|
|
327
|
+
"""Execute circuits on the backend."""
|
|
328
|
+
config = map_legacy_method_config(config)
|
|
329
|
+
aer_circuits = add_final_save_op(aer_circuits, "statevector")
|
|
330
|
+
return cpp_execute_circuits(self._controller, aer_circuits, noise_model, config)
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# This code is part of Qiskit.
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright IBM 2018, 2019.
|
|
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
|
+
# pylint: disable=invalid-name
|
|
14
|
+
"""
|
|
15
|
+
Aer Unitary Simulator Backend.
|
|
16
|
+
"""
|
|
17
|
+
import copy
|
|
18
|
+
import logging
|
|
19
|
+
from warnings import warn
|
|
20
|
+
|
|
21
|
+
from qiskit.providers.options import Options
|
|
22
|
+
|
|
23
|
+
from ..aererror import AerError
|
|
24
|
+
from ..version import __version__
|
|
25
|
+
from .aerbackend import AerBackend
|
|
26
|
+
from .backend_utils import (
|
|
27
|
+
cpp_execute_circuits,
|
|
28
|
+
available_devices,
|
|
29
|
+
MAX_QUBITS_STATEVECTOR,
|
|
30
|
+
LEGACY_METHOD_MAP,
|
|
31
|
+
add_final_save_op,
|
|
32
|
+
map_legacy_method_config,
|
|
33
|
+
)
|
|
34
|
+
from .backendconfiguration import AerBackendConfiguration
|
|
35
|
+
|
|
36
|
+
# pylint: disable=import-error, no-name-in-module, abstract-method
|
|
37
|
+
from .controller_wrappers import aer_controller_execute
|
|
38
|
+
|
|
39
|
+
# Logger
|
|
40
|
+
logger = logging.getLogger(__name__)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class UnitarySimulator(AerBackend):
|
|
44
|
+
"""Ideal quantum circuit unitary simulator.
|
|
45
|
+
|
|
46
|
+
**Configurable Options**
|
|
47
|
+
|
|
48
|
+
The `UnitarySimulator` supports CPU and GPU simulation methods and
|
|
49
|
+
additional configurable options. These may be set using the appropriate kwargs
|
|
50
|
+
during initialization. They can also be set of updated using the
|
|
51
|
+
:meth:`set_options` method.
|
|
52
|
+
|
|
53
|
+
Run-time options may also be specified as kwargs using the :meth:`run` method.
|
|
54
|
+
These will not be stored in the backend and will only apply to that execution.
|
|
55
|
+
They will also override any previously set options.
|
|
56
|
+
|
|
57
|
+
For example, to configure a a single-precision simulator
|
|
58
|
+
|
|
59
|
+
.. code-block:: python
|
|
60
|
+
|
|
61
|
+
backend = UnitarySimulator(precision='single')
|
|
62
|
+
|
|
63
|
+
**Backend Options**
|
|
64
|
+
|
|
65
|
+
The following configurable backend options are supported
|
|
66
|
+
|
|
67
|
+
* ``device`` (str): Set the simulation device (Default: ``"CPU"``).
|
|
68
|
+
Use :meth:`available_devices` to return a list of devices supported
|
|
69
|
+
on the current system.
|
|
70
|
+
|
|
71
|
+
* ``method`` (str): [DEPRECATED] Set the simulation method supported
|
|
72
|
+
methods are ``"unitary"`` for CPU simulation, and
|
|
73
|
+
``"unitary_gpu"`` for GPU simulation. This option has been
|
|
74
|
+
deprecated, use the ``device`` option to set "CPU" or "GPU"
|
|
75
|
+
simulation instead.
|
|
76
|
+
|
|
77
|
+
* ``precision`` (str): Set the floating point precision for
|
|
78
|
+
certain simulation methods to either ``"single"`` or ``"double"``
|
|
79
|
+
precision (default: ``"double"``).
|
|
80
|
+
|
|
81
|
+
* ``executor`` (futures.Executor): Set a custom executor for
|
|
82
|
+
asynchronous running of simulation jobs (Default: None).
|
|
83
|
+
|
|
84
|
+
* ``max_shot_size`` (int or None): If the number of shots of a noisy
|
|
85
|
+
circuit exceeds this value simulation will be split into multi
|
|
86
|
+
circuits for execution and the results accumulated. If ``None``
|
|
87
|
+
circuits will not be split based on shots. When splitting circuits
|
|
88
|
+
use the ``max_job_size`` option to control how these split circuits
|
|
89
|
+
should be submitted to the executor (Default: None).
|
|
90
|
+
|
|
91
|
+
* ``max_shot_size`` (int or None): If the number of shots with
|
|
92
|
+
a noise model exceeds this value, simulation will split the experiments into
|
|
93
|
+
sub experiments. If ``None`` simulator does nothing (Default: None).
|
|
94
|
+
|
|
95
|
+
* ``"initial_unitary"`` (matrix_like): Sets a custom initial unitary
|
|
96
|
+
matrix for the simulation instead of identity (Default: None).
|
|
97
|
+
|
|
98
|
+
* ``"validation_threshold"`` (double): Sets the threshold for checking
|
|
99
|
+
if initial unitary and target unitary are unitary matrices.
|
|
100
|
+
(Default: 1e-8).
|
|
101
|
+
|
|
102
|
+
* ``"zero_threshold"`` (double): Sets the threshold for truncating
|
|
103
|
+
small values to zero in the result data (Default: 1e-10).
|
|
104
|
+
|
|
105
|
+
* ``"max_parallel_threads"`` (int): Sets the maximum number of CPU
|
|
106
|
+
cores used by OpenMP for parallelization. If set to 0 the
|
|
107
|
+
maximum will be set to the number of CPU cores (Default: 0).
|
|
108
|
+
|
|
109
|
+
* ``"max_parallel_experiments"`` (int): Sets the maximum number of
|
|
110
|
+
experiments that may be executed in parallel up to the
|
|
111
|
+
max_parallel_threads value. If set to 1 parallel circuit
|
|
112
|
+
execution will be disabled. If set to 0 the maximum will be
|
|
113
|
+
automatically set to max_parallel_threads (Default: 1).
|
|
114
|
+
|
|
115
|
+
* ``"max_memory_mb"`` (int): Sets the maximum size of memory
|
|
116
|
+
to store a state vector. If a state vector needs more, an error
|
|
117
|
+
is thrown. In general, a state vector of n-qubits uses 2^n complex
|
|
118
|
+
values (16 Bytes). If set to 0, the maximum will be automatically
|
|
119
|
+
set to the system memory size (Default: 0).
|
|
120
|
+
|
|
121
|
+
* ``"statevector_parallel_threshold"`` (int): Sets the threshold that
|
|
122
|
+
2 * "n_qubits" must be greater than to enable OpenMP
|
|
123
|
+
parallelization for matrix multiplication during execution of
|
|
124
|
+
an experiment. If parallel circuit or shot execution is enabled
|
|
125
|
+
this will only use unallocated CPU cores up to
|
|
126
|
+
max_parallel_threads. Note that setting this too low can reduce
|
|
127
|
+
performance (Default: 14).
|
|
128
|
+
|
|
129
|
+
These backend options apply in circuit optimization passes:
|
|
130
|
+
|
|
131
|
+
* ``fusion_enable`` (bool): Enable fusion optimization in circuit
|
|
132
|
+
optimization passes [Default: True]
|
|
133
|
+
* ``fusion_verbose`` (bool): Output gates generated in fusion optimization
|
|
134
|
+
into metadata [Default: False]
|
|
135
|
+
* ``fusion_max_qubit`` (int): Maximum number of qubits for a operation generated
|
|
136
|
+
in a fusion optimization [Default: 5]
|
|
137
|
+
* ``fusion_threshold`` (int): Threshold that number of qubits must be greater
|
|
138
|
+
than or equal to enable fusion optimization [Default: 7]
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
_DEFAULT_CONFIGURATION = {
|
|
142
|
+
"backend_name": "unitary_simulator",
|
|
143
|
+
"backend_version": __version__,
|
|
144
|
+
"n_qubits": MAX_QUBITS_STATEVECTOR // 2,
|
|
145
|
+
"url": "https://github.com/Qiskit/qiskit-aer",
|
|
146
|
+
"simulator": True,
|
|
147
|
+
"local": True,
|
|
148
|
+
"conditional": False,
|
|
149
|
+
"open_pulse": False,
|
|
150
|
+
"memory": False,
|
|
151
|
+
"max_shots": int(1e6), # Note that this backend will only ever
|
|
152
|
+
# perform a single shot. This value is just
|
|
153
|
+
# so that the default shot value for execute
|
|
154
|
+
# will not raise an error when trying to run
|
|
155
|
+
# a simulation
|
|
156
|
+
"description": "A C++ unitary circuit simulator",
|
|
157
|
+
"coupling_map": None,
|
|
158
|
+
"basis_gates": sorted(
|
|
159
|
+
[
|
|
160
|
+
"u1",
|
|
161
|
+
"u2",
|
|
162
|
+
"u3",
|
|
163
|
+
"u",
|
|
164
|
+
"p",
|
|
165
|
+
"r",
|
|
166
|
+
"rx",
|
|
167
|
+
"ry",
|
|
168
|
+
"rz",
|
|
169
|
+
"id",
|
|
170
|
+
"x",
|
|
171
|
+
"y",
|
|
172
|
+
"z",
|
|
173
|
+
"h",
|
|
174
|
+
"s",
|
|
175
|
+
"sdg",
|
|
176
|
+
"sx",
|
|
177
|
+
"sxdg",
|
|
178
|
+
"t",
|
|
179
|
+
"tdg",
|
|
180
|
+
"swap",
|
|
181
|
+
"cx",
|
|
182
|
+
"cy",
|
|
183
|
+
"cz",
|
|
184
|
+
"csx",
|
|
185
|
+
"cu",
|
|
186
|
+
"cp",
|
|
187
|
+
"cu1",
|
|
188
|
+
"cu2",
|
|
189
|
+
"cu3",
|
|
190
|
+
"rxx",
|
|
191
|
+
"ryy",
|
|
192
|
+
"rzz",
|
|
193
|
+
"rzx",
|
|
194
|
+
"ccx",
|
|
195
|
+
"ccz",
|
|
196
|
+
"cswap",
|
|
197
|
+
"mcx",
|
|
198
|
+
"mcy",
|
|
199
|
+
"mcz",
|
|
200
|
+
"mcsx",
|
|
201
|
+
"mcu",
|
|
202
|
+
"mcp",
|
|
203
|
+
"mcphase",
|
|
204
|
+
"mcu1",
|
|
205
|
+
"mcu2",
|
|
206
|
+
"mcu3",
|
|
207
|
+
"mcrx",
|
|
208
|
+
"mcry",
|
|
209
|
+
"mcrz",
|
|
210
|
+
"mcr",
|
|
211
|
+
"mcswap",
|
|
212
|
+
"unitary",
|
|
213
|
+
"diagonal",
|
|
214
|
+
"multiplexer",
|
|
215
|
+
"delay",
|
|
216
|
+
"pauli",
|
|
217
|
+
]
|
|
218
|
+
),
|
|
219
|
+
"custom_instructions": sorted(["save_unitary", "save_state", "set_unitary", "reset"]),
|
|
220
|
+
"gates": [],
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
_SIMULATION_DEVICES = ("CPU", "GPU", "Thrust")
|
|
224
|
+
|
|
225
|
+
_AVAILABLE_DEVICES = None
|
|
226
|
+
|
|
227
|
+
def __init__(self, configuration=None, properties=None, provider=None, **backend_options):
|
|
228
|
+
warn(
|
|
229
|
+
"The `UnitarySimulator` backend will be deprecated in the"
|
|
230
|
+
" future. It has been superseded by the `AerSimulator`"
|
|
231
|
+
" backend. To obtain legacy functionality initialize with"
|
|
232
|
+
' `AerSimulator(method="unitary")` and append run circuits'
|
|
233
|
+
" with the `save_state` instruction.",
|
|
234
|
+
PendingDeprecationWarning,
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
self._controller = aer_controller_execute()
|
|
238
|
+
|
|
239
|
+
if UnitarySimulator._AVAILABLE_DEVICES is None:
|
|
240
|
+
UnitarySimulator._AVAILABLE_DEVICES = available_devices(self._controller)
|
|
241
|
+
|
|
242
|
+
if configuration is None:
|
|
243
|
+
configuration = AerBackendConfiguration.from_dict(
|
|
244
|
+
UnitarySimulator._DEFAULT_CONFIGURATION
|
|
245
|
+
)
|
|
246
|
+
else:
|
|
247
|
+
configuration.open_pulse = False
|
|
248
|
+
|
|
249
|
+
super().__init__(
|
|
250
|
+
configuration, properties=properties, provider=provider, backend_options=backend_options
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
@classmethod
|
|
254
|
+
def _default_options(cls):
|
|
255
|
+
return Options(
|
|
256
|
+
# Global options
|
|
257
|
+
shots=1,
|
|
258
|
+
device="CPU",
|
|
259
|
+
precision="double",
|
|
260
|
+
executor=None,
|
|
261
|
+
max_job_size=None,
|
|
262
|
+
max_shot_size=None,
|
|
263
|
+
zero_threshold=1e-10,
|
|
264
|
+
seed_simulator=None,
|
|
265
|
+
validation_threshold=None,
|
|
266
|
+
max_parallel_threads=None,
|
|
267
|
+
max_parallel_experiments=None,
|
|
268
|
+
max_parallel_shots=None,
|
|
269
|
+
max_memory_mb=None,
|
|
270
|
+
fusion_enable=True,
|
|
271
|
+
fusion_verbose=False,
|
|
272
|
+
fusion_max_qubit=5,
|
|
273
|
+
fusion_threshold=14,
|
|
274
|
+
blocking_qubits=None,
|
|
275
|
+
blocking_enable=False,
|
|
276
|
+
# statevector options
|
|
277
|
+
statevector_parallel_threshold=14,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
def set_option(self, key, value):
|
|
281
|
+
if key == "method":
|
|
282
|
+
# Handle deprecation of method option for device option
|
|
283
|
+
warn(
|
|
284
|
+
"The method option of the `UnitarySimulator` has been"
|
|
285
|
+
" deprecated as of qiskit-aer 0.9.0. To run a GPU statevector"
|
|
286
|
+
" simulation use the option `device='GPU'` instead",
|
|
287
|
+
DeprecationWarning,
|
|
288
|
+
)
|
|
289
|
+
if value in LEGACY_METHOD_MAP:
|
|
290
|
+
value, device = LEGACY_METHOD_MAP[value]
|
|
291
|
+
self.set_option("device", device)
|
|
292
|
+
if value != "unitary":
|
|
293
|
+
raise AerError("only the 'unitary' method is supported for the UnitarySimulator")
|
|
294
|
+
return
|
|
295
|
+
super().set_option(key, value)
|
|
296
|
+
|
|
297
|
+
def available_methods(self):
|
|
298
|
+
"""Return the available simulation methods."""
|
|
299
|
+
warn(
|
|
300
|
+
"The `available_methods` method of the UnitarySimulator"
|
|
301
|
+
" is deprecated as of qiskit-aer 0.9.0 as this simulator only"
|
|
302
|
+
" supports a single method. To check if GPU simulation is available"
|
|
303
|
+
" use the `available_devices` method instead.",
|
|
304
|
+
DeprecationWarning,
|
|
305
|
+
)
|
|
306
|
+
return ("unitary",)
|
|
307
|
+
|
|
308
|
+
def available_devices(self):
|
|
309
|
+
"""Return the available simulation methods."""
|
|
310
|
+
return copy.copy(self._AVAILABLE_DEVICES)
|
|
311
|
+
|
|
312
|
+
def _execute_circuits(self, aer_circuits, noise_model, config):
|
|
313
|
+
"""Execute circuits on the backend."""
|
|
314
|
+
config = map_legacy_method_config(config)
|
|
315
|
+
aer_circuits = add_final_save_op(aer_circuits, "unitary")
|
|
316
|
+
return cpp_execute_circuits(self._controller, aer_circuits, noise_model, config)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# This code is part of Qiskit.
|
|
4
|
+
#
|
|
5
|
+
# (C) Copyright IBM 2018, 2019.
|
|
6
|
+
#
|
|
7
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
|
8
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
9
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
|
10
|
+
#
|
|
11
|
+
# Any modifications or derivative works of this code must retain this
|
|
12
|
+
# copyright notice, and modified files need to carry a notice indicating
|
|
13
|
+
# that they have been altered from the originals.
|
|
14
|
+
"""
|
|
15
|
+
================================================
|
|
16
|
+
Aer Jobs (:mod:`qiskit_aer.jobs`)
|
|
17
|
+
================================================
|
|
18
|
+
|
|
19
|
+
.. currentmodule:: qiskit_aer.jobs
|
|
20
|
+
|
|
21
|
+
This module contains classes and functions to manage Aer jobs.
|
|
22
|
+
|
|
23
|
+
Classes
|
|
24
|
+
=======
|
|
25
|
+
|
|
26
|
+
The following are the classes used to manage job submissions.
|
|
27
|
+
|
|
28
|
+
.. autosummary::
|
|
29
|
+
:toctree: ../stubs/
|
|
30
|
+
|
|
31
|
+
AerJob
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from .aerjob import AerJob
|