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.
Files changed (83) hide show
  1. qiskit_aer/VERSION.txt +1 -0
  2. qiskit_aer/__init__.py +89 -0
  3. qiskit_aer/aererror.py +30 -0
  4. qiskit_aer/aerprovider.py +119 -0
  5. qiskit_aer/backends/__init__.py +20 -0
  6. qiskit_aer/backends/aer_compiler.py +1085 -0
  7. qiskit_aer/backends/aer_simulator.py +1025 -0
  8. qiskit_aer/backends/aerbackend.py +679 -0
  9. qiskit_aer/backends/backend_utils.py +567 -0
  10. qiskit_aer/backends/backendconfiguration.py +395 -0
  11. qiskit_aer/backends/backendproperties.py +590 -0
  12. qiskit_aer/backends/compatibility.py +287 -0
  13. qiskit_aer/backends/controller_wrappers.cp314-win_amd64.pyd +0 -0
  14. qiskit_aer/backends/libopenblas.dll +0 -0
  15. qiskit_aer/backends/name_mapping.py +306 -0
  16. qiskit_aer/backends/qasm_simulator.py +925 -0
  17. qiskit_aer/backends/statevector_simulator.py +330 -0
  18. qiskit_aer/backends/unitary_simulator.py +316 -0
  19. qiskit_aer/jobs/__init__.py +35 -0
  20. qiskit_aer/jobs/aerjob.py +143 -0
  21. qiskit_aer/jobs/utils.py +66 -0
  22. qiskit_aer/library/__init__.py +204 -0
  23. qiskit_aer/library/control_flow_instructions/__init__.py +16 -0
  24. qiskit_aer/library/control_flow_instructions/jump.py +47 -0
  25. qiskit_aer/library/control_flow_instructions/mark.py +30 -0
  26. qiskit_aer/library/control_flow_instructions/store.py +29 -0
  27. qiskit_aer/library/default_qubits.py +44 -0
  28. qiskit_aer/library/instructions_table.csv +21 -0
  29. qiskit_aer/library/save_instructions/__init__.py +44 -0
  30. qiskit_aer/library/save_instructions/save_amplitudes.py +168 -0
  31. qiskit_aer/library/save_instructions/save_clifford.py +63 -0
  32. qiskit_aer/library/save_instructions/save_data.py +129 -0
  33. qiskit_aer/library/save_instructions/save_density_matrix.py +91 -0
  34. qiskit_aer/library/save_instructions/save_expectation_value.py +257 -0
  35. qiskit_aer/library/save_instructions/save_matrix_product_state.py +71 -0
  36. qiskit_aer/library/save_instructions/save_probabilities.py +156 -0
  37. qiskit_aer/library/save_instructions/save_stabilizer.py +70 -0
  38. qiskit_aer/library/save_instructions/save_state.py +79 -0
  39. qiskit_aer/library/save_instructions/save_statevector.py +120 -0
  40. qiskit_aer/library/save_instructions/save_superop.py +62 -0
  41. qiskit_aer/library/save_instructions/save_unitary.py +63 -0
  42. qiskit_aer/library/set_instructions/__init__.py +19 -0
  43. qiskit_aer/library/set_instructions/set_density_matrix.py +78 -0
  44. qiskit_aer/library/set_instructions/set_matrix_product_state.py +83 -0
  45. qiskit_aer/library/set_instructions/set_stabilizer.py +77 -0
  46. qiskit_aer/library/set_instructions/set_statevector.py +78 -0
  47. qiskit_aer/library/set_instructions/set_superop.py +78 -0
  48. qiskit_aer/library/set_instructions/set_unitary.py +78 -0
  49. qiskit_aer/noise/__init__.py +265 -0
  50. qiskit_aer/noise/device/__init__.py +25 -0
  51. qiskit_aer/noise/device/models.py +397 -0
  52. qiskit_aer/noise/device/parameters.py +202 -0
  53. qiskit_aer/noise/errors/__init__.py +30 -0
  54. qiskit_aer/noise/errors/base_quantum_error.py +119 -0
  55. qiskit_aer/noise/errors/pauli_error.py +283 -0
  56. qiskit_aer/noise/errors/pauli_lindblad_error.py +363 -0
  57. qiskit_aer/noise/errors/quantum_error.py +451 -0
  58. qiskit_aer/noise/errors/readout_error.py +355 -0
  59. qiskit_aer/noise/errors/standard_errors.py +498 -0
  60. qiskit_aer/noise/noise_model.py +1231 -0
  61. qiskit_aer/noise/noiseerror.py +30 -0
  62. qiskit_aer/noise/passes/__init__.py +18 -0
  63. qiskit_aer/noise/passes/local_noise_pass.py +160 -0
  64. qiskit_aer/noise/passes/relaxation_noise_pass.py +137 -0
  65. qiskit_aer/primitives/__init__.py +44 -0
  66. qiskit_aer/primitives/estimator.py +751 -0
  67. qiskit_aer/primitives/estimator_v2.py +159 -0
  68. qiskit_aer/primitives/sampler.py +361 -0
  69. qiskit_aer/primitives/sampler_v2.py +256 -0
  70. qiskit_aer/quantum_info/__init__.py +32 -0
  71. qiskit_aer/quantum_info/states/__init__.py +16 -0
  72. qiskit_aer/quantum_info/states/aer_densitymatrix.py +313 -0
  73. qiskit_aer/quantum_info/states/aer_state.py +525 -0
  74. qiskit_aer/quantum_info/states/aer_statevector.py +302 -0
  75. qiskit_aer/utils/__init__.py +44 -0
  76. qiskit_aer/utils/noise_model_inserter.py +66 -0
  77. qiskit_aer/utils/noise_transformation.py +431 -0
  78. qiskit_aer/version.py +86 -0
  79. qiskit_aer-0.17.2.dist-info/METADATA +209 -0
  80. qiskit_aer-0.17.2.dist-info/RECORD +83 -0
  81. qiskit_aer-0.17.2.dist-info/WHEEL +5 -0
  82. qiskit_aer-0.17.2.dist-info/licenses/LICENSE.txt +203 -0
  83. qiskit_aer-0.17.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,355 @@
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
+ Readout error class for Aer noise model.
14
+ """
15
+
16
+ import copy
17
+
18
+ import numpy as np
19
+ from numpy.linalg import norm
20
+ from qiskit.circuit import Instruction
21
+ from qiskit.quantum_info.operators.predicates import ATOL_DEFAULT, RTOL_DEFAULT
22
+
23
+ from ..noiseerror import NoiseError
24
+
25
+
26
+ class ReadoutError:
27
+ """
28
+ Readout error class for Aer noise model.
29
+ """
30
+
31
+ # pylint: disable=invalid-name
32
+ _ATOL_DEFAULT = ATOL_DEFAULT
33
+ _RTOL_DEFAULT = RTOL_DEFAULT
34
+ _MAX_TOL = 1e-4
35
+
36
+ def __init__(self, probabilities, atol=ATOL_DEFAULT):
37
+ """
38
+ Create a readout error for a noise model.
39
+
40
+ For an N-qubit readout error probabilities are entered as vectors:
41
+
42
+ .. code-block:: python
43
+
44
+ probabilities[m] = [P(0|m), P(1|m), ..., P(2 ** N - 1|m)]
45
+
46
+ where ``P(n|m)`` is the probability of recording a noisy measurement
47
+ outcome as ``n`` given the true ideal measurement outcome was ``m``,
48
+ where ``n`` and ``m`` are integer representations of bit-strings.
49
+
50
+ **Example: 1-qubit**
51
+
52
+ .. code-block:: python
53
+
54
+ probabilities[0] = [P("0"|"0"), P("1"|"0")]
55
+ probabilities[1] = [P("0"|"1"), P("1"|"1")]
56
+
57
+ **Example: 2-qubit**
58
+
59
+ .. code-block:: python
60
+
61
+ probabilities[0] = [P("00"|"00"), P("01"|"00"), P("10"|"00"), P("11"|"00")]
62
+ probabilities[1] = [P("00"|"01"), P("01"|"01"), P("10"|"01"), P("11"|"01")]
63
+ probabilities[2] = [P("00"|"10"), P("01"|"10"), P("10"|"10"), P("11"|"10")]
64
+ probabilities[3] = [P("00"|"11"), P("01"|"11"), P("10"|"11"), P("11"|"11")]
65
+
66
+ Args:
67
+ probabilities (matrix): List of outcome assignment probabilities.
68
+ atol (double): Threshold for checking probabilities are normalized
69
+ (Default: 1e-8).
70
+
71
+ Raises:
72
+ NoiseError: if an invalid argument is provided
73
+ """
74
+ self._check_probabilities(probabilities, atol)
75
+ self._probabilities = np.array(probabilities, dtype=float)
76
+ self._number_of_qubits = int(np.log2(self._probabilities.shape[0]))
77
+ if self._probabilities.shape != (2**self._number_of_qubits, 2**self._number_of_qubits):
78
+ raise NoiseError("Input readout error probabilities is not a 2^N by 2^N matrix.")
79
+
80
+ def __repr__(self):
81
+ """Display ReadoutError."""
82
+ return "ReadoutError({})".format(self._probabilities)
83
+
84
+ def __str__(self):
85
+ """Print error information."""
86
+ output = (
87
+ "ReadoutError on {} qubits.".format(self._number_of_qubits)
88
+ + " Assignment probabilities:"
89
+ )
90
+ for j, vec in enumerate(self._probabilities):
91
+ output += "\n P(j|{0}) = {1}".format(j, vec)
92
+ return output
93
+
94
+ def __eq__(self, other):
95
+ """Test if two ReadoutErrors are equal."""
96
+ if not isinstance(other, ReadoutError):
97
+ return False
98
+ if self.number_of_qubits != other.number_of_qubits:
99
+ return False
100
+ return np.allclose(
101
+ self._probabilities, other._probabilities, atol=self.atol, rtol=self.rtol
102
+ )
103
+
104
+ def copy(self):
105
+ """Make a copy of current ReadoutError."""
106
+ # pylint: disable=no-value-for-parameter
107
+ # The constructor of subclasses from raw data should be a copy
108
+ return copy.deepcopy(self)
109
+
110
+ @property
111
+ def number_of_qubits(self):
112
+ """Return the number of qubits for the error."""
113
+ return self._number_of_qubits
114
+
115
+ @property
116
+ def probabilities(self):
117
+ """Return the readout error probabilities matrix."""
118
+ return self._probabilities
119
+
120
+ @property
121
+ def atol(self):
122
+ """The default absolute tolerance parameter for float comparisons."""
123
+ return ReadoutError._ATOL_DEFAULT
124
+
125
+ @property
126
+ def rtol(self):
127
+ """The relative tolerance parameter for float comparisons."""
128
+ return ReadoutError._RTOL_DEFAULT
129
+
130
+ @classmethod
131
+ def set_atol(cls, value):
132
+ """Set the class default absolute tolerance parameter for float comparisons."""
133
+ if value < 0:
134
+ raise NoiseError("Invalid atol ({}) must be non-negative.".format(value))
135
+ if value > cls._MAX_TOL:
136
+ raise NoiseError("Invalid atol ({}) must be less than {}.".format(value, cls._MAX_TOL))
137
+ cls._ATOL_DEFAULT = value
138
+
139
+ @classmethod
140
+ def set_rtol(cls, value):
141
+ """Set the class default relative tolerance parameter for float comparisons."""
142
+ if value < 0:
143
+ raise NoiseError("Invalid rtol ({}) must be non-negative.".format(value))
144
+ if value > cls._MAX_TOL:
145
+ raise NoiseError("Invalid rtol ({}) must be less than {}.".format(value, cls._MAX_TOL))
146
+ cls._RTOL_DEFAULT = value
147
+
148
+ def ideal(self):
149
+ """Return True if current error object is an identity"""
150
+ iden = np.eye(2**self.number_of_qubits)
151
+ delta = round(norm(np.array(self.probabilities) - iden), 12)
152
+ if delta == 0:
153
+ return True
154
+ return False
155
+
156
+ def to_instruction(self):
157
+ """Convert the ReadoutError to a circuit Instruction."""
158
+ return Instruction("roerror", 0, self.number_of_qubits, self._probabilities)
159
+
160
+ def to_dict(self):
161
+ """Return the current error as a dictionary."""
162
+ error = {
163
+ "type": "roerror",
164
+ "operations": ["measure"],
165
+ "probabilities": self._probabilities.tolist(),
166
+ }
167
+ return error
168
+
169
+ def compose(self, other, front=False):
170
+ """Return the composition readout error other * self.
171
+
172
+ Note that for `front=True` this is equivalent to the
173
+ :meth:`ReadoutError.dot` method.
174
+
175
+ Args:
176
+ other (ReadoutError): a readout error.
177
+ front (bool): If True return the reverse order composation
178
+ self * other instead [default: False].
179
+
180
+ Returns:
181
+ ReadoutError: The composition readout error.
182
+
183
+ Raises:
184
+ NoiseError: if other is not a ReadoutError or has incompatible
185
+ dimensions.
186
+ """
187
+ if front:
188
+ return self._matmul(other)
189
+ return self._matmul(other, left_multiply=True)
190
+
191
+ def dot(self, other):
192
+ """Return the composition readout error self * other.
193
+
194
+ Args:
195
+ other (ReadoutError): a readout error.
196
+
197
+ Returns:
198
+ ReadoutError: The composition readout error.
199
+
200
+ Raises:
201
+ NoiseError: if other is not a ReadoutError or has incompatible
202
+ dimensions.
203
+ """
204
+ return self._matmul(other)
205
+
206
+ def power(self, n):
207
+ """Return the compose of the readout error with itself n times.
208
+
209
+ Args:
210
+ n (int): the number of times to compose with self (n>0).
211
+
212
+ Returns:
213
+ ReadoutError: the n-times composition channel.
214
+
215
+ Raises:
216
+ NoiseError: if the power is not a positive integer.
217
+ """
218
+ if not isinstance(n, int) or n < 1:
219
+ raise NoiseError("Can only power with positive integer powers.")
220
+ ret = self.copy()
221
+ for _ in range(1, n):
222
+ ret = ret.compose(self)
223
+ return ret
224
+
225
+ def tensor(self, other):
226
+ """Return the tensor product readout error self ⊗ other.
227
+
228
+ Args:
229
+ other (ReadoutError): a readout error.
230
+
231
+ Returns:
232
+ ReadoutError: the tensor product readout error self ⊗ other.
233
+
234
+ Raises:
235
+ NoiseError: if other is not a ReadoutError.
236
+ """
237
+ return self._tensor_product(other, reverse=False)
238
+
239
+ def expand(self, other):
240
+ """Return the tensor product readout error self ⊗ other.
241
+
242
+ Args:
243
+ other (ReadoutError): a readout error.
244
+
245
+ Returns:
246
+ ReadoutError: the tensor product readout error other ⊗ self.
247
+
248
+ Raises:
249
+ NoiseError: if other is not a ReadoutError.
250
+ """
251
+ return self._tensor_product(other, reverse=True)
252
+
253
+ @staticmethod
254
+ def _check_probabilities(probabilities, threshold):
255
+ """Check probabilities are valid."""
256
+ # probabilities parameter can be a list or a numpy.ndarray
257
+ if (isinstance(probabilities, list) and not probabilities) or (
258
+ isinstance(probabilities, np.ndarray) and probabilities.size == 0
259
+ ):
260
+ raise NoiseError("Input probabilities: empty.")
261
+ num_outcomes = len(probabilities[0])
262
+ num_qubits = int(np.log2(num_outcomes))
263
+ if 2**num_qubits != num_outcomes:
264
+ raise NoiseError(
265
+ "Invalid probabilities: length " "{} != 2**{}".format(num_outcomes, num_qubits)
266
+ )
267
+ if len(probabilities) != num_outcomes:
268
+ raise NoiseError("Invalid probabilities.")
269
+ for vec in probabilities:
270
+ arr = np.array(vec)
271
+ if len(arr) != num_outcomes:
272
+ raise NoiseError("Invalid probabilities: vectors are different lengths.")
273
+ if abs(sum(arr) - 1) > threshold:
274
+ raise NoiseError(
275
+ "Invalid probabilities: sum({})= {} " "is not 1.".format(vec, sum(arr))
276
+ )
277
+ if arr[arr < 0].size > 0:
278
+ raise NoiseError(
279
+ "Invalid probabilities: {} " "contains a negative probability.".format(vec)
280
+ )
281
+
282
+ def _matmul(self, other, left_multiply=False):
283
+ """Return the composition readout error.
284
+
285
+ Args:
286
+ other (ReadoutError): a readout error.
287
+ left_multiply (bool): If True return other * self
288
+ If False return self * other [Default:False]
289
+ Returns:
290
+ ReadoutError: The composition readout error.
291
+
292
+ Raises:
293
+ NoiseError: if other is not a ReadoutError or has incompatible
294
+ dimensions.
295
+ """
296
+ if not isinstance(other, ReadoutError):
297
+ other = ReadoutError(other)
298
+ if self.number_of_qubits != other.number_of_qubits:
299
+ raise NoiseError("other must have same number of qubits.")
300
+ if left_multiply:
301
+ probs = np.dot(other._probabilities, self._probabilities)
302
+ else:
303
+ probs = np.dot(self._probabilities, other._probabilities)
304
+ return ReadoutError(probs)
305
+
306
+ def _tensor_product(self, other, reverse=False):
307
+ """Return the tensor product readout error.
308
+
309
+ Args:
310
+ other (ReadoutError): a readout error.
311
+ reverse (bool): If False return self ⊗ other, if True return
312
+ if True return (other ⊗ self) [Default: False
313
+ Returns:
314
+ ReadoutError: the tensor product readout error.
315
+ """
316
+ if not isinstance(other, ReadoutError):
317
+ other = ReadoutError(other)
318
+ if reverse:
319
+ probs = np.kron(other._probabilities, self._probabilities)
320
+ else:
321
+ probs = np.kron(self._probabilities, other._probabilities)
322
+ return ReadoutError(probs)
323
+
324
+ # Overloads
325
+ def __matmul__(self, other):
326
+ return self.compose(other)
327
+
328
+ def __mul__(self, other):
329
+ return self.dot(other)
330
+
331
+ def __pow__(self, n):
332
+ return self.power(n)
333
+
334
+ def __xor__(self, other):
335
+ return self.tensor(other)
336
+
337
+ def __rmul__(self, other):
338
+ raise NotImplementedError("'ReadoutError' does not support scalar multiplication.")
339
+
340
+ def __truediv__(self, other):
341
+ raise NotImplementedError("'ReadoutError' does not support division.")
342
+
343
+ def __add__(self, other):
344
+ raise NotImplementedError("'ReadoutError' does not support addition.")
345
+
346
+ def __sub__(self, other):
347
+ raise NotImplementedError("'ReadoutError' does not support subtraction.")
348
+
349
+ def __neg__(self):
350
+ raise NotImplementedError("'ReadoutError' does not support negation.")
351
+
352
+ @property
353
+ def num_qubits(self):
354
+ """Return the number of qubits."""
355
+ return self._number_of_qubits