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,257 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2018, 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
+ Simulator instruction to save exact operator expectation value.
14
+ """
15
+
16
+ from numpy import allclose
17
+ from qiskit.quantum_info import Pauli, SparsePauliOp, Operator
18
+ from qiskit.circuit import QuantumCircuit
19
+ from .save_data import SaveAverageData
20
+
21
+
22
+ class SaveExpectationValue(SaveAverageData):
23
+ """Save expectation value of an operator."""
24
+
25
+ def __init__(
26
+ self,
27
+ operator,
28
+ label="expectation_value",
29
+ unnormalized=False,
30
+ pershot=False,
31
+ conditional=False,
32
+ ):
33
+ r"""Instruction to save the expectation value of a Hermitian operator.
34
+
35
+ The expectation value of a Hermitian operator :math:`H` for a simulator
36
+ in quantum state :math`\rho`is given by
37
+ :math:`\langle H\rangle = \mbox{Tr}[H.\rho]`.
38
+
39
+ Args:
40
+ operator (Pauli or SparsePauliOp or Operator): a Hermitian operator.
41
+ label (str): the key for retrieving saved data from results.
42
+ unnormalized (bool): If True return save the unnormalized accumulated
43
+ or conditional accumulated expectation value
44
+ over all shot [Default: False].
45
+ pershot (bool): if True save a list of expectation values for each shot
46
+ of the simulation rather than the average over
47
+ all shots [Default: False].
48
+ conditional (bool): if True save the average or pershot data
49
+ conditional on the current classical register
50
+ values [Default: False].
51
+
52
+ Raises:
53
+ ValueError: if the input operator is not Hermitian.
54
+ TypeError: if the input operator is of invalid type.
55
+
56
+ .. note::
57
+
58
+ This instruction can be directly appended to a circuit using the
59
+ :func:`save_expectation_value` circuit method.
60
+ """
61
+ # Convert O to SparsePauliOp representation
62
+ if isinstance(operator, Pauli):
63
+ operator = SparsePauliOp(operator)
64
+ elif not isinstance(operator, SparsePauliOp):
65
+ operator = SparsePauliOp.from_operator(Operator(operator))
66
+ if not allclose(operator.coeffs.imag, 0):
67
+ raise ValueError("Input operator is not Hermitian.")
68
+ params = _expval_params(operator, variance=False)
69
+ super().__init__(
70
+ "save_expval",
71
+ operator.num_qubits,
72
+ label,
73
+ unnormalized=unnormalized,
74
+ pershot=pershot,
75
+ conditional=conditional,
76
+ params=params,
77
+ )
78
+
79
+
80
+ class SaveExpectationValueVariance(SaveAverageData):
81
+ """Save expectation value and variance of an operator."""
82
+
83
+ def __init__(
84
+ self,
85
+ operator,
86
+ label="expectation_value_variance",
87
+ unnormalized=False,
88
+ pershot=False,
89
+ conditional=False,
90
+ ):
91
+ r"""Instruction to save the expectation value and variance of a Hermitian operator.
92
+
93
+ The expectation value of a Hermitian operator :math:`H` for a
94
+ simulator in quantum state :math`\rho`is given by
95
+ :math:`\langle H\rangle = \mbox{Tr}[H.\rho]`. The variance is given by
96
+ :math:`\sigma^2 = \langle H^2 \rangle - \langle H \rangle>^2`.
97
+
98
+ Args:
99
+ operator (Pauli or SparsePauliOp or Operator): a Hermitian operator.
100
+ label (str): the key for retrieving saved data from results.
101
+ unnormalized (bool): If True return save the unnormalized accumulated
102
+ or conditional accumulated expectation value
103
+ over all shot [Default: False].
104
+ pershot (bool): if True save a list of expectation values for each shot
105
+ of the simulation rather than the average over
106
+ all shots [Default: False].
107
+ conditional (bool): if True save the average or pershot data
108
+ conditional on the current classical register
109
+ values [Default: False].
110
+
111
+ Raises:
112
+ ValueError: if the input operator is not Hermitian.
113
+ TypeError: if the input operator is of invalid type.
114
+
115
+ .. note::
116
+
117
+ This instruction can be directly appended to a circuit using
118
+ the :func:`save_expectation_value` circuit method.
119
+ """
120
+ # Convert O to SparsePauliOp representation
121
+ if isinstance(operator, Pauli):
122
+ operator = SparsePauliOp(operator)
123
+ elif not isinstance(operator, SparsePauliOp):
124
+ operator = SparsePauliOp.from_operator(Operator(operator))
125
+ if not allclose(operator.coeffs.imag, 0):
126
+ raise ValueError("Input operator is not Hermitian.")
127
+ params = _expval_params(operator, variance=True)
128
+ super().__init__(
129
+ "save_expval_var",
130
+ operator.num_qubits,
131
+ label,
132
+ unnormalized=unnormalized,
133
+ pershot=pershot,
134
+ conditional=conditional,
135
+ params=params,
136
+ )
137
+
138
+
139
+ def _expval_params(operator, variance=False):
140
+ # Convert O to SparsePauliOp representation
141
+ if isinstance(operator, Pauli):
142
+ operator = SparsePauliOp(operator)
143
+ elif not isinstance(operator, SparsePauliOp):
144
+ operator = SparsePauliOp.from_operator(Operator(operator))
145
+ if not isinstance(operator, SparsePauliOp):
146
+ raise TypeError("Invalid input operator")
147
+
148
+ params = {}
149
+
150
+ # Add Pauli basis components of O
151
+ for pauli, coeff in operator.label_iter():
152
+ if pauli in params:
153
+ coeff1 = params[pauli][0]
154
+ params[pauli] = (coeff1 + coeff.real, 0)
155
+ else:
156
+ params[pauli] = (coeff.real, 0)
157
+
158
+ # Add Pauli basis components of O^2
159
+ if variance:
160
+ for pauli, coeff in operator.dot(operator).label_iter():
161
+ if pauli in params:
162
+ coeff1, coeff2 = params[pauli]
163
+ params[pauli] = (coeff1, coeff2 + coeff.real)
164
+ else:
165
+ params[pauli] = (0, coeff.real)
166
+
167
+ # Convert to list
168
+ return list(params.items())
169
+
170
+
171
+ def save_expectation_value(
172
+ self,
173
+ operator,
174
+ qubits,
175
+ label="expectation_value",
176
+ unnormalized=False,
177
+ pershot=False,
178
+ conditional=False,
179
+ ):
180
+ r"""Save the expectation value of a Hermitian operator.
181
+
182
+ Args:
183
+ operator (Pauli or SparsePauliOp or Operator): a Hermitian operator.
184
+ qubits (list): circuit qubits to apply instruction.
185
+ label (str): the key for retrieving saved data from results.
186
+ unnormalized (bool): If True return save the unnormalized accumulated
187
+ or conditional accumulated expectation value
188
+ over all shot [Default: False].
189
+ pershot (bool): if True save a list of expectation values for each
190
+ shot of the simulation rather than the average over
191
+ all shots [Default: False].
192
+ conditional (bool): if True save the average or pershot data
193
+ conditional on the current classical register
194
+ values [Default: False].
195
+
196
+ Returns:
197
+ QuantumCircuit: with attached instruction.
198
+
199
+ Raises:
200
+ ValueError: if the input operator is not Hermitian.
201
+ TypeError: if the input operator is of invalid type.
202
+
203
+ .. note::
204
+
205
+ This method appends a :class:`SaveExpectationValue` instruction to
206
+ the quantum circuit.
207
+ """
208
+ instr = SaveExpectationValue(
209
+ operator, label=label, unnormalized=unnormalized, pershot=pershot, conditional=conditional
210
+ )
211
+ return self.append(instr, qubits)
212
+
213
+
214
+ def save_expectation_value_variance(
215
+ self,
216
+ operator,
217
+ qubits,
218
+ label="expectation_value_variance",
219
+ unnormalized=False,
220
+ pershot=False,
221
+ conditional=False,
222
+ ):
223
+ r"""Save the expectation value of a Hermitian operator.
224
+
225
+ Args:
226
+ operator (Pauli or SparsePauliOp or Operator): a Hermitian operator.
227
+ qubits (list): circuit qubits to apply instruction.
228
+ label (str): the key for retrieving saved data from results.
229
+ unnormalized (bool): If True return save the unnormalized accumulated
230
+ or conditional accumulated expectation value
231
+ and variance over all shot [Default: False].
232
+ pershot (bool): if True save a list of expectation values and
233
+ variances for each shot of the simulation rather than
234
+ the average over all shots [Default: False].
235
+ conditional (bool): if True save the data conditional on the current
236
+ classical register values [Default: False].
237
+
238
+ Returns:
239
+ QuantumCircuit: with attached instruction.
240
+
241
+ Raises:
242
+ ValueError: if the input operator is not Hermitian.
243
+ TypeError: if the input operator is of invalid type.
244
+
245
+ .. note::
246
+
247
+ This method appends a :class:`SaveExpectationValueVariance`
248
+ instruction to the quantum circuit.
249
+ """
250
+ instr = SaveExpectationValueVariance(
251
+ operator, label=label, unnormalized=unnormalized, pershot=pershot, conditional=conditional
252
+ )
253
+ return self.append(instr, qubits)
254
+
255
+
256
+ QuantumCircuit.save_expectation_value = save_expectation_value
257
+ QuantumCircuit.save_expectation_value_variance = save_expectation_value_variance
@@ -0,0 +1,71 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2018, 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
+ Simulator instruction to save matrix product state.
14
+ """
15
+
16
+ from qiskit.circuit import QuantumCircuit
17
+ from .save_data import SaveSingleData
18
+ from ..default_qubits import default_qubits
19
+
20
+
21
+ class SaveMatrixProductState(SaveSingleData):
22
+ """Save matrix product state instruction"""
23
+
24
+ def __init__(self, num_qubits, label="matrix_product_state", pershot=False, conditional=False):
25
+ """Create new instruction to save the matrix product state.
26
+
27
+ Args:
28
+ num_qubits (int): the number of qubits
29
+ label (str): the key for retrieving saved data from results.
30
+ pershot (bool): if True save the mps for each
31
+ shot of the simulation [Default: False].
32
+ conditional (bool): if True save data conditional on the current
33
+ classical register values [Default: False].
34
+
35
+ .. note::
36
+
37
+ This save instruction must always be performed on the full width of
38
+ qubits in a circuit, otherwise an exception will be raised during
39
+ simulation.
40
+ """
41
+ super().__init__(
42
+ "save_matrix_product_state", num_qubits, label, pershot=pershot, conditional=conditional
43
+ )
44
+
45
+
46
+ def save_matrix_product_state(self, label="matrix_product_state", pershot=False, conditional=False):
47
+ """Save the current simulator quantum state as a matrix product state.
48
+
49
+ Args:
50
+ label (str): the key for retrieving saved data from results.
51
+ pershot (bool): if True save the mps for each
52
+ shot of the simulation [Default: False].
53
+ conditional (bool): if True save pershot data conditional on the
54
+ current classical register values
55
+ [Default: False].
56
+
57
+ Returns:
58
+ QuantumCircuit: with attached instruction.
59
+
60
+ .. note:
61
+
62
+ This instruction is always defined across all qubits in a circuit.
63
+ """
64
+ qubits = default_qubits(self)
65
+ instr = SaveMatrixProductState(
66
+ len(qubits), label=label, pershot=pershot, conditional=conditional
67
+ )
68
+ return self.append(instr, qubits)
69
+
70
+
71
+ QuantumCircuit.save_matrix_product_state = save_matrix_product_state
@@ -0,0 +1,156 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2018, 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
+ Simulator instruction to save measurement outcome probabilities.
14
+ """
15
+
16
+ from qiskit.circuit import QuantumCircuit
17
+ from .save_data import SaveAverageData
18
+ from ..default_qubits import default_qubits
19
+
20
+
21
+ class SaveProbabilities(SaveAverageData):
22
+ """Save measurement outcome probabilities vector."""
23
+
24
+ def __init__(
25
+ self,
26
+ num_qubits,
27
+ label="probabilities",
28
+ unnormalized=False,
29
+ pershot=False,
30
+ conditional=False,
31
+ ):
32
+ """Instruction to save measurement probabilities vector.
33
+
34
+ Args:
35
+ num_qubits (int): the number of qubits for the snapshot type.
36
+ label (str): the key for retrieving saved data from results.
37
+ unnormalized (bool): If True return save the unnormalized accumulated
38
+ probabilities over all shots [Default: False].
39
+ pershot (bool): if True save a list of probabilities for each shot
40
+ of the simulation rather than the average over
41
+ all shots [Default: False].
42
+ conditional (bool): if True save the probabilities data conditional
43
+ on the current classical register values
44
+ [Default: False].
45
+ """
46
+ super().__init__(
47
+ "save_probabilities",
48
+ num_qubits,
49
+ label,
50
+ conditional=conditional,
51
+ pershot=pershot,
52
+ unnormalized=unnormalized,
53
+ )
54
+
55
+
56
+ class SaveProbabilitiesDict(SaveAverageData):
57
+ """Save measurement outcome probabilities dict."""
58
+
59
+ def __init__(
60
+ self,
61
+ num_qubits,
62
+ label="probabilities_dict",
63
+ unnormalized=False,
64
+ pershot=False,
65
+ conditional=False,
66
+ ):
67
+ """Instruction to save measurement probabilities dict.
68
+
69
+ Args:
70
+ num_qubits (int): the number of qubits for the snapshot type.
71
+ label (str): the key for retrieving saved data from results.
72
+ unnormalized (bool): If True return save the unnormalized accumulated
73
+ probabilities over all shots [Default: False].
74
+ pershot (bool): if True save a list of probabilities for each shot
75
+ of the simulation rather than the average over
76
+ all shots [Default: False].
77
+ conditional (bool): if True save the probabilities data conditional
78
+ on the current classical register values
79
+ [Default: False].
80
+ """
81
+ super().__init__(
82
+ "save_probabilities_dict",
83
+ num_qubits,
84
+ label,
85
+ unnormalized=unnormalized,
86
+ pershot=pershot,
87
+ conditional=conditional,
88
+ )
89
+
90
+
91
+ def save_probabilities(
92
+ self, qubits=None, label="probabilities", unnormalized=False, pershot=False, conditional=False
93
+ ):
94
+ """Save measurement outcome probabilities vector.
95
+
96
+ Args:
97
+ qubits (list or None): the qubits to apply snapshot to. If None all
98
+ qubits will be snapshot [Default: None].
99
+ label (str): the key for retrieving saved data from results.
100
+ unnormalized (bool): If True return save the unnormalized accumulated
101
+ probabilities over all shots [Default: False].
102
+ pershot (bool): if True save a list of probabilities for each shot
103
+ of the simulation rather than the average over
104
+ all shots [Default: False].
105
+ conditional (bool): if True save the probabilities data conditional
106
+ on the current classical register values
107
+ [Default: False].
108
+
109
+ Returns:
110
+ QuantumCircuit: with attached instruction.
111
+ """
112
+ qubits = default_qubits(self, qubits=qubits)
113
+ instr = SaveProbabilities(
114
+ len(qubits),
115
+ label=label,
116
+ unnormalized=unnormalized,
117
+ pershot=pershot,
118
+ conditional=conditional,
119
+ )
120
+ return self.append(instr, qubits)
121
+
122
+
123
+ def save_probabilities_dict(
124
+ self, qubits=None, label="probabilities", unnormalized=False, pershot=False, conditional=False
125
+ ):
126
+ """Save measurement outcome probabilities vector.
127
+
128
+ Args:
129
+ qubits (list or None): the qubits to apply snapshot to. If None all
130
+ qubits will be snapshot [Default: None].
131
+ label (str): the key for retrieving saved data from results.
132
+ unnormalized (bool): If True return save the unnormalized accumulated
133
+ probabilities over all shots [Default: False].
134
+ pershot (bool): if True save a list of probabilities for each shot
135
+ of the simulation rather than the average over
136
+ all shots [Default: False].
137
+ conditional (bool): if True save the probabilities data conditional
138
+ on the current classical register values
139
+ [Default: False].
140
+
141
+ Returns:
142
+ QuantumCircuit: with attached instruction.
143
+ """
144
+ qubits = default_qubits(self, qubits=qubits)
145
+ instr = SaveProbabilitiesDict(
146
+ len(qubits),
147
+ label=label,
148
+ unnormalized=unnormalized,
149
+ pershot=pershot,
150
+ conditional=conditional,
151
+ )
152
+ return self.append(instr, qubits)
153
+
154
+
155
+ QuantumCircuit.save_probabilities = save_probabilities
156
+ QuantumCircuit.save_probabilities_dict = save_probabilities_dict
@@ -0,0 +1,70 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2018, 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
+ Simulator instruction to save Clifford state.
14
+ """
15
+
16
+ from qiskit.circuit import QuantumCircuit
17
+ from .save_data import SaveSingleData
18
+ from ..default_qubits import default_qubits
19
+
20
+
21
+ class SaveStabilizer(SaveSingleData):
22
+ """Save Stabilizer instruction"""
23
+
24
+ def __init__(self, num_qubits, label="stabilizer", pershot=False, conditional=False):
25
+ """Create new instruction to save the stabilizer simulator state as a StabilizerState.
26
+
27
+ Args:
28
+ num_qubits (int): the number of qubits of the
29
+ label (str): the key for retrieving saved data from results.
30
+ pershot (bool): if True save a list of StabilizerStates for each
31
+ shot of the simulation rather than a single
32
+ statevector [Default: False].
33
+ conditional (bool): if True save data conditional on the current
34
+ classical register values [Default: False].
35
+
36
+ .. note::
37
+
38
+ This save instruction must always be performed on the full width of
39
+ qubits in a circuit, otherwise an exception will be raised during
40
+ simulation.
41
+ """
42
+ super().__init__(
43
+ "save_stabilizer", num_qubits, label, pershot=pershot, conditional=conditional
44
+ )
45
+
46
+
47
+ def save_stabilizer(self, label="stabilizer", pershot=False, conditional=False):
48
+ """Save the current stabilizer simulator quantum state as a StabilizerState.
49
+
50
+ Args:
51
+ label (str): the key for retrieving saved data from results.
52
+ pershot (bool): if True save a list of StabilizerStates for each
53
+ shot of the simulation [Default: False].
54
+ conditional (bool): if True save pershot data conditional on the
55
+ current classical register values
56
+ [Default: False].
57
+
58
+ Returns:
59
+ QuantumCircuit: with attached instruction.
60
+
61
+ .. note::
62
+
63
+ This instruction is always defined across all qubits in a circuit.
64
+ """
65
+ qubits = default_qubits(self)
66
+ instr = SaveStabilizer(len(qubits), label=label, pershot=pershot, conditional=conditional)
67
+ return self.append(instr, qubits)
68
+
69
+
70
+ QuantumCircuit.save_stabilizer = save_stabilizer
@@ -0,0 +1,79 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2018, 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
+ Simulator instruction to save simulator state.
14
+ """
15
+
16
+ from qiskit.circuit import QuantumCircuit
17
+ from .save_data import SaveSingleData
18
+ from ..default_qubits import default_qubits
19
+
20
+
21
+ class SaveState(SaveSingleData):
22
+ """Save simulator state
23
+
24
+ The format of the saved state depends on the simulation method used.
25
+ """
26
+
27
+ def __init__(self, num_qubits, label=None, pershot=False, conditional=False):
28
+ """Create new instruction to save the simulator state.
29
+
30
+ The format of the saved state depends on the simulation method used.
31
+
32
+ Args:
33
+ num_qubits (int): the number of qubits of the
34
+ label (str or None): Optional, the key for retrieving saved data
35
+ from results. If None the key will be the
36
+ state type of the simulator.
37
+ pershot (bool): if True save a list of states for each
38
+ shot of the simulation rather than a single
39
+ state [Default: False].
40
+ conditional (bool): if True save data conditional on the current
41
+ classical register values [Default: False].
42
+
43
+ .. note::
44
+
45
+ This save instruction must always be performed on the full width of
46
+ qubits in a circuit, otherwise an exception will be raised during
47
+ simulation.
48
+ """
49
+ if label is None:
50
+ label = "_method_"
51
+ super().__init__("save_state", num_qubits, label, pershot=pershot, conditional=conditional)
52
+
53
+
54
+ def save_state(self, label=None, pershot=False, conditional=False):
55
+ """Save the current simulator quantum state.
56
+
57
+ Args:
58
+ label (str or None): Optional, the key for retrieving saved data
59
+ from results. If None the key will be the
60
+ state type of the simulator.
61
+ pershot (bool): if True save a list of statevectors for each
62
+ shot of the simulation [Default: False].
63
+ conditional (bool): if True save pershot data conditional on the
64
+ current classical register values
65
+ [Default: False].
66
+
67
+ Returns:
68
+ QuantumCircuit: with attached instruction.
69
+
70
+ .. note:
71
+
72
+ This instruction is always defined across all qubits in a circuit.
73
+ """
74
+ qubits = default_qubits(self)
75
+ instr = SaveState(len(qubits), label=label, pershot=pershot, conditional=conditional)
76
+ return self.append(instr, qubits)
77
+
78
+
79
+ QuantumCircuit.save_state = save_state