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,168 @@
|
|
|
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 statevector amplitudes and amplitudes squared.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from qiskit.circuit import QuantumCircuit
|
|
17
|
+
from .save_data import SaveSingleData, SaveAverageData
|
|
18
|
+
from ..default_qubits import default_qubits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveAmplitudes(SaveSingleData):
|
|
22
|
+
"""Save complex statevector amplitudes."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, num_qubits, params, label="amplitudes", pershot=False, conditional=False):
|
|
25
|
+
"""Instruction to save complex statevector amplitudes.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
num_qubits (int): the number of qubits for the snapshot type.
|
|
29
|
+
params (list): list of entries to vale.
|
|
30
|
+
label (str): the key for retrieving saved data from results.
|
|
31
|
+
pershot (bool): if True save a list of amplitudes vectors for each
|
|
32
|
+
shot of the simulation rather than the a single
|
|
33
|
+
amplitude vector [Default: False].
|
|
34
|
+
conditional (bool): if True save the amplitudes vector conditional
|
|
35
|
+
on the current classical register values
|
|
36
|
+
[Default: False].
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
ValueError: if params is invalid for the specified number of qubits.
|
|
40
|
+
"""
|
|
41
|
+
params = _format_amplitude_params(params, num_qubits)
|
|
42
|
+
super().__init__(
|
|
43
|
+
"save_amplitudes",
|
|
44
|
+
num_qubits,
|
|
45
|
+
label,
|
|
46
|
+
pershot=pershot,
|
|
47
|
+
conditional=conditional,
|
|
48
|
+
params=params,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class SaveAmplitudesSquared(SaveAverageData):
|
|
53
|
+
"""Save squared statevector amplitudes (probabilities)."""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
num_qubits,
|
|
58
|
+
params,
|
|
59
|
+
label="amplitudes_squared",
|
|
60
|
+
unnormalized=False,
|
|
61
|
+
pershot=False,
|
|
62
|
+
conditional=False,
|
|
63
|
+
):
|
|
64
|
+
"""Instruction to save squared statevector amplitudes (probabilities).
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
num_qubits (int): the number of qubits for the snapshot type.
|
|
68
|
+
params (list): list of entries to vale.
|
|
69
|
+
label (str): the key for retrieving saved data from results.
|
|
70
|
+
unnormalized (bool): If True return save the unnormalized accumulated
|
|
71
|
+
probabilities over all shots [Default: False].
|
|
72
|
+
pershot (bool): if True save a list of probability vectors for each
|
|
73
|
+
shot of the simulation rather than the a single
|
|
74
|
+
amplitude vector [Default: False].
|
|
75
|
+
conditional (bool): if True save the probability vector conditional
|
|
76
|
+
on the current classical register values
|
|
77
|
+
[Default: False].
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ValueError: if params is invalid for the specified number of qubits.
|
|
81
|
+
"""
|
|
82
|
+
params = _format_amplitude_params(params, num_qubits)
|
|
83
|
+
super().__init__(
|
|
84
|
+
"save_amplitudes_sq",
|
|
85
|
+
num_qubits,
|
|
86
|
+
label,
|
|
87
|
+
unnormalized=unnormalized,
|
|
88
|
+
pershot=pershot,
|
|
89
|
+
conditional=conditional,
|
|
90
|
+
params=params,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def save_amplitudes(self, params, label="amplitudes", pershot=False, conditional=False):
|
|
95
|
+
"""Save complex statevector amplitudes.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
params (List[int] or List[str]): the basis states to return amplitudes for.
|
|
99
|
+
label (str): the key for retrieving saved data from results.
|
|
100
|
+
pershot (bool): if True save a list of amplitudes vectors for each
|
|
101
|
+
shot of the simulation rather than the a single
|
|
102
|
+
amplitude vector [Default: False].
|
|
103
|
+
conditional (bool): if True save the amplitudes vector conditional
|
|
104
|
+
on the current classical register values
|
|
105
|
+
[Default: False].
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
QuantumCircuit: with attached instruction.
|
|
109
|
+
|
|
110
|
+
Raises:
|
|
111
|
+
ValueError: if params is invalid for the specified number of qubits.
|
|
112
|
+
"""
|
|
113
|
+
qubits = default_qubits(self)
|
|
114
|
+
instr = SaveAmplitudes(
|
|
115
|
+
len(qubits), params, label=label, pershot=pershot, conditional=conditional
|
|
116
|
+
)
|
|
117
|
+
return self.append(instr, qubits)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def save_amplitudes_squared(
|
|
121
|
+
self, params, label="amplitudes_squared", unnormalized=False, pershot=False, conditional=False
|
|
122
|
+
):
|
|
123
|
+
"""Save squared statevector amplitudes (probabilities).
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
params (List[int] or List[str]): the basis states to return amplitudes for.
|
|
127
|
+
label (str): the key for retrieving saved data from results.
|
|
128
|
+
unnormalized (bool): If True return save the unnormalized accumulated
|
|
129
|
+
probabilities over all shots [Default: False].
|
|
130
|
+
pershot (bool): if True save a list of probability vectors for each
|
|
131
|
+
shot of the simulation rather than the a single
|
|
132
|
+
amplitude vector [Default: False].
|
|
133
|
+
conditional (bool): if True save the probability vector conditional
|
|
134
|
+
on the current classical register values
|
|
135
|
+
[Default: False].
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
QuantumCircuit: with attached instruction.
|
|
139
|
+
|
|
140
|
+
Raises:
|
|
141
|
+
ValueError: if params is invalid for the specified number of qubits.
|
|
142
|
+
"""
|
|
143
|
+
qubits = default_qubits(self)
|
|
144
|
+
instr = SaveAmplitudesSquared(
|
|
145
|
+
len(qubits),
|
|
146
|
+
params,
|
|
147
|
+
label=label,
|
|
148
|
+
unnormalized=unnormalized,
|
|
149
|
+
pershot=pershot,
|
|
150
|
+
conditional=conditional,
|
|
151
|
+
)
|
|
152
|
+
return self.append(instr, qubits)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _format_amplitude_params(params, num_qubits=None):
|
|
156
|
+
"""Format amplitude params as a interger list."""
|
|
157
|
+
if isinstance(params[0], str):
|
|
158
|
+
if params[0].find("0x") == 0:
|
|
159
|
+
params = [int(i, 16) for i in params]
|
|
160
|
+
else:
|
|
161
|
+
params = [int(i, 2) for i in params]
|
|
162
|
+
if num_qubits and max(params) >= 2**num_qubits:
|
|
163
|
+
raise ValueError("Param values contain a state larger than the number of qubits")
|
|
164
|
+
return params
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
QuantumCircuit.save_amplitudes = save_amplitudes
|
|
168
|
+
QuantumCircuit.save_amplitudes_squared = save_amplitudes_squared
|
|
@@ -0,0 +1,63 @@
|
|
|
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 SaveClifford(SaveSingleData):
|
|
22
|
+
"""Save Clifford instruction"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, num_qubits, label="clifford", pershot=False):
|
|
25
|
+
"""Create new instruction to save the stabilizer simulator state as a Clifford.
|
|
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 Cliffords for each
|
|
31
|
+
shot of the simulation rather than a single
|
|
32
|
+
statevector [Default: False].
|
|
33
|
+
|
|
34
|
+
.. note::
|
|
35
|
+
|
|
36
|
+
This save instruction must always be performed on the full width of
|
|
37
|
+
qubits in a circuit, otherwise an exception will be raised during
|
|
38
|
+
simulation.
|
|
39
|
+
"""
|
|
40
|
+
super().__init__("save_clifford", num_qubits, label, pershot=pershot)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def save_clifford(self, label="clifford", pershot=False):
|
|
44
|
+
"""Save the current stabilizer simulator quantum state as a Clifford.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
label (str): the key for retrieving saved data from results.
|
|
48
|
+
pershot (bool): if True save a list of Cliffords for each
|
|
49
|
+
shot of the simulation [Default: False].
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
QuantumCircuit: with attached instruction.
|
|
53
|
+
|
|
54
|
+
.. note::
|
|
55
|
+
|
|
56
|
+
This instruction is always defined across all qubits in a circuit.
|
|
57
|
+
"""
|
|
58
|
+
qubits = default_qubits(self)
|
|
59
|
+
instr = SaveClifford(len(qubits), label=label, pershot=pershot)
|
|
60
|
+
return self.append(instr, qubits)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
QuantumCircuit.save_clifford = save_clifford
|
|
@@ -0,0 +1,129 @@
|
|
|
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 custom internal data to results.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import copy
|
|
17
|
+
|
|
18
|
+
from qiskit.circuit import Instruction
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveData(Instruction):
|
|
22
|
+
"""Pragma Instruction to save simulator data."""
|
|
23
|
+
|
|
24
|
+
_directive = True
|
|
25
|
+
_allowed_subtypes = set(
|
|
26
|
+
["single", "c_single", "list", "c_list", "average", "c_average", "accum", "c_accum"]
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def __init__(self, name, num_qubits, label, subtype="single", params=None):
|
|
30
|
+
"""Create new save data instruction.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name (str): the name of the save instruction.
|
|
34
|
+
num_qubits (int): the number of qubits for the snapshot type.
|
|
35
|
+
label (str): the key for retrieving saved data from results.
|
|
36
|
+
subtype (str): the data subtype for the instruction [Default: 'single'].
|
|
37
|
+
params (list or None): Optional, the parameters for instruction
|
|
38
|
+
[Default: None].
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
TypeError: if the subtype string is invalid.
|
|
42
|
+
|
|
43
|
+
Additional Information:
|
|
44
|
+
The supported subtypes are 'single', 'list', 'c_list', 'average',
|
|
45
|
+
'c_average', 'accum', 'c_accum'.
|
|
46
|
+
"""
|
|
47
|
+
if subtype not in self._allowed_subtypes:
|
|
48
|
+
raise TypeError("Invalid data subtype for SaveData instruction.")
|
|
49
|
+
|
|
50
|
+
if not isinstance(label, str):
|
|
51
|
+
raise TypeError(f"Invalid label for save data instruction, {label} must be a string.")
|
|
52
|
+
|
|
53
|
+
if params is None:
|
|
54
|
+
params = {}
|
|
55
|
+
|
|
56
|
+
super().__init__(name, num_qubits, 0, params)
|
|
57
|
+
|
|
58
|
+
self._label = label
|
|
59
|
+
self._subtype = subtype
|
|
60
|
+
|
|
61
|
+
def inverse(self, annotated=False):
|
|
62
|
+
"""Special case. Return self."""
|
|
63
|
+
return copy.copy(self)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class SaveAverageData(SaveData):
|
|
67
|
+
"""Save averageble data"""
|
|
68
|
+
|
|
69
|
+
def __init__(
|
|
70
|
+
self,
|
|
71
|
+
name,
|
|
72
|
+
num_qubits,
|
|
73
|
+
label,
|
|
74
|
+
unnormalized=False,
|
|
75
|
+
pershot=False,
|
|
76
|
+
conditional=False,
|
|
77
|
+
params=None,
|
|
78
|
+
):
|
|
79
|
+
"""Create new save data instruction.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
name (str): the name of the save instruction.
|
|
83
|
+
num_qubits (int): the number of qubits for the snapshot type.
|
|
84
|
+
label (str): the key for retrieving saved data from results.
|
|
85
|
+
unnormalized (bool): If True return save the unnormalized accumulated
|
|
86
|
+
or conditional accumulated data over all shot.
|
|
87
|
+
[Default: False].
|
|
88
|
+
pershot (bool): if True save a list of data for each shot of the
|
|
89
|
+
simulation rather than the average over all shots
|
|
90
|
+
[Default: False].
|
|
91
|
+
conditional (bool): if True save the average or pershot data
|
|
92
|
+
conditional on the current classical register
|
|
93
|
+
values [Default: False].
|
|
94
|
+
params (list or None): Optional, the parameters for instruction
|
|
95
|
+
[Default: None].
|
|
96
|
+
"""
|
|
97
|
+
if pershot:
|
|
98
|
+
subtype = "list"
|
|
99
|
+
elif unnormalized:
|
|
100
|
+
subtype = "accum"
|
|
101
|
+
else:
|
|
102
|
+
subtype = "average"
|
|
103
|
+
if conditional:
|
|
104
|
+
subtype = "c_" + subtype
|
|
105
|
+
super().__init__(name, num_qubits, label, subtype=subtype, params=params)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class SaveSingleData(SaveData):
|
|
109
|
+
"""Save non-averagable single data type."""
|
|
110
|
+
|
|
111
|
+
def __init__(self, name, num_qubits, label, pershot=False, conditional=False, params=None):
|
|
112
|
+
"""Create new save data instruction.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
name (str): the name of the save instruction.
|
|
116
|
+
num_qubits (int): the number of qubits for the snapshot type.
|
|
117
|
+
label (str): the key for retrieving saved data from results.
|
|
118
|
+
pershot (bool): if True save a list of data for each shot of the
|
|
119
|
+
simulation [Default: False].
|
|
120
|
+
conditional (bool): if True save data conditional on the
|
|
121
|
+
current classical register values
|
|
122
|
+
[Default: False].
|
|
123
|
+
params (list or None): Optional, the parameters for instruction
|
|
124
|
+
[Default: None].
|
|
125
|
+
"""
|
|
126
|
+
subtype = "list" if pershot else "single"
|
|
127
|
+
if conditional:
|
|
128
|
+
subtype = "c_" + subtype
|
|
129
|
+
super().__init__(name, num_qubits, label, subtype=subtype, params=params)
|
|
@@ -0,0 +1,91 @@
|
|
|
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 a density matrix.
|
|
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 SaveDensityMatrix(SaveAverageData):
|
|
22
|
+
"""Save a reduced density matrix."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
num_qubits,
|
|
27
|
+
label="density_matrix",
|
|
28
|
+
unnormalized=False,
|
|
29
|
+
pershot=False,
|
|
30
|
+
conditional=False,
|
|
31
|
+
):
|
|
32
|
+
"""Create new instruction to save the simulator reduced density matrix.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
num_qubits (int): the number of qubits for the save instruction.
|
|
36
|
+
label (str): the key for retrieving saved data from results.
|
|
37
|
+
unnormalized (bool): If True return save the unnormalized accumulated
|
|
38
|
+
or conditional accumulated density matrix over
|
|
39
|
+
all shots [Default: False].
|
|
40
|
+
pershot (bool): if True save a list of density matrices for each shot
|
|
41
|
+
of the simulation rather than the average over
|
|
42
|
+
all shots [Default: False].
|
|
43
|
+
conditional (bool): if True save the average or pershot data
|
|
44
|
+
conditional on the current classical register
|
|
45
|
+
values [Default: False].
|
|
46
|
+
"""
|
|
47
|
+
super().__init__(
|
|
48
|
+
"save_density_matrix",
|
|
49
|
+
num_qubits,
|
|
50
|
+
label,
|
|
51
|
+
unnormalized=unnormalized,
|
|
52
|
+
pershot=pershot,
|
|
53
|
+
conditional=conditional,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def save_density_matrix(
|
|
58
|
+
self, qubits=None, label="density_matrix", unnormalized=False, pershot=False, conditional=False
|
|
59
|
+
):
|
|
60
|
+
"""Save the current simulator quantum state as a density matrix.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
qubits (list or None): the qubits to save reduced density matrix on.
|
|
64
|
+
If None the full density matrix of qubits will
|
|
65
|
+
be saved [Default: None].
|
|
66
|
+
label (str): the key for retrieving saved data from results.
|
|
67
|
+
unnormalized (bool): If True return save the unnormalized accumulated
|
|
68
|
+
or conditional accumulated density matrix over
|
|
69
|
+
all shots [Default: False].
|
|
70
|
+
pershot (bool): if True save a list of density matrices for each shot
|
|
71
|
+
of the simulation rather than the average over
|
|
72
|
+
all shots [Default: False].
|
|
73
|
+
conditional (bool): if True save the average or pershot data
|
|
74
|
+
conditional on the current classical register
|
|
75
|
+
values [Default: False].
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
QuantumCircuit: with attached instruction.
|
|
79
|
+
"""
|
|
80
|
+
qubits = default_qubits(self, qubits=qubits)
|
|
81
|
+
instr = SaveDensityMatrix(
|
|
82
|
+
len(qubits),
|
|
83
|
+
label=label,
|
|
84
|
+
unnormalized=unnormalized,
|
|
85
|
+
pershot=pershot,
|
|
86
|
+
conditional=conditional,
|
|
87
|
+
)
|
|
88
|
+
return self.append(instr, qubits)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
QuantumCircuit.save_density_matrix = save_density_matrix
|